parent
568b1ff07a
commit
638594b11b
@ -0,0 +1,59 @@ |
||||
use crate::entities::notification::{Notification, NotificationType}; |
||||
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 ) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
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::Update(s) => { |
||||
write!(f, "Status {{ #{}, acct: @{}, status: «{}», vis: {:?} }}", s.id, s.account.acct, s.content, s.visibility ) |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue