96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1 | use futures_util::{StreamExt, stream}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 2 | use matrix_sdk::{Client, Room, RoomState}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 3 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 4 | use crate::{RoomMembership, RoomNotificationMode, RoomSummary}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 5 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 6 | pub(crate) async fn room_summaries(client: &Client) -> Vec<RoomSummary> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 7 | let mut summaries = stream::iter(client.rooms()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 8 | .map(|room| async move { room_summary(&room).await }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | .buffer_unordered(16) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 10 | .collect::<Vec<_>>() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 11 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 12 | summaries.sort_by(|left, right| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 13 | right |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 14 | .latest_event_timestamp_ms |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 15 | .cmp(&left.latest_event_timestamp_ms) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 16 | .then_with(|| left.name.to_lowercase().cmp(&right.name.to_lowercase())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 17 | .then_with(|| left.room_id.cmp(&right.room_id)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 18 | }); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 19 | summaries |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 20 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 21 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 22 | async fn room_summary(room: &Room) -> RoomSummary { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 23 | let name = room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 24 | .display_name() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 25 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 26 | .map(|name| name.to_string()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 27 | .unwrap_or_else(|_| room.room_id().to_string()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 28 | let custom_notification_mode = room.user_defined_notification_mode().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 29 | let effective_notification_mode = match custom_notification_mode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 30 | Some(mode) => Some(mode), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 31 | None => room.notification_mode().await, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 32 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 33 | RoomSummary { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 34 | room_id: room.room_id().to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 35 | name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 36 | membership: match room.state() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 37 | RoomState::Joined => RoomMembership::Joined, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 38 | RoomState::Invited => RoomMembership::Invited, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 39 | RoomState::Left => RoomMembership::Left, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 40 | RoomState::Knocked => RoomMembership::Knocked, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | RoomState::Banned => RoomMembership::Banned, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 43 | unread_messages: room.num_unread_messages(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 44 | unread_mentions: room.num_unread_mentions(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 45 | encrypted: room.encryption_state().is_encrypted(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 46 | space: room.is_space(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 47 | direct: room.is_direct().await.unwrap_or(false), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 48 | favourite: room.is_favourite(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 49 | low_priority: room.is_low_priority(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 50 | avatar: room.avatar_url(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 51 | latest_event_timestamp_ms: room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 52 | .latest_event_timestamp() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 53 | .map(|value| value.get().into()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 54 | notification_mode: effective_notification_mode.map(notification_mode), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 55 | notification_mode_custom: custom_notification_mode.is_some(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 56 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 57 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 58 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 59 | pub(crate) const fn notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 60 | mode: matrix_sdk::notification_settings::RoomNotificationMode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 61 | ) -> RoomNotificationMode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 62 | match mode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 63 | matrix_sdk::notification_settings::RoomNotificationMode::AllMessages => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 64 | RoomNotificationMode::AllMessages |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 65 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 66 | matrix_sdk::notification_settings::RoomNotificationMode::MentionsAndKeywordsOnly => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 67 | RoomNotificationMode::MentionsAndKeywordsOnly |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 68 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 69 | matrix_sdk::notification_settings::RoomNotificationMode::Mute => RoomNotificationMode::Mute, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 70 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 71 | } |