mastodon_async_entities/
notification.rs

1//! Module containing all info about notifications.
2
3use std::fmt::Display;
4
5use super::{account::Account, status::Status};
6use serde::{Deserialize, Serialize};
7use time::{serde::iso8601, OffsetDateTime};
8
9/// A struct containing info about a notification.
10#[allow(clippy::derive_partial_eq_without_eq)]
11#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
12pub struct Notification {
13    /// The notification ID.
14    pub id: NotificationId,
15    /// The type of notification.
16    #[serde(rename = "type")]
17    pub notification_type: NotificationType,
18    /// The time the notification was created.
19    #[serde(with = "iso8601")]
20    pub created_at: OffsetDateTime,
21    /// The Account sending the notification to the user.
22    pub account: Account,
23    /// The Status associated with the notification, if applicable.
24    pub status: Option<Status>,
25}
26
27/// Wrapper type for a notification ID string
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
29#[serde(transparent)]
30pub struct NotificationId(String);
31
32impl AsRef<str> for NotificationId {
33    fn as_ref(&self) -> &str {
34        &self.0
35    }
36}
37
38impl NotificationId {
39    pub fn new(value: impl Into<String>) -> Self {
40        Self(value.into())
41    }
42}
43
44impl Display for NotificationId {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        write!(f, "{}", self.0)
47    }
48}
49
50static_assertions::assert_not_impl_any!(
51    NotificationId: PartialEq<crate::account::AccountId>,
52    PartialEq<crate::attachment::AttachmentId>,
53    PartialEq<crate::filter::FilterId>,
54    PartialEq<crate::mention::MentionId>,
55    PartialEq<crate::list::ListId>,
56    PartialEq<crate::push::SubscriptionId>,
57    PartialEq<crate::relationship::RelationshipId>,
58    PartialEq<crate::report::ReportId>,
59    PartialEq<crate::status::StatusId>,
60);
61
62/// The type of notification.
63#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
64#[serde(rename_all = "lowercase")]
65pub enum NotificationType {
66    /// Someone mentioned the application client in another status.
67    Mention,
68    /// Someone reblogged one of the application client's statuses.
69    Reblog,
70    /// Someone favourited one of the application client's statuses.
71    Favourite,
72    /// Someone followed the application client.
73    Follow,
74    /// Someone asked to followed the application client when follow requests must be approved.
75    #[serde(rename = "follow_request")]
76    FollowRequest,
77    /// A poll the application client previously voted in has ended.
78    Poll,
79}