96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1 | use futures_util::{StreamExt, stream}; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 2 | use matrix_sdk::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 3 | Client, Room, RoomState, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 4 | deserialized_responses::SyncOrStrippedState, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 5 | latest_events::LatestEventValue, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 6 | notification_settings::{IsEncrypted, IsOneToOne, NotificationSettings}, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 7 | ruma::events::{ |
fa5b4e09943a | atagen | 2026-10-24 09:33 UTC | 8 | AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnySyncTimelineEvent, StateEventType, |
fa5b4e09943a | atagen | 2026-10-24 09:33 UTC | 9 | SyncStateEvent, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 10 | room::message::{Relation, RoomMessageEventContent}, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 11 | space::child::SpaceChildEventContent, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 12 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 13 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 14 | use matrix_sdk_ui::spaces::{SpaceRoom, SpaceService}; |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 15 | use ruma::{ |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 16 | OwnedRoomId, |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 17 | serde::{JsonObject, Raw}, |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 18 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 19 | |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 20 | use super::message_kind; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 21 | use crate::{ |
5d2974de5826 | atagen | 2026-10-08 11:29 UTC | 22 | LatestEvent, MediaId, MessageKind, RoomHero, RoomMembership, RoomNotificationMode, RoomSummary, |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 23 | SendState, SpaceChild, space_order, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 24 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 25 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 26 | pub(crate) async fn room_summaries(client: &Client, spaces: &SpaceService) -> Vec<RoomSummary> { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 27 | let settings = client.notification_settings().await; |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 28 | let settings = &settings; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 29 | let mut summaries = stream::iter(client.rooms()) |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 30 | .map(|room| async move { room_summary(&room, spaces, settings).await }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 31 | .buffer_unordered(16) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 32 | .collect::<Vec<_>>() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 33 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 34 | summaries.sort_by(|left, right| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 35 | right |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 36 | .latest_event_timestamp_ms |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 37 | .cmp(&left.latest_event_timestamp_ms) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 38 | .then_with(|| left.name.to_lowercase().cmp(&right.name.to_lowercase())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 39 | .then_with(|| left.room_id.cmp(&right.room_id)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 40 | }); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | summaries |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 43 | |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 44 | async fn room_summary( |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 45 | room: &Room, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 46 | spaces: &SpaceService, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 47 | settings: &NotificationSettings, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 48 | ) -> RoomSummary { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 49 | let name = room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 50 | .display_name() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 51 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 52 | .map(|name| name.to_string()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 53 | .unwrap_or_else(|_| room.room_id().to_string()); |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 54 | let joined = room.state() == RoomState::Joined; |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 55 | let custom_notification_mode = if joined { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 56 | settings |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 57 | .get_user_defined_room_notification_mode(room.room_id()) |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 58 | .await |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 59 | } else { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 60 | None |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 61 | }; |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 62 | if let Some(mode) = custom_notification_mode { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 63 | room.update_cached_user_defined_notification_mode(mode); |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 64 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 65 | let effective_notification_mode = match custom_notification_mode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 66 | Some(mode) => Some(mode), |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 67 | None if joined => match room.latest_encryption_state().await { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 68 | Ok(state) => Some( |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 69 | settings |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 70 | .get_default_room_notification_mode( |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 71 | IsEncrypted::from(state.is_encrypted()), |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 72 | IsOneToOne::from(room.active_members_count() == 2), |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 73 | ) |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 74 | .await, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 75 | ), |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 76 | Err(_) => None, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 77 | }, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 78 | None => None, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 79 | }; |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 80 | let power_levels = if joined { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 81 | room.power_levels().await.ok() |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 82 | } else { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 83 | None |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 84 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 85 | let inviter = match room.state() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 86 | RoomState::Invited => room |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 87 | .invite_details() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 88 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 89 | .ok() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 90 | .map(|invite| invite.inviter_id), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 91 | _ => None, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 92 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 93 | let children = if room.is_space() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 94 | space_children(room).await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 95 | } else { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 96 | Vec::new() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 97 | }; |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 98 | let thread_unreads = super::stored_thread_unreads(room).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 99 | RoomSummary { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 100 | room_id: room.room_id().to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 101 | name, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 102 | membership: membership(room.state()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 103 | unread_messages: room.num_unread_messages(), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 104 | unread_mentions: room.num_unread_mentions() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 105 | + thread_unreads |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 106 | .values() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 107 | .map(|unread| unread.mentions) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 108 | .sum::<u64>(), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 109 | unread_notifications: room.num_unread_notifications(), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 110 | thread_unreads, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 111 | encrypted: room.encryption_state().is_encrypted(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 112 | space: room.is_space(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 113 | direct: room.is_direct().await.unwrap_or(false), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 114 | favourite: room.is_favourite(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 115 | low_priority: room.is_low_priority(), |
5d2974de5826 | atagen | 2026-10-08 11:29 UTC | 116 | avatar: room.avatar_url().as_deref().map(MediaId::plain), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 117 | latest_event_timestamp_ms: room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 118 | .latest_event_timestamp() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 119 | .map(|value| value.get().into()), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 120 | latest_event: latest_event(room), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 121 | notification_mode: effective_notification_mode.map(notification_mode), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 122 | notification_mode_custom: custom_notification_mode.is_some(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 123 | topic: room.topic(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 124 | canonical_alias: room.canonical_alias(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 125 | joined_members: room.joined_members_count(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 126 | invited_members: room.invited_members_count(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 127 | heroes: room |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 128 | .heroes() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 129 | .into_iter() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 130 | .map(|hero| RoomHero { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 131 | user_id: hero.user_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 132 | display_name: hero.display_name, |
5d2974de5826 | atagen | 2026-10-08 11:29 UTC | 133 | avatar: hero.avatar_url.as_deref().map(MediaId::plain), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 134 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 135 | .collect(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 136 | successor: room.successor_room().map(|successor| successor.room_id), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 137 | inviter, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 138 | parent_spaces: spaces |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 139 | .joined_parents_of_child(room.room_id()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 140 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 141 | .into_iter() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 142 | .map(|parent| parent.room_id) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 143 | .collect(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 144 | children, |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 145 | space_order: if room.is_space() { |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 146 | stored_space_order(room).await |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 147 | } else { |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 148 | None |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 149 | }, |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 150 | can_edit_packs: power_levels |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 151 | .as_ref() |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 152 | .is_some_and(|levels| super::can_edit_packs_with(room, levels)), |
fa5b4e09943a | atagen | 2026-10-24 09:33 UTC | 153 | pinned_events: room.pinned_event_ids().unwrap_or_default(), |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 154 | can_pin: power_levels.as_ref().is_some_and(|levels| { |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 155 | levels.user_can_send_state(room.own_user_id(), StateEventType::RoomPinnedEvents) |
3e5a785a7273 | atagen | 2026-10-28 07:57 UTC | 156 | }), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 157 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 158 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 159 | |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 160 | /// None when unset or when another client wrote something msc3230 doesn't allow |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 161 | pub(crate) async fn stored_space_order(room: &Room) -> Option<String> { |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 162 | room.account_data(space_order::EVENT_TYPE.into()) |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 163 | .await |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 164 | .ok()?? |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 165 | .get_field::<Raw<JsonObject>>("content") |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 166 | .ok()?? |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 167 | .get_field::<String>("order") |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 168 | .ok()? |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 169 | .filter(|order| space_order::valid(order)) |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 170 | } |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 171 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 172 | const fn membership(state: RoomState) -> RoomMembership { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 173 | match state { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 174 | RoomState::Joined => RoomMembership::Joined, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 175 | RoomState::Invited => RoomMembership::Invited, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 176 | RoomState::Left => RoomMembership::Left, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 177 | RoomState::Knocked => RoomMembership::Knocked, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 178 | RoomState::Banned => RoomMembership::Banned, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 179 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 180 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 181 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 182 | /// what the space itself lists, straight from local state. redacted children don't count |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 183 | async fn space_children(room: &Room) -> Vec<OwnedRoomId> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 184 | let Ok(events) = room |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 185 | .get_state_events_static::<SpaceChildEventContent>() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 186 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 187 | else { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 188 | return Vec::new(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 189 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 190 | events |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 191 | .into_iter() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 192 | .filter_map(|event| match event.deserialize().ok()? { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 193 | SyncOrStrippedState::Sync(SyncStateEvent::Original(event)) => Some(event.state_key), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 194 | SyncOrStrippedState::Stripped(event) => Some(event.state_key), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 195 | SyncOrStrippedState::Sync(SyncStateEvent::Redacted(_)) => None, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 196 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 197 | .collect() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 198 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 199 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 200 | fn latest_event(room: &Room) -> Option<LatestEvent> { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 201 | let own = || Some(room.own_user_id().to_owned()); |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 202 | let local = |local: &matrix_sdk::latest_events::LocalLatestEventValue| { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 203 | let preview = match local.content.deserialize() { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 204 | Ok(AnyMessageLikeEventContent::RoomMessage(content)) => preview(&content), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 205 | _ => (None, None), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 206 | }; |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 207 | (preview, Some(local.timestamp)) |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 208 | }; |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 209 | let (sender, (kind, body), timestamp, send_state) = match room.latest_event() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 210 | LatestEventValue::None => return None, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 211 | LatestEventValue::Remote(event) => { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 212 | let preview = match event.raw().deserialize() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 213 | Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 214 | message, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 215 | ))) => message |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 216 | .as_original() |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 217 | .map_or((None, None), |message| preview(&message.content)), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 218 | _ => (None, None), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 219 | }; |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 220 | (event.sender(), preview, event.timestamp(), SendState::Sent) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 221 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 222 | LatestEventValue::RemoteInvite { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 223 | timestamp, inviter, .. |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 224 | } => (inviter, (None, None), Some(timestamp), SendState::Sent), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 225 | LatestEventValue::LocalIsSending(value) => { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 226 | let (preview, timestamp) = local(&value); |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 227 | (own(), preview, timestamp, SendState::Sending) |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 228 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 229 | LatestEventValue::LocalHasBeenSent { value, .. } => { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 230 | let (preview, timestamp) = local(&value); |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 231 | (own(), preview, timestamp, SendState::Sent) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 232 | } |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 233 | // the sdk won't say whether it'll retry, so assume the user has to |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 234 | LatestEventValue::LocalCannotBeSent(value) => { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 235 | let (preview, timestamp) = local(&value); |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 236 | ( |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 237 | own(), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 238 | preview, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 239 | timestamp, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 240 | SendState::Failed { will_retry: false }, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 241 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 242 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 243 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 244 | Some(LatestEvent { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 245 | sender, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 246 | kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 247 | body, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 248 | timestamp_ms: timestamp.map(|timestamp| timestamp.get().into()), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 249 | send_state, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 250 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 251 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 252 | |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 253 | /// the latest event of an edited message is the edit, whose own body is the `* fallback` |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 254 | fn preview(content: &RoomMessageEventContent) -> (Option<MessageKind>, Option<String>) { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 255 | let msgtype = match &content.relates_to { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 256 | Some(Relation::Replacement(replacement)) => &replacement.new_content.msgtype, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 257 | _ => &content.msgtype, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 258 | }; |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 259 | (Some(message_kind(msgtype)), Some(msgtype.body().to_owned())) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 260 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 261 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 262 | pub(crate) fn space_child(room: SpaceRoom) -> SpaceChild { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 263 | SpaceChild { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 264 | name: room.display_name, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 265 | room_id: room.room_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 266 | topic: room.topic, |
5d2974de5826 | atagen | 2026-10-08 11:29 UTC | 267 | avatar: room.avatar_url.as_deref().map(MediaId::plain), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 268 | canonical_alias: room.canonical_alias, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 269 | joined_members: room.num_joined_members, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 270 | space: room.room_type == Some(ruma::room::RoomType::Space), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 271 | children_count: room.children_count, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 272 | membership: room.state.map(membership), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 273 | via: room.via, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 274 | suggested: room.suggested, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 275 | world_readable: room.world_readable, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 276 | guest_can_join: room.guest_can_join, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 277 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 278 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 279 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 280 | pub(crate) const fn notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 281 | mode: matrix_sdk::notification_settings::RoomNotificationMode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 282 | ) -> RoomNotificationMode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 283 | match mode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 284 | matrix_sdk::notification_settings::RoomNotificationMode::AllMessages => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 285 | RoomNotificationMode::AllMessages |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 286 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 287 | matrix_sdk::notification_settings::RoomNotificationMode::MentionsAndKeywordsOnly => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 288 | RoomNotificationMode::MentionsAndKeywordsOnly |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 289 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 290 | matrix_sdk::notification_settings::RoomNotificationMode::Mute => RoomNotificationMode::Mute, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 291 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 292 | } |