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