Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ pub struct NormalizedNotification {
/// Grouped users (for renote:grouped type)
#[serde(skip_serializing_if = "Option::is_none")]
pub users: Option<Vec<NormalizedUser>>,
/// Assigned role (for roleAssigned type)
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<UserRole>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -1154,6 +1157,8 @@ pub struct RawNotification {
pub reactions: Option<Vec<RawReactionInfo>>,
/// Grouped users (for renote:grouped type from notifications-grouped API)
pub users: Option<Vec<RawUser>>,
/// Assigned role (for roleAssigned type)
pub role: Option<UserRole>,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -1508,6 +1513,7 @@ impl RawNotification {
users: self
.users
.map(|us| us.into_iter().map(Into::into).collect()),
role: self.role,
}
}
}
Expand Down
Loading