You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
use crate::entities::notification::{Notification, NotificationType};
|
|
use crate::entities::status::Status;
|
|
use std::fmt::{Display, Formatter};
|
|
use crate::entities::event::Event;
|
|
|
|
pub struct NotificationDisplay<'a>(pub &'a Notification);
|
|
|
|
impl<'a> Display for NotificationDisplay<'a> {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
let n = self.0;
|
|
match &n.notification_type {
|
|
NotificationType::Follow => {
|
|
write!(f, "Follow {{ #{}, @{} }}", n.id, n.account.acct )
|
|
}
|
|
NotificationType::Favourite => {
|
|
if let Some(ref s) = n.status {
|
|
write!(f, "Favourite {{ #{}, acct: @{}, status: «{}» }}", n.id, n.account.acct, s.content )
|
|
} else {
|
|
write!(f, "Favourite {{ #{}, acct: @{}, status: -- }}", n.id, n.account.acct )
|
|
}
|
|
}
|
|
NotificationType::Mention => {
|
|
if let Some(ref s) = n.status {
|
|
write!(f, "Mention {{ #{}, acct: @{}, status: «{}» }}", n.id, n.account.acct, s.content )
|
|
} else {
|
|
write!(f, "Mention {{ #{}, acct: @{}, status: -- }}", n.id, n.account.acct )
|
|
}
|
|
}
|
|
NotificationType::Reblog => {
|
|
if let Some(ref s) = n.status {
|
|
write!(f, "Reblog {{ #{}, acct: @{}, status: «{}» }}", n.id, n.account.acct, s.content )
|
|
} else {
|
|
write!(f, "Reblog {{ #{}, acct: @{}, status: -- }}", n.id, n.account.acct )
|
|
}
|
|
}
|
|
NotificationType::Other(other) => {
|
|
f.write_str(&other)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct EventDisplay<'a>(pub &'a Event);
|
|
|
|
impl<'a> Display for EventDisplay<'a> {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
let n = self.0;
|
|
match n {
|
|
Event::Notification(n) => {
|
|
NotificationDisplay(n).fmt(f)
|
|
}
|
|
Event::Delete(id) => {
|
|
write!(f, "Delete {{ #{} }}", id)
|
|
}
|
|
Event::FiltersChanged => {
|
|
write!(f, "FiltersChanged")
|
|
}
|
|
Event::Heartbeat => {
|
|
write!(f, "Heartbeat")
|
|
}
|
|
Event::Update(s) => {
|
|
StatusDisplay(s).fmt(f)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct StatusDisplay<'a>(pub &'a Status);
|
|
|
|
impl<'a> Display for StatusDisplay<'a> {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "Status {{ #{}, acct: @{}, status: «{}», vis: {:?} }}", self.0.id, self.0.account.acct, self.0.content, self.0.visibility )
|
|
}
|
|
}
|
|
|