Commit 95dcbd9c42

95dcbd9c4296622b88b3504bdf558d8ac55c291e

parent: 37c3ecdc3f

Unregistered key

vaw <git@nlih.de> · 2026-09-28 13:35 UTC

Save thread summary

Layout: unified · split

src/base.rs +122 −45
@@ -6,6 +6,7 @@ use std::collections::{BTreeSet, HashSet};
66
77use emojis::Emoji;
88use matrix_sdk::Client;
9use matrix_sdk::deserialized_responses::{ThreadSummary, ThreadSummaryStatus};
910use matrix_sdk::ruma::events::poll::start::PollStartEvent;
1011use matrix_sdk::ruma::events::poll::unstable_start::{
1112 UnstablePollStartEvent,
@@ -1392,6 +1393,38 @@ bitflags::bitflags! {
13921393 }
13931394}
13941395
1396pub struct Thread {
1397 messages: Messages,
1398
1399 root: Option<Message>,
1400 // TODO: check access
1401 pub(crate) summary: Option<ThreadSummary>,
1402}
1403
1404impl Thread {
1405 fn new(root: OwnedEventId) -> Self {
1406 Self {
1407 messages: Messages::new(ReceiptThread::Thread(root)),
1408 root: None,
1409 summary: None,
1410 }
1411 }
1412}
1413
1414impl Deref for Thread {
1415 type Target = Messages;
1416
1417 fn deref(&self) -> &Self::Target {
1418 &self.messages
1419 }
1420}
1421
1422impl DerefMut for Thread {
1423 fn deref_mut(&mut self) -> &mut Self::Target {
1424 &mut self.messages
1425 }
1426}
1427
13951428/// Information about room's the user's joined.
13961429pub struct RoomInfo {
13971430 /// The display name for this room.
@@ -1426,7 +1459,7 @@ pub struct RoomInfo {
14261459 pub unloaded_unstable_polls: HashMap<OwnedEventId, UnloadedUnstablePoll>,
14271460
14281461 /// A map of message identifiers to thread replies.
1429 threads: HashMap<OwnedEventId, Messages>,
1462 threads: HashMap<OwnedEventId, Thread>,
14301463
14311464 /// Whether the scrollback for this room is currently being fetched.
14321465 pub fetching: bool,
@@ -1494,24 +1527,28 @@ impl Default for RoomInfo {
14941527}
14951528
14961529impl RoomInfo {
1497 pub fn get_thread(&self, root: Option<&EventId>) -> Option<&Messages> {
1498 if let Some(thread_root) = root {
1499 self.threads.get(thread_root)
1530 pub fn get_messages(&self, thread_root: Option<&EventId>) -> Option<&Messages> {
1531 if let Some(thread_root) = thread_root {
1532 self.threads.get(thread_root).map(Deref::deref)
15001533 } else {
15011534 Some(&self.messages)
15021535 }
15031536 }
15041537
1505 pub fn get_thread_mut(&mut self, root: Option<OwnedEventId>) -> &mut Messages {
1506 if let Some(thread_root) = root {
1538 pub fn get_messages_mut(&mut self, thread_root: Option<OwnedEventId>) -> &mut Messages {
1539 if let Some(thread_root) = thread_root {
15071540 self.threads
15081541 .entry(thread_root.clone())
1509 .or_insert_with(|| Messages::thread(thread_root))
1542 .or_insert_with(|| Thread::new(thread_root))
15101543 } else {
15111544 &mut self.messages
15121545 }
15131546 }
15141547
1548 pub fn get_thread(&self, root: &EventId) -> Option<&Thread> {
1549 self.threads.get(root)
1550 }
1551
15151552 /// Get the event for the last message in a thread (or the thread root if there are no
15161553 /// in-thread replies yet).
15171554 ///
@@ -1641,7 +1678,7 @@ impl RoomInfo {
16411678 let key = loc.to_message_key()?;
16421679 let root = loc.to_thread_root();
16431680
1644 self.get_thread(root)?.get(key)
1681 self.get_messages(root)?.get(key)
16451682 }
16461683
16471684 /// Get an event for an identifier as mutable.
@@ -1651,7 +1688,7 @@ impl RoomInfo {
16511688 let key = loc.to_message_key()?;
16521689 let root = loc.to_thread_root();
16531690
1654 self.get_thread_mut(root.map(ToOwned::to_owned)).get_mut(key)
1691 self.get_messages_mut(root.map(ToOwned::to_owned)).get_mut(key)
16551692 }
16561693
16571694 /// Map an event identifier to its [`MessageKey`] and thread root.
@@ -1679,7 +1716,7 @@ impl RoomInfo {
16791716 pub fn get_message(&self, message_id: &MessageId) -> Option<&Message> {
16801717 let (root, key) = self.get_message_thread_key(message_id)?;
16811718
1682 self.get_thread(root)?.get(key)
1719 self.get_messages(root)?.get(key)
16831720 }
16841721
16851722 /// Get an event for an identifier as mutable.
@@ -1689,7 +1726,7 @@ impl RoomInfo {
16891726 let root = root.map(ToOwned::to_owned);
16901727 let key = key.to_owned();
16911728
1692 self.get_thread_mut(root).get_mut(&key)
1729 self.get_messages_mut(root).get_mut(&key)
16931730 }
16941731
16951732 pub fn redact(&mut self, ev: OriginalSyncRoomRedactionEvent) {
@@ -1703,7 +1740,7 @@ impl RoomInfo {
17031740 let edit_key = edit_key.clone();
17041741 let msg_loc = self.keys.get(msg_event_id).cloned();
17051742 if let Some(EventLocation::Message(thread, msg_key)) = msg_loc {
1706 if let Some(msg) = self.get_thread_mut(thread).get_mut(&msg_key) {
1743 if let Some(msg) = self.get_messages_mut(thread).get_mut(&msg_key) {
17071744 msg.remove_edit(&edit_key);
17081745 }
17091746 } else {
@@ -1760,14 +1797,25 @@ impl RoomInfo {
17601797 event_id: OwnedEventId,
17611798 thread_root: Option<OwnedEventId>,
17621799 message: Message,
1800 thread_summary: ThreadSummaryStatus,
17631801 ) {
17641802 let sender = message.sender.clone();
17651803
1804 if let ThreadSummaryStatus::Some(thread_summary) = thread_summary {
1805 let thread = self
1806 .threads
1807 .entry(event_id.clone())
1808 .or_insert_with(|| Thread::new(event_id.clone()));
1809
1810 thread.root = Some(message.clone());
1811 thread.summary = Some(thread_summary);
1812 }
1813
17661814 let key = MessageKey { ts: message.timestamp, id: event_id.clone().into() };
17671815 let loc = EventLocation::Message(thread_root.clone(), key.clone());
17681816 self.keys.insert(event_id.clone(), loc);
17691817
1770 let thread = self.get_thread_mut(thread_root);
1818 let thread = self.get_messages_mut(thread_root);
17711819 thread.insert_message(key, message);
17721820 self.set_implicit_receipt(sender, event_id);
17731821 }
@@ -1778,6 +1826,7 @@ impl RoomInfo {
17781826 event_id: OwnedEventId,
17791827 thread_root: Option<OwnedEventId>,
17801828 message: Message,
1829 thread_summary: ThreadSummaryStatus,
17811830 settings: &ApplicationSettings,
17821831 previews: &mut PreviewManager,
17831832 ) {
@@ -1787,7 +1836,7 @@ impl RoomInfo {
17871836 }
17881837 }
17891838
1790 self.insert_msglike(event_id, thread_root, message);
1839 self.insert_msglike(event_id, thread_root, message, thread_summary);
17911840 }
17921841
17931842 /// Insert a reaction to a message.
@@ -1812,6 +1861,7 @@ impl RoomInfo {
18121861 pub fn insert_sticker(
18131862 &mut self,
18141863 sticker: StickerEvent,
1864 thread_summary: ThreadSummaryStatus,
18151865 settings: &ApplicationSettings,
18161866 previews: &mut PreviewManager,
18171867 ) {
@@ -1820,7 +1870,7 @@ impl RoomInfo {
18201870 MessageLikeEvent::Original(OriginalMessageLikeEvent {
18211871 content:
18221872 StickerEventContent {
1823 relates_to: Some(Relation::Thread(Thread { event_id, .. })),
1873 relates_to: Some(Relation::Thread(ThreadRelation { event_id, .. })),
18241874 ..
18251875 },
18261876 ..
@@ -1828,7 +1878,14 @@ impl RoomInfo {
18281878 _ => None,
18291879 };
18301880
1831 self.insert_msglike_with_preview(event_id, thread_root, sticker.into(), settings, previews);
1881 self.insert_msglike_with_preview(
1882 event_id,
1883 thread_root,
1884 sticker.into(),
1885 thread_summary,
1886 settings,
1887 previews,
1888 );
18321889 }
18331890
18341891 /// Insert a reaction to a message.
@@ -1858,7 +1915,12 @@ impl RoomInfo {
18581915 }
18591916
18601917 /// Insert the start of a poll.
1861 pub fn insert_poll_start(&mut self, poll: PollStartEvent, own_user_id: &UserId) {
1918 pub fn insert_poll_start(
1919 &mut self,
1920 poll: PollStartEvent,
1921 own_user_id: &UserId,
1922 thread_summary: ThreadSummaryStatus,
1923 ) {
18621924 let event_id = poll.event_id().to_owned();
18631925 let key = MessageKey {
18641926 ts: poll.origin_server_ts().into(),
@@ -1895,7 +1957,7 @@ impl RoomInfo {
18951957 }
18961958 } else {
18971959 let thread_root = match &ev.content.relates_to {
1898 Some(Relation::Thread(Thread { event_id, .. })) => {
1960 Some(Relation::Thread(ThreadRelation { event_id, .. })) => {
18991961 Some(event_id.to_owned())
19001962 },
19011963 _ => None,
@@ -1907,13 +1969,13 @@ impl RoomInfo {
19071969 );
19081970 let msg = Message::new(msg, ev.sender, ev.origin_server_ts.into());
19091971
1910 self.insert_msglike(event_id, thread_root, msg);
1972 self.insert_msglike(event_id, thread_root, msg, thread_summary);
19111973 }
19121974 },
19131975 MessageLikeEvent::Redacted(ev) => {
19141976 let message: Message = ev.into();
19151977
1916 self.insert_msglike(event_id, None, message);
1978 self.insert_msglike(event_id, None, message, thread_summary);
19171979 },
19181980 }
19191981 }
@@ -1923,6 +1985,7 @@ impl RoomInfo {
19231985 &mut self,
19241986 poll: UnstablePollStartEvent,
19251987 own_user_id: &UserId,
1988 thread_summary: ThreadSummaryStatus,
19261989 ) {
19271990 let event_id = poll.event_id().to_owned();
19281991 let key = MessageKey {
@@ -1935,8 +1998,9 @@ impl RoomInfo {
19351998 match ev.content {
19361999 UnstablePollStartEventContent::New(content) => {
19372000 let thread_root = match &content.relates_to {
1938 Some(RelationWithoutReplacement::Thread(Thread {
1939 event_id, ..
2001 Some(RelationWithoutReplacement::Thread(ThreadRelation {
2002 event_id,
2003 ..
19402004 })) => Some(event_id.to_owned()),
19412005 _ => None,
19422006 };
@@ -1954,7 +2018,7 @@ impl RoomInfo {
19542018 );
19552019 let msg = Message::new(msg, ev.sender, ev.origin_server_ts.into());
19562020
1957 self.insert_msglike(event_id, thread_root, msg);
2021 self.insert_msglike(event_id, thread_root, msg, thread_summary);
19582022 },
19592023 UnstablePollStartEventContent::Replacement(content) => {
19602024 let loc = EventLocation::Poll(
@@ -1986,7 +2050,7 @@ impl RoomInfo {
19862050 MessageLikeEvent::Redacted(ev) => {
19872051 let message: Message = ev.into();
19882052
1989 self.insert_msglike(event_id, None, message);
2053 self.insert_msglike(event_id, None, message, thread_summary);
19902054 },
19912055 }
19922056 }
@@ -2054,7 +2118,7 @@ impl RoomInfo {
20542118
20552119 if let Some(EventLocation::Message(thread, key)) = msg_loc {
20562120 // The edited message is already loaded in cache
2057 let Some(msg) = self.get_thread_mut(thread).get_mut(&key) else {
2121 let Some(msg) = self.get_messages_mut(thread).get_mut(&key) else {
20582122 return;
20592123 };
20602124 msg.insert_edit(edit_key.clone(), replacement.new_content);
@@ -2077,28 +2141,34 @@ impl RoomInfo {
20772141 pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) {
20782142 let event_id = msg.event_id().to_owned();
20792143
2080 self.insert_msglike(event_id, None, msg.into());
2144 self.insert_msglike(event_id, None, msg.into(), ThreadSummaryStatus::None);
20812145 }
20822146
20832147 /// Inserts events that couldn't be decrypted into the scrollback.
2084 pub fn insert_encrypted(&mut self, msg: RoomEncryptedEvent) {
2148 pub fn insert_encrypted(
2149 &mut self,
2150 msg: RoomEncryptedEvent,
2151 thread_summary: ThreadSummaryStatus,
2152 ) {
20852153 let event_id = msg.event_id().to_owned();
20862154
2087 let thread_root = if let Some(EncryptedRelation::Thread(Thread { event_id, .. })) =
2088 msg.as_original().and_then(|ev| ev.content.relates_to.as_ref())
2089 {
2090 Some(event_id.to_owned())
2091 } else {
2092 None
2093 };
2155 let thread_root =
2156 if let Some(EncryptedRelation::Thread(ThreadRelation { event_id, .. })) =
2157 msg.as_original().and_then(|ev| ev.content.relates_to.as_ref())
2158 {
2159 Some(event_id.to_owned())
2160 } else {
2161 None
2162 };
20942163
2095 self.insert_msglike(event_id, thread_root, msg.into());
2164 self.insert_msglike(event_id, thread_root, msg.into(), thread_summary);
20962165 }
20972166
20982167 /// Insert a new message event, and prepare for image-preview if it has an image attachment.
20992168 pub fn insert_message(
21002169 &mut self,
21012170 ev: RoomMessageEvent,
2171 thread_summary: ThreadSummaryStatus,
21022172 settings: &ApplicationSettings,
21032173 previews: &mut PreviewManager,
21042174 ) {
@@ -2109,14 +2179,21 @@ impl RoomInfo {
21092179 self.insert_edit(ev, repl, settings, previews);
21102180 return;
21112181 },
2112 Some(Relation::Thread(Thread { event_id, .. })) => Some(event_id.to_owned()),
2182 Some(Relation::Thread(ThreadRelation { event_id, .. })) => Some(event_id.to_owned()),
21132183 _ => None,
21142184 };
21152185 let mut message: Message = ev.into();
21162186 if let Some(edits) = self.unloaded_edits.remove(&event_id) {
21172187 message.set_edits(edits);
21182188 }
2119 self.insert_msglike_with_preview(event_id, thread_root, message, settings, previews);
2189 self.insert_msglike_with_preview(
2190 event_id,
2191 thread_root,
2192 message,
2193 thread_summary,
2194 settings,
2195 previews,
2196 );
21202197 }
21212198
21222199 /// Indicates whether this room has unread messages.
@@ -2264,8 +2341,8 @@ impl RoomInfo {
22642341 let user_id = &settings.user_id;
22652342
22662343 let messages = match &thread {
2267 ReceiptThread::Main => self.get_thread(None),
2268 ReceiptThread::Thread(root) => self.get_thread(Some(root)),
2344 ReceiptThread::Main => self.get_messages(None),
2345 ReceiptThread::Thread(root) => self.get_messages(Some(root)),
22692346 _ => None,
22702347 };
22712348
@@ -3238,7 +3315,7 @@ pub mod tests {
32383315 MSG5_KEY.clone(),
32393316 );
32403317
3241 info.insert_message(event, &settings, &mut previews);
3318 info.insert_message(event, ThreadSummaryStatus::Unknown, &settings, &mut previews);
32423319
32433320 assert_eq!(
32443321 info.user_receipts
@@ -3270,8 +3347,8 @@ pub mod tests {
32703347 MSG2_KEY.clone(),
32713348 );
32723349
3273 info.insert_message(newer, &settings, &mut previews);
3274 info.insert_message(older, &settings, &mut previews);
3350 info.insert_message(newer, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3351 info.insert_message(older, ThreadSummaryStatus::Unknown, &settings, &mut previews);
32753352
32763353 assert_eq!(
32773354 info.user_receipts
@@ -3332,8 +3409,8 @@ pub mod tests {
33323409 MSG5_KEY.clone(),
33333410 );
33343411
3335 info.insert_message(older, &settings, &mut previews);
3336 info.insert_message(newer, &settings, &mut previews);
3412 info.insert_message(older, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3413 info.insert_message(newer, ThreadSummaryStatus::Unknown, &settings, &mut previews);
33373414 info.set_receipt(ReceiptThread::Main, TEST_USER2.clone(), MSG2_EVID.clone());
33383415
33393416 assert_eq!(
@@ -3356,7 +3433,7 @@ pub mod tests {
33563433 MSG2_KEY.clone(),
33573434 );
33583435
3359 info.insert_message(older, &settings, &mut previews);
3436 info.insert_message(older, ThreadSummaryStatus::Unknown, &settings, &mut previews);
33603437
33613438 assert_eq!(
33623439 info.user_receipts
src/message/html.rs +1
@@ -717,6 +717,7 @@ impl StyleTreeNode {
717717}
718718
719719/// A processed HTML document.
720#[derive(Clone)]
720721pub struct StyleTree {
721722 pub(super) children: StyleTreeChildren,
722723}
src/message/mod.rs +11 −13
@@ -90,10 +90,6 @@ impl Messages {
9090 Self::new(ReceiptThread::Main)
9191 }
9292
93 pub fn thread(root: OwnedEventId) -> Self {
94 Self::new(ReceiptThread::Thread(root))
95 }
96
9793 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) {
9894 let mut msg = msg.into();
9995 if let MessageEvent::Original(ev, edits) = &mut msg.event {
@@ -421,7 +417,7 @@ fn redaction_reason_event(ev: SyncRoomRedactionEvent) -> Option<String> {
421417fn has_reply_fallback(relation: Option<&Relation<RoomMessageEventContentWithoutRelation>>) -> bool {
422418 matches!(
423419 relation,
424 Some(Relation::Reply(_) | Relation::Thread(Thread { in_reply_to: Some(_), .. }))
420 Some(Relation::Reply(_) | Relation::Thread(ThreadRelation { in_reply_to: Some(_), .. }))
425421 )
426422}
427423
@@ -1022,6 +1018,7 @@ impl<'a> MessageFormatter<'a> {
10221018 }
10231019}
10241020
1021#[derive(Clone)]
10251022pub struct Message {
10261023 pub event: MessageEvent,
10271024 pub sender: OwnedUserId,
@@ -1059,7 +1056,7 @@ impl Message {
10591056 MessageEvent::Sticker(ev, ..) => {
10601057 return match &ev.content.relates_to {
10611058 Some(Relation::Reply(reply)) => Some(reply.in_reply_to.event_id.clone()),
1062 Some(Relation::Thread(Thread {
1059 Some(Relation::Thread(ThreadRelation {
10631060 in_reply_to: Some(in_reply_to),
10641061 is_falling_back: false,
10651062 ..
@@ -1073,7 +1070,7 @@ impl Message {
10731070
10741071 match &content.relates_to {
10751072 Some(Relation::Reply(reply)) => Some(reply.in_reply_to.event_id.clone()),
1076 Some(Relation::Thread(Thread {
1073 Some(Relation::Thread(ThreadRelation {
10771074 in_reply_to: Some(in_reply_to),
10781075 is_falling_back: false,
10791076 ..
@@ -1097,7 +1094,7 @@ impl Message {
10971094 };
10981095
10991096 match &content.relates_to {
1100 Some(Relation::Thread(Thread {
1097 Some(Relation::Thread(ThreadRelation {
11011098 event_id,
11021099 in_reply_to: Some(in_reply_to),
11031100 is_falling_back: true,
@@ -1389,8 +1386,9 @@ impl Message {
13891386 protos.extend(react_protos);
13901387 }
13911388
1392 if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(Some(id))) {
1393 fmt.push_thread_reply_count(thread.len(), &mut text, style);
1389 if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(id)) {
1390 let len = thread.summary.as_ref().map(|s| s.num_replies).unwrap_or_default();
1391 fmt.push_thread_reply_count(thread.len().max(len as usize), &mut text, style);
13941392 }
13951393
13961394 (text, protos)
@@ -1714,15 +1712,15 @@ pub mod tests {
17141712 assert!(has_reply_fallback(Some(&reply)));
17151713
17161714 let thread_reply: Relation<RoomMessageEventContentWithoutRelation> =
1717 Relation::Thread(Thread::reply(root.clone(), target.clone()));
1715 Relation::Thread(ThreadRelation::reply(root.clone(), target.clone()));
17181716 assert!(has_reply_fallback(Some(&thread_reply)));
17191717
17201718 let thread_fallback: Relation<RoomMessageEventContentWithoutRelation> =
1721 Relation::Thread(Thread::plain(root.clone(), target));
1719 Relation::Thread(ThreadRelation::plain(root.clone(), target));
17221720 assert!(has_reply_fallback(Some(&thread_fallback)));
17231721
17241722 let thread_without_fallback: Relation<RoomMessageEventContentWithoutRelation> =
1725 Relation::Thread(Thread::without_fallback(root));
1723 Relation::Thread(ThreadRelation::without_fallback(root));
17261724 assert!(!has_reply_fallback(Some(&thread_without_fallback)));
17271725 assert!(!has_reply_fallback(None));
17281726 }
src/prelude.rs +1 −1
@@ -12,7 +12,7 @@ pub use std::time::{Duration, Instant};
1212pub use matrix_sdk::room_preview::RoomPreview;
1313pub use matrix_sdk::ruma::events::AnySyncStateEvent;
1414pub use matrix_sdk::ruma::events::receipt::ReceiptThread;
15pub use matrix_sdk::ruma::events::relation::Thread;
15pub use matrix_sdk::ruma::events::relation::Thread as ThreadRelation;
1616pub use matrix_sdk::ruma::events::room::MediaSource;
1717pub use matrix_sdk::ruma::events::room::encrypted::Relation as EncryptedRelation;
1818pub use matrix_sdk::ruma::events::room::message::{
src/tests.rs +1 −1
@@ -131,7 +131,7 @@ pub fn mock_room() -> RoomInfo {
131131 let mut room = RoomInfo::default();
132132 room.name = Some("Watercooler Discussion".into());
133133 room.keys = mock_keys();
134 *room.get_thread_mut(None) = mock_messages();
134 *room.get_messages_mut(None) = mock_messages();
135135
136136 let user_id = TEST_USER2.clone();
137137 let name = "User 2";
src/windows/room/chat.rs +1 −1
@@ -424,7 +424,7 @@ impl ChatState {
424424 Some(EchoLocation::Replaced(id)) => id,
425425 Some(EchoLocation::Message(thread, orig_key)) => {
426426 let Some(MessageEvent::Local(_, handle, _)) = info
427 .get_thread(thread.as_deref())
427 .get_messages(thread.as_deref())
428428 .and_then(|thread| thread.get(orig_key))
429429 .map(|msg| &msg.event)
430430 else {
src/windows/room/scrollback.rs +1 −1
@@ -163,7 +163,7 @@ impl ScrollbackState {
163163 }
164164
165165 pub fn get_thread<'a>(&self, info: &'a RoomInfo) -> Option<&'a Messages> {
166 info.get_thread(self.thread.as_deref())
166 info.get_messages(self.thread.as_deref())
167167 }
168168
169169 pub fn messages<'a>(
src/worker.rs +27 −17
@@ -14,7 +14,7 @@ use matrix_sdk::AuthSession;
1414use matrix_sdk::authentication::matrix::MatrixSession;
1515use matrix_sdk::config::{RequestConfig, SyncSettings};
1616use matrix_sdk::deserialized_responses::RawSyncOrStrippedState;
17use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind};
17use matrix_sdk::deserialized_responses::{ThreadSummaryStatus, TimelineEvent, TimelineEventKind};
1818use matrix_sdk::encryption::{BackupDownloadStrategy, EncryptionSettings};
1919use matrix_sdk::event_cache::DecryptionRetryRequest;
2020use matrix_sdk::event_handler::Ctx;
@@ -116,7 +116,7 @@ const RECEIPT_RETRY_INTERVAL: Duration = Duration::from_secs(2);
116116type ReceiptKey = (OwnedRoomId, ReceiptThread, ReceiptType);
117117type ReceiptUpdate = (OwnedRoomId, ReceiptThread, ReceiptType, OwnedEventId);
118118
119type MessageAndReceipts = (AnyTimelineEvent, ReceiptThread, Vec<OwnedUserId>);
119type MessageAndReceipts = (AnyTimelineEvent, ThreadSummaryStatus, ReceiptThread, Vec<OwnedUserId>);
120120type MessageFetchResult = IambResult<(bool, Vec<MessageAndReceipts>)>;
121121
122122fn initial_devname() -> String {
@@ -462,7 +462,7 @@ async fn get_receipts_for_timeline_events(
462462 },
463463 };
464464
465 msgs.push((msg, thread, receipts));
465 msgs.push((msg, ev.thread_summary, thread, receipts));
466466 }
467467
468468 if !redecryption_requests.is_empty() {
@@ -505,7 +505,7 @@ fn insert_msgs_and_receipts(
505505 previews: &mut PreviewManager,
506506 settings: &ApplicationSettings,
507507) {
508 for (msg, thread, receipts) in msgs {
508 for (msg, thread_summary, thread, receipts) in msgs {
509509 let sender = msg.sender().to_owned();
510510 let _ = presences.get_or_default(sender);
511511
@@ -515,25 +515,25 @@ fn insert_msgs_and_receipts(
515515
516516 match msg {
517517 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomEncrypted(msg)) => {
518 info.insert_encrypted(msg);
518 info.insert_encrypted(msg, thread_summary);
519519 },
520520 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(msg)) => {
521 info.insert_message(msg, settings, previews);
521 info.insert_message(msg, thread_summary, settings, previews);
522522 },
523523 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::Reaction(ev)) => {
524524 info.insert_reaction_with_preview(ev, settings, previews);
525525 },
526526 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::Sticker(ev)) => {
527 info.insert_sticker(ev, settings, previews);
527 info.insert_sticker(ev, thread_summary, settings, previews);
528528 },
529529 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomRedaction(..)) => {
530530 // ignoring redaction events because we get them bundled with the redacted event
531531 },
532532 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollStart(ev)) => {
533 info.insert_poll_start(ev, &settings.user_id);
533 info.insert_poll_start(ev, &settings.user_id, thread_summary);
534534 },
535535 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::UnstablePollStart(ev)) => {
536 info.insert_unstable_poll_start(ev, &settings.user_id);
536 info.insert_unstable_poll_start(ev, &settings.user_id, thread_summary);
537537 },
538538 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollResponse(ev)) => {
539539 if let MessageLikeEvent::Original(ev) = ev {
@@ -977,7 +977,9 @@ fn insert_local_echo(
977977 // XXX: Show echo on edited message
978978 return Ok(());
979979 },
980 Some(Relation::Thread(Thread { event_id, .. })) => Some(event_id.to_owned()),
980 Some(Relation::Thread(ThreadRelation { event_id, .. })) => {
981 Some(event_id.to_owned())
982 },
981983 _ => None,
982984 };
983985
@@ -989,7 +991,7 @@ fn insert_local_echo(
989991 info.echo_keys
990992 .insert(transaction_id, EchoLocation::Message(thread.clone(), key.clone()));
991993
992 let thread = info.get_thread_mut(thread);
994 let thread = info.get_messages_mut(thread);
993995 thread.insert(key, msg);
994996 },
995997 LocalEchoContent::Redaction { .. } => {
@@ -1044,7 +1046,7 @@ async fn subscribe_sendqueue_forever(client: &Client, store: &AsyncProgramStore)
10441046 continue;
10451047 };
10461048
1047 let Some(msg) = info.get_thread_mut(thread).get_mut(&key) else {
1049 let Some(msg) = info.get_messages_mut(thread).get_mut(&key) else {
10481050 tracing::debug!(?transaction_id, "replaced local echo not found");
10491051 continue;
10501052 };
@@ -1070,7 +1072,7 @@ async fn subscribe_sendqueue_forever(client: &Client, store: &AsyncProgramStore)
10701072 let location = std::mem::replace(location, EchoLocation::Replaced(event_id));
10711073
10721074 if let EchoLocation::Message(thread, key) = location {
1073 info.get_thread_mut(thread).remove(&key);
1075 info.get_messages_mut(thread).remove(&key);
10741076 }
10751077 }
10761078 },
@@ -1805,7 +1807,7 @@ impl ClientWorker {
18051807 let info = rooms.get_or_default(room_id.to_owned());
18061808
18071809 let full_ev = ev.into_full_event(room_id.to_owned());
1808 info.insert_message(full_ev, settings, previews);
1810 info.insert_message(full_ev, ThreadSummaryStatus::Unknown, settings, previews);
18091811
18101812 update_event_receipts(info, &room, event_id).await;
18111813 }
@@ -1857,7 +1859,7 @@ impl ClientWorker {
18571859 let info = rooms.get_or_default(room_id.to_owned());
18581860
18591861 let full_ev = ev.into_full_event(room_id.to_owned());
1860 info.insert_sticker(full_ev, settings, previews);
1862 info.insert_sticker(full_ev, ThreadSummaryStatus::Unknown, settings, previews);
18611863
18621864 update_event_receipts(info, &room, event_id).await;
18631865 }
@@ -1908,7 +1910,11 @@ impl ClientWorker {
19081910 let info = rooms.get_or_default(room_id.to_owned());
19091911
19101912 let full_ev = ev.into_full_event(room_id.to_owned());
1911 info.insert_poll_start(full_ev, &settings.user_id);
1913 info.insert_poll_start(
1914 full_ev,
1915 &settings.user_id,
1916 ThreadSummaryStatus::Unknown,
1917 );
19121918
19131919 update_event_receipts(info, &room, event_id).await;
19141920 }
@@ -1933,7 +1939,11 @@ impl ClientWorker {
19331939 let info = rooms.get_or_default(room_id.to_owned());
19341940
19351941 let full_ev = ev.into_full_event(room_id.to_owned());
1936 info.insert_unstable_poll_start(full_ev, &settings.user_id);
1942 info.insert_unstable_poll_start(
1943 full_ev,
1944 &settings.user_id,
1945 ThreadSummaryStatus::Unknown,
1946 );
19371947
19381948 update_event_receipts(info, &room, event_id).await;
19391949 }