diff --git a/src/api.rs b/src/api.rs index 03a3422..efaa19d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -2851,6 +2851,41 @@ mod tests { assert_eq!(notifs[0].reaction.as_deref(), Some(":star:")); } + #[tokio::test] + async fn get_notifications_parses_role_assigned() { + let server = MockServer::start().await; + Mock::given(method("POST")) + .and(path("/api/i/notifications")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!([{ + "id": "notif1", + "createdAt": "2025-01-01T00:00:00.000Z", + "type": "roleAssigned", + "role": { + "id": "role1", + "name": "Active", + "color": "#ff0000", + "iconUrl": "https://example.com/role.png", + "description": "active users", + "displayOrder": 0, + "isModerator": false + } + }]))) + .mount(&server) + .await; + + let client = MisskeyClient::with_base_url(&server.uri()); + let notifs = client + .get_notifications("h", "token", "acc1", TimelineOptions::default()) + .await + .unwrap(); + assert_eq!(notifs.len(), 1); + assert_eq!(notifs[0].notification_type, "roleAssigned"); + let role = notifs[0].role.as_ref().expect("role present"); + assert_eq!(role.name, "Active"); + assert_eq!(role.color.as_deref(), Some("#ff0000")); + assert_eq!(role.icon_url.as_deref(), Some("https://example.com/role.png")); + } + #[tokio::test] async fn search_notes_parses() { let server = MockServer::start().await; diff --git a/src/models.rs b/src/models.rs index a859968..c619649 100644 --- a/src/models.rs +++ b/src/models.rs @@ -366,6 +366,9 @@ pub struct NormalizedNotification { /// Grouped users (for renote:grouped type) #[serde(skip_serializing_if = "Option::is_none")] pub users: Option>, + /// Assigned role (for roleAssigned type) + #[serde(skip_serializing_if = "Option::is_none")] + pub role: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1154,6 +1157,8 @@ pub struct RawNotification { pub reactions: Option>, /// Grouped users (for renote:grouped type from notifications-grouped API) pub users: Option>, + /// Assigned role (for roleAssigned type) + pub role: Option, } #[derive(Debug, Deserialize)] @@ -1508,6 +1513,7 @@ impl RawNotification { users: self .users .map(|us| us.into_iter().map(Into::into).collect()), + role: self.role, } } }