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};
6 6
7use emojis::Emoji; 7use emojis::Emoji;
8use matrix_sdk::Client; 8use matrix_sdk::Client;
9use matrix_sdk::deserialized_responses::{ThreadSummary, ThreadSummaryStatus};
9use matrix_sdk::ruma::events::poll::start::PollStartEvent; 10use matrix_sdk::ruma::events::poll::start::PollStartEvent;
10use matrix_sdk::ruma::events::poll::unstable_start::{ 11use matrix_sdk::ruma::events::poll::unstable_start::{
11 UnstablePollStartEvent, 12 UnstablePollStartEvent,
@@ -1392,6 +1393,38 @@ bitflags::bitflags! {
1392 } 1393 }
1393} 1394}
1394 1395
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
1395/// Information about room's the user's joined. 1428/// Information about room's the user's joined.
1396pub struct RoomInfo { 1429pub struct RoomInfo {
1397 /// The display name for this room. 1430 /// The display name for this room.
@@ -1426,7 +1459,7 @@ pub struct RoomInfo {
1426 pub unloaded_unstable_polls: HashMap<OwnedEventId, UnloadedUnstablePoll>, 1459 pub unloaded_unstable_polls: HashMap<OwnedEventId, UnloadedUnstablePoll>,
1427 1460
1428 /// A map of message identifiers to thread replies. 1461 /// A map of message identifiers to thread replies.
1429 threads: HashMap<OwnedEventId, Messages>, 1462 threads: HashMap<OwnedEventId, Thread>,
1430 1463
1431 /// Whether the scrollback for this room is currently being fetched. 1464 /// Whether the scrollback for this room is currently being fetched.
1432 pub fetching: bool, 1465 pub fetching: bool,
@@ -1494,24 +1527,28 @@ impl Default for RoomInfo {
1494} 1527}
1495 1528
1496impl RoomInfo { 1529impl RoomInfo {
1497 pub fn get_thread(&self, root: Option<&EventId>) -> Option<&Messages> { 1530 pub fn get_messages(&self, thread_root: Option<&EventId>) -> Option<&Messages> {
1498 if let Some(thread_root) = root { 1531 if let Some(thread_root) = thread_root {
1499 self.threads.get(thread_root) 1532 self.threads.get(thread_root).map(Deref::deref)
1500 } else { 1533 } else {
1501 Some(&self.messages) 1534 Some(&self.messages)
1502 } 1535 }
1503 } 1536 }
1504 1537
1505 pub fn get_thread_mut(&mut self, root: Option<OwnedEventId>) -> &mut Messages { 1538 pub fn get_messages_mut(&mut self, thread_root: Option<OwnedEventId>) -> &mut Messages {
1506 if let Some(thread_root) = root { 1539 if let Some(thread_root) = thread_root {
1507 self.threads 1540 self.threads
1508 .entry(thread_root.clone()) 1541 .entry(thread_root.clone())
1509 .or_insert_with(|| Messages::thread(thread_root)) 1542 .or_insert_with(|| Thread::new(thread_root))
1510 } else { 1543 } else {
1511 &mut self.messages 1544 &mut self.messages
1512 } 1545 }
1513 } 1546 }
1514 1547
1548 pub fn get_thread(&self, root: &EventId) -> Option<&Thread> {
1549 self.threads.get(root)
1550 }
1551
1515 /// Get the event for the last message in a thread (or the thread root if there are no 1552 /// Get the event for the last message in a thread (or the thread root if there are no
1516 /// in-thread replies yet). 1553 /// in-thread replies yet).
1517 /// 1554 ///
@@ -1641,7 +1678,7 @@ impl RoomInfo {
1641 let key = loc.to_message_key()?; 1678 let key = loc.to_message_key()?;
1642 let root = loc.to_thread_root(); 1679 let root = loc.to_thread_root();
1643 1680
1644 self.get_thread(root)?.get(key) 1681 self.get_messages(root)?.get(key)
1645 } 1682 }
1646 1683
1647 /// Get an event for an identifier as mutable. 1684 /// Get an event for an identifier as mutable.
@@ -1651,7 +1688,7 @@ impl RoomInfo {
1651 let key = loc.to_message_key()?; 1688 let key = loc.to_message_key()?;
1652 let root = loc.to_thread_root(); 1689 let root = loc.to_thread_root();
1653 1690
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)
1655 } 1692 }
1656 1693
1657 /// Map an event identifier to its [`MessageKey`] and thread root. 1694 /// Map an event identifier to its [`MessageKey`] and thread root.
@@ -1679,7 +1716,7 @@ impl RoomInfo {
1679 pub fn get_message(&self, message_id: &MessageId) -> Option<&Message> { 1716 pub fn get_message(&self, message_id: &MessageId) -> Option<&Message> {
1680 let (root, key) = self.get_message_thread_key(message_id)?; 1717 let (root, key) = self.get_message_thread_key(message_id)?;
1681 1718
1682 self.get_thread(root)?.get(key) 1719 self.get_messages(root)?.get(key)
1683 } 1720 }
1684 1721
1685 /// Get an event for an identifier as mutable. 1722 /// Get an event for an identifier as mutable.
@@ -1689,7 +1726,7 @@ impl RoomInfo {
1689 let root = root.map(ToOwned::to_owned); 1726 let root = root.map(ToOwned::to_owned);
1690 let key = key.to_owned(); 1727 let key = key.to_owned();
1691 1728
1692 self.get_thread_mut(root).get_mut(&key) 1729 self.get_messages_mut(root).get_mut(&key)
1693 } 1730 }
1694 1731
1695 pub fn redact(&mut self, ev: OriginalSyncRoomRedactionEvent) { 1732 pub fn redact(&mut self, ev: OriginalSyncRoomRedactionEvent) {
@@ -1703,7 +1740,7 @@ impl RoomInfo {
1703 let edit_key = edit_key.clone(); 1740 let edit_key = edit_key.clone();
1704 let msg_loc = self.keys.get(msg_event_id).cloned(); 1741 let msg_loc = self.keys.get(msg_event_id).cloned();
1705 if let Some(EventLocation::Message(thread, msg_key)) = msg_loc { 1742 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) {
1707 msg.remove_edit(&edit_key); 1744 msg.remove_edit(&edit_key);
1708 } 1745 }
1709 } else { 1746 } else {
@@ -1760,14 +1797,25 @@ impl RoomInfo {
1760 event_id: OwnedEventId, 1797 event_id: OwnedEventId,
1761 thread_root: Option<OwnedEventId>, 1798 thread_root: Option<OwnedEventId>,
1762 message: Message, 1799 message: Message,
1800 thread_summary: ThreadSummaryStatus,
1763 ) { 1801 ) {
1764 let sender = message.sender.clone(); 1802 let sender = message.sender.clone();
1765 1803
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
1766 let key = MessageKey { ts: message.timestamp, id: event_id.clone().into() }; 1814 let key = MessageKey { ts: message.timestamp, id: event_id.clone().into() };
1767 let loc = EventLocation::Message(thread_root.clone(), key.clone()); 1815 let loc = EventLocation::Message(thread_root.clone(), key.clone());
1768 self.keys.insert(event_id.clone(), loc); 1816 self.keys.insert(event_id.clone(), loc);
1769 1817
1770 let thread = self.get_thread_mut(thread_root); 1818 let thread = self.get_messages_mut(thread_root);
1771 thread.insert_message(key, message); 1819 thread.insert_message(key, message);
1772 self.set_implicit_receipt(sender, event_id); 1820 self.set_implicit_receipt(sender, event_id);
1773 } 1821 }
@@ -1778,6 +1826,7 @@ impl RoomInfo {
1778 event_id: OwnedEventId, 1826 event_id: OwnedEventId,
1779 thread_root: Option<OwnedEventId>, 1827 thread_root: Option<OwnedEventId>,
1780 message: Message, 1828 message: Message,
1829 thread_summary: ThreadSummaryStatus,
1781 settings: &ApplicationSettings, 1830 settings: &ApplicationSettings,
1782 previews: &mut PreviewManager, 1831 previews: &mut PreviewManager,
1783 ) { 1832 ) {
@@ -1787,7 +1836,7 @@ impl RoomInfo {
1787 } 1836 }
1788 } 1837 }
1789 1838
1790 self.insert_msglike(event_id, thread_root, message); 1839 self.insert_msglike(event_id, thread_root, message, thread_summary);
1791 } 1840 }
1792 1841
1793 /// Insert a reaction to a message. 1842 /// Insert a reaction to a message.
@@ -1812,6 +1861,7 @@ impl RoomInfo {
1812 pub fn insert_sticker( 1861 pub fn insert_sticker(
1813 &mut self, 1862 &mut self,
1814 sticker: StickerEvent, 1863 sticker: StickerEvent,
1864 thread_summary: ThreadSummaryStatus,
1815 settings: &ApplicationSettings, 1865 settings: &ApplicationSettings,
1816 previews: &mut PreviewManager, 1866 previews: &mut PreviewManager,
1817 ) { 1867 ) {
@@ -1820,7 +1870,7 @@ impl RoomInfo {
1820 MessageLikeEvent::Original(OriginalMessageLikeEvent { 1870 MessageLikeEvent::Original(OriginalMessageLikeEvent {
1821 content: 1871 content:
1822 StickerEventContent { 1872 StickerEventContent {
1823 relates_to: Some(Relation::Thread(Thread { event_id, .. })), 1873 relates_to: Some(Relation::Thread(ThreadRelation { event_id, .. })),
1824 .. 1874 ..
1825 }, 1875 },
1826 .. 1876 ..
@@ -1828,7 +1878,14 @@ impl RoomInfo {
1828 _ => None, 1878 _ => None,
1829 }; 1879 };
1830 1880
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 );
1832 } 1889 }
1833 1890
1834 /// Insert a reaction to a message. 1891 /// Insert a reaction to a message.
@@ -1858,7 +1915,12 @@ impl RoomInfo {
1858 } 1915 }
1859 1916
1860 /// Insert the start of a poll. 1917 /// 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 ) {
1862 let event_id = poll.event_id().to_owned(); 1924 let event_id = poll.event_id().to_owned();
1863 let key = MessageKey { 1925 let key = MessageKey {
1864 ts: poll.origin_server_ts().into(), 1926 ts: poll.origin_server_ts().into(),
@@ -1895,7 +1957,7 @@ impl RoomInfo {
1895 } 1957 }
1896 } else { 1958 } else {
1897 let thread_root = match &ev.content.relates_to { 1959 let thread_root = match &ev.content.relates_to {
1898 Some(Relation::Thread(Thread { event_id, .. })) => { 1960 Some(Relation::Thread(ThreadRelation { event_id, .. })) => {
1899 Some(event_id.to_owned()) 1961 Some(event_id.to_owned())
1900 }, 1962 },
1901 _ => None, 1963 _ => None,
@@ -1907,13 +1969,13 @@ impl RoomInfo {
1907 ); 1969 );
1908 let msg = Message::new(msg, ev.sender, ev.origin_server_ts.into()); 1970 let msg = Message::new(msg, ev.sender, ev.origin_server_ts.into());
1909 1971
1910 self.insert_msglike(event_id, thread_root, msg); 1972 self.insert_msglike(event_id, thread_root, msg, thread_summary);
1911 } 1973 }
1912 }, 1974 },
1913 MessageLikeEvent::Redacted(ev) => { 1975 MessageLikeEvent::Redacted(ev) => {
1914 let message: Message = ev.into(); 1976 let message: Message = ev.into();
1915 1977
1916 self.insert_msglike(event_id, None, message); 1978 self.insert_msglike(event_id, None, message, thread_summary);
1917 }, 1979 },
1918 } 1980 }
1919 } 1981 }
@@ -1923,6 +1985,7 @@ impl RoomInfo {
1923 &mut self, 1985 &mut self,
1924 poll: UnstablePollStartEvent, 1986 poll: UnstablePollStartEvent,
1925 own_user_id: &UserId, 1987 own_user_id: &UserId,
1988 thread_summary: ThreadSummaryStatus,
1926 ) { 1989 ) {
1927 let event_id = poll.event_id().to_owned(); 1990 let event_id = poll.event_id().to_owned();
1928 let key = MessageKey { 1991 let key = MessageKey {
@@ -1935,8 +1998,9 @@ impl RoomInfo {
1935 match ev.content { 1998 match ev.content {
1936 UnstablePollStartEventContent::New(content) => { 1999 UnstablePollStartEventContent::New(content) => {
1937 let thread_root = match &content.relates_to { 2000 let thread_root = match &content.relates_to {
1938 Some(RelationWithoutReplacement::Thread(Thread { 2001 Some(RelationWithoutReplacement::Thread(ThreadRelation {
1939 event_id, .. 2002 event_id,
2003 ..
1940 })) => Some(event_id.to_owned()), 2004 })) => Some(event_id.to_owned()),
1941 _ => None, 2005 _ => None,
1942 }; 2006 };
@@ -1954,7 +2018,7 @@ impl RoomInfo {
1954 ); 2018 );
1955 let msg = Message::new(msg, ev.sender, ev.origin_server_ts.into()); 2019 let msg = Message::new(msg, ev.sender, ev.origin_server_ts.into());
1956 2020
1957 self.insert_msglike(event_id, thread_root, msg); 2021 self.insert_msglike(event_id, thread_root, msg, thread_summary);
1958 }, 2022 },
1959 UnstablePollStartEventContent::Replacement(content) => { 2023 UnstablePollStartEventContent::Replacement(content) => {
1960 let loc = EventLocation::Poll( 2024 let loc = EventLocation::Poll(
@@ -1986,7 +2050,7 @@ impl RoomInfo {
1986 MessageLikeEvent::Redacted(ev) => { 2050 MessageLikeEvent::Redacted(ev) => {
1987 let message: Message = ev.into(); 2051 let message: Message = ev.into();
1988 2052
1989 self.insert_msglike(event_id, None, message); 2053 self.insert_msglike(event_id, None, message, thread_summary);
1990 }, 2054 },
1991 } 2055 }
1992 } 2056 }
@@ -2054,7 +2118,7 @@ impl RoomInfo {
2054 2118
2055 if let Some(EventLocation::Message(thread, key)) = msg_loc { 2119 if let Some(EventLocation::Message(thread, key)) = msg_loc {
2056 // The edited message is already loaded in cache 2120 // 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 {
2058 return; 2122 return;
2059 }; 2123 };
2060 msg.insert_edit(edit_key.clone(), replacement.new_content); 2124 msg.insert_edit(edit_key.clone(), replacement.new_content);
@@ -2077,28 +2141,34 @@ impl RoomInfo {
2077 pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) { 2141 pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) {
2078 let event_id = msg.event_id().to_owned(); 2142 let event_id = msg.event_id().to_owned();
2079 2143
2080 self.insert_msglike(event_id, None, msg.into()); 2144 self.insert_msglike(event_id, None, msg.into(), ThreadSummaryStatus::None);
2081 } 2145 }
2082 2146
2083 /// Inserts events that couldn't be decrypted into the scrollback. 2147 /// 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 ) {
2085 let event_id = msg.event_id().to_owned(); 2153 let event_id = msg.event_id().to_owned();
2086 2154
2087 let thread_root = if let Some(EncryptedRelation::Thread(Thread { event_id, .. })) = 2155 let thread_root =
2088 msg.as_original().and_then(|ev| ev.content.relates_to.as_ref()) 2156 if let Some(EncryptedRelation::Thread(ThreadRelation { event_id, .. })) =
2089 { 2157 msg.as_original().and_then(|ev| ev.content.relates_to.as_ref())
2090 Some(event_id.to_owned()) 2158 {
2091 } else { 2159 Some(event_id.to_owned())
2092 None 2160 } else {
2093 }; 2161 None
2162 };
2094 2163
2095 self.insert_msglike(event_id, thread_root, msg.into()); 2164 self.insert_msglike(event_id, thread_root, msg.into(), thread_summary);
2096 } 2165 }
2097 2166
2098 /// Insert a new message event, and prepare for image-preview if it has an image attachment. 2167 /// Insert a new message event, and prepare for image-preview if it has an image attachment.
2099 pub fn insert_message( 2168 pub fn insert_message(
2100 &mut self, 2169 &mut self,
2101 ev: RoomMessageEvent, 2170 ev: RoomMessageEvent,
2171 thread_summary: ThreadSummaryStatus,
2102 settings: &ApplicationSettings, 2172 settings: &ApplicationSettings,
2103 previews: &mut PreviewManager, 2173 previews: &mut PreviewManager,
2104 ) { 2174 ) {
@@ -2109,14 +2179,21 @@ impl RoomInfo {
2109 self.insert_edit(ev, repl, settings, previews); 2179 self.insert_edit(ev, repl, settings, previews);
2110 return; 2180 return;
2111 }, 2181 },
2112 Some(Relation::Thread(Thread { event_id, .. })) => Some(event_id.to_owned()), 2182 Some(Relation::Thread(ThreadRelation { event_id, .. })) => Some(event_id.to_owned()),
2113 _ => None, 2183 _ => None,
2114 }; 2184 };
2115 let mut message: Message = ev.into(); 2185 let mut message: Message = ev.into();
2116 if let Some(edits) = self.unloaded_edits.remove(&event_id) { 2186 if let Some(edits) = self.unloaded_edits.remove(&event_id) {
2117 message.set_edits(edits); 2187 message.set_edits(edits);
2118 } 2188 }
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 );
2120 } 2197 }
2121 2198
2122 /// Indicates whether this room has unread messages. 2199 /// Indicates whether this room has unread messages.
@@ -2264,8 +2341,8 @@ impl RoomInfo {
2264 let user_id = &settings.user_id; 2341 let user_id = &settings.user_id;
2265 2342
2266 let messages = match &thread { 2343 let messages = match &thread {
2267 ReceiptThread::Main => self.get_thread(None), 2344 ReceiptThread::Main => self.get_messages(None),
2268 ReceiptThread::Thread(root) => self.get_thread(Some(root)), 2345 ReceiptThread::Thread(root) => self.get_messages(Some(root)),
2269 _ => None, 2346 _ => None,
2270 }; 2347 };
2271 2348
@@ -3238,7 +3315,7 @@ pub mod tests {
3238 MSG5_KEY.clone(), 3315 MSG5_KEY.clone(),
3239 ); 3316 );
3240 3317
3241 info.insert_message(event, &settings, &mut previews); 3318 info.insert_message(event, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3242 3319
3243 assert_eq!( 3320 assert_eq!(
3244 info.user_receipts 3321 info.user_receipts
@@ -3270,8 +3347,8 @@ pub mod tests {
3270 MSG2_KEY.clone(), 3347 MSG2_KEY.clone(),
3271 ); 3348 );
3272 3349
3273 info.insert_message(newer, &settings, &mut previews); 3350 info.insert_message(newer, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3274 info.insert_message(older, &settings, &mut previews); 3351 info.insert_message(older, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3275 3352
3276 assert_eq!( 3353 assert_eq!(
3277 info.user_receipts 3354 info.user_receipts
@@ -3332,8 +3409,8 @@ pub mod tests {
3332 MSG5_KEY.clone(), 3409 MSG5_KEY.clone(),
3333 ); 3410 );
3334 3411
3335 info.insert_message(older, &settings, &mut previews); 3412 info.insert_message(older, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3336 info.insert_message(newer, &settings, &mut previews); 3413 info.insert_message(newer, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3337 info.set_receipt(ReceiptThread::Main, TEST_USER2.clone(), MSG2_EVID.clone()); 3414 info.set_receipt(ReceiptThread::Main, TEST_USER2.clone(), MSG2_EVID.clone());
3338 3415
3339 assert_eq!( 3416 assert_eq!(
@@ -3356,7 +3433,7 @@ pub mod tests {
3356 MSG2_KEY.clone(), 3433 MSG2_KEY.clone(),
3357 ); 3434 );
3358 3435
3359 info.insert_message(older, &settings, &mut previews); 3436 info.insert_message(older, ThreadSummaryStatus::Unknown, &settings, &mut previews);
3360 3437
3361 assert_eq!( 3438 assert_eq!(
3362 info.user_receipts 3439 info.user_receipts
src/message/html.rs +1
@@ -717,6 +717,7 @@ impl StyleTreeNode {
717} 717}
718 718
719/// A processed HTML document. 719/// A processed HTML document.
720#[derive(Clone)]
720pub struct StyleTree { 721pub struct StyleTree {
721 pub(super) children: StyleTreeChildren, 722 pub(super) children: StyleTreeChildren,
722} 723}
src/message/mod.rs +11 −13
@@ -90,10 +90,6 @@ impl Messages {
90 Self::new(ReceiptThread::Main) 90 Self::new(ReceiptThread::Main)
91 } 91 }
92 92
93 pub fn thread(root: OwnedEventId) -> Self {
94 Self::new(ReceiptThread::Thread(root))
95 }
96
97 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) { 93 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) {
98 let mut msg = msg.into(); 94 let mut msg = msg.into();
99 if let MessageEvent::Original(ev, edits) = &mut msg.event { 95 if let MessageEvent::Original(ev, edits) = &mut msg.event {
@@ -421,7 +417,7 @@ fn redaction_reason_event(ev: SyncRoomRedactionEvent) -> Option<String> {
421fn has_reply_fallback(relation: Option<&Relation<RoomMessageEventContentWithoutRelation>>) -> bool { 417fn has_reply_fallback(relation: Option<&Relation<RoomMessageEventContentWithoutRelation>>) -> bool {
422 matches!( 418 matches!(
423 relation, 419 relation,
424 Some(Relation::Reply(_) | Relation::Thread(Thread { in_reply_to: Some(_), .. })) 420 Some(Relation::Reply(_) | Relation::Thread(ThreadRelation { in_reply_to: Some(_), .. }))
425 ) 421 )
426} 422}
427 423
@@ -1022,6 +1018,7 @@ impl<'a> MessageFormatter<'a> {
1022 } 1018 }
1023} 1019}
1024 1020
1021#[derive(Clone)]
1025pub struct Message { 1022pub struct Message {
1026 pub event: MessageEvent, 1023 pub event: MessageEvent,
1027 pub sender: OwnedUserId, 1024 pub sender: OwnedUserId,
@@ -1059,7 +1056,7 @@ impl Message {
1059 MessageEvent::Sticker(ev, ..) => { 1056 MessageEvent::Sticker(ev, ..) => {
1060 return match &ev.content.relates_to { 1057 return match &ev.content.relates_to {
1061 Some(Relation::Reply(reply)) => Some(reply.in_reply_to.event_id.clone()), 1058 Some(Relation::Reply(reply)) => Some(reply.in_reply_to.event_id.clone()),
1062 Some(Relation::Thread(Thread { 1059 Some(Relation::Thread(ThreadRelation {
1063 in_reply_to: Some(in_reply_to), 1060 in_reply_to: Some(in_reply_to),
1064 is_falling_back: false, 1061 is_falling_back: false,
1065 .. 1062 ..
@@ -1073,7 +1070,7 @@ impl Message {
1073 1070
1074 match &content.relates_to { 1071 match &content.relates_to {
1075 Some(Relation::Reply(reply)) => Some(reply.in_reply_to.event_id.clone()), 1072 Some(Relation::Reply(reply)) => Some(reply.in_reply_to.event_id.clone()),
1076 Some(Relation::Thread(Thread { 1073 Some(Relation::Thread(ThreadRelation {
1077 in_reply_to: Some(in_reply_to), 1074 in_reply_to: Some(in_reply_to),
1078 is_falling_back: false, 1075 is_falling_back: false,
1079 .. 1076 ..
@@ -1097,7 +1094,7 @@ impl Message {
1097 }; 1094 };
1098 1095
1099 match &content.relates_to { 1096 match &content.relates_to {
1100 Some(Relation::Thread(Thread { 1097 Some(Relation::Thread(ThreadRelation {
1101 event_id, 1098 event_id,
1102 in_reply_to: Some(in_reply_to), 1099 in_reply_to: Some(in_reply_to),
1103 is_falling_back: true, 1100 is_falling_back: true,
@@ -1389,8 +1386,9 @@ impl Message {
1389 protos.extend(react_protos); 1386 protos.extend(react_protos);
1390 } 1387 }
1391 1388
1392 if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(Some(id))) { 1389 if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(id)) {
1393 fmt.push_thread_reply_count(thread.len(), &mut text, style); 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);
1394 } 1392 }
1395 1393
1396 (text, protos) 1394 (text, protos)
@@ -1714,15 +1712,15 @@ pub mod tests {
1714 assert!(has_reply_fallback(Some(&reply))); 1712 assert!(has_reply_fallback(Some(&reply)));
1715 1713
1716 let thread_reply: Relation<RoomMessageEventContentWithoutRelation> = 1714 let thread_reply: Relation<RoomMessageEventContentWithoutRelation> =
1717 Relation::Thread(Thread::reply(root.clone(), target.clone())); 1715 Relation::Thread(ThreadRelation::reply(root.clone(), target.clone()));
1718 assert!(has_reply_fallback(Some(&thread_reply))); 1716 assert!(has_reply_fallback(Some(&thread_reply)));
1719 1717
1720 let thread_fallback: Relation<RoomMessageEventContentWithoutRelation> = 1718 let thread_fallback: Relation<RoomMessageEventContentWithoutRelation> =
1721 Relation::Thread(Thread::plain(root.clone(), target)); 1719 Relation::Thread(ThreadRelation::plain(root.clone(), target));
1722 assert!(has_reply_fallback(Some(&thread_fallback))); 1720 assert!(has_reply_fallback(Some(&thread_fallback)));
1723 1721
1724 let thread_without_fallback: Relation<RoomMessageEventContentWithoutRelation> = 1722 let thread_without_fallback: Relation<RoomMessageEventContentWithoutRelation> =
1725 Relation::Thread(Thread::without_fallback(root)); 1723 Relation::Thread(ThreadRelation::without_fallback(root));
1726 assert!(!has_reply_fallback(Some(&thread_without_fallback))); 1724 assert!(!has_reply_fallback(Some(&thread_without_fallback)));
1727 assert!(!has_reply_fallback(None)); 1725 assert!(!has_reply_fallback(None));
1728 } 1726 }
src/prelude.rs +1 −1
@@ -12,7 +12,7 @@ pub use std::time::{Duration, Instant};
12pub use matrix_sdk::room_preview::RoomPreview; 12pub use matrix_sdk::room_preview::RoomPreview;
13pub use matrix_sdk::ruma::events::AnySyncStateEvent; 13pub use matrix_sdk::ruma::events::AnySyncStateEvent;
14pub use matrix_sdk::ruma::events::receipt::ReceiptThread; 14pub 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;
16pub use matrix_sdk::ruma::events::room::MediaSource; 16pub use matrix_sdk::ruma::events::room::MediaSource;
17pub use matrix_sdk::ruma::events::room::encrypted::Relation as EncryptedRelation; 17pub use matrix_sdk::ruma::events::room::encrypted::Relation as EncryptedRelation;
18pub use matrix_sdk::ruma::events::room::message::{ 18pub use matrix_sdk::ruma::events::room::message::{
src/tests.rs +1 −1
@@ -131,7 +131,7 @@ pub fn mock_room() -> RoomInfo {
131 let mut room = RoomInfo::default(); 131 let mut room = RoomInfo::default();
132 room.name = Some("Watercooler Discussion".into()); 132 room.name = Some("Watercooler Discussion".into());
133 room.keys = mock_keys(); 133 room.keys = mock_keys();
134 *room.get_thread_mut(None) = mock_messages(); 134 *room.get_messages_mut(None) = mock_messages();
135 135
136 let user_id = TEST_USER2.clone(); 136 let user_id = TEST_USER2.clone();
137 let name = "User 2"; 137 let name = "User 2";
src/windows/room/chat.rs +1 −1
@@ -424,7 +424,7 @@ impl ChatState {
424 Some(EchoLocation::Replaced(id)) => id, 424 Some(EchoLocation::Replaced(id)) => id,
425 Some(EchoLocation::Message(thread, orig_key)) => { 425 Some(EchoLocation::Message(thread, orig_key)) => {
426 let Some(MessageEvent::Local(_, handle, _)) = info 426 let Some(MessageEvent::Local(_, handle, _)) = info
427 .get_thread(thread.as_deref()) 427 .get_messages(thread.as_deref())
428 .and_then(|thread| thread.get(orig_key)) 428 .and_then(|thread| thread.get(orig_key))
429 .map(|msg| &msg.event) 429 .map(|msg| &msg.event)
430 else { 430 else {
src/windows/room/scrollback.rs +1 −1
@@ -163,7 +163,7 @@ impl ScrollbackState {
163 } 163 }
164 164
165 pub fn get_thread<'a>(&self, info: &'a RoomInfo) -> Option<&'a Messages> { 165 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())
167 } 167 }
168 168
169 pub fn messages<'a>( 169 pub fn messages<'a>(
src/worker.rs +27 −17
@@ -14,7 +14,7 @@ use matrix_sdk::AuthSession;
14use matrix_sdk::authentication::matrix::MatrixSession; 14use matrix_sdk::authentication::matrix::MatrixSession;
15use matrix_sdk::config::{RequestConfig, SyncSettings}; 15use matrix_sdk::config::{RequestConfig, SyncSettings};
16use matrix_sdk::deserialized_responses::RawSyncOrStrippedState; 16use matrix_sdk::deserialized_responses::RawSyncOrStrippedState;
17use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind}; 17use matrix_sdk::deserialized_responses::{ThreadSummaryStatus, TimelineEvent, TimelineEventKind};
18use matrix_sdk::encryption::{BackupDownloadStrategy, EncryptionSettings}; 18use matrix_sdk::encryption::{BackupDownloadStrategy, EncryptionSettings};
19use matrix_sdk::event_cache::DecryptionRetryRequest; 19use matrix_sdk::event_cache::DecryptionRetryRequest;
20use matrix_sdk::event_handler::Ctx; 20use matrix_sdk::event_handler::Ctx;
@@ -116,7 +116,7 @@ const RECEIPT_RETRY_INTERVAL: Duration = Duration::from_secs(2);
116type ReceiptKey = (OwnedRoomId, ReceiptThread, ReceiptType); 116type ReceiptKey = (OwnedRoomId, ReceiptThread, ReceiptType);
117type ReceiptUpdate = (OwnedRoomId, ReceiptThread, ReceiptType, OwnedEventId); 117type ReceiptUpdate = (OwnedRoomId, ReceiptThread, ReceiptType, OwnedEventId);
118 118
119type MessageAndReceipts = (AnyTimelineEvent, ReceiptThread, Vec<OwnedUserId>); 119type MessageAndReceipts = (AnyTimelineEvent, ThreadSummaryStatus, ReceiptThread, Vec<OwnedUserId>);
120type MessageFetchResult = IambResult<(bool, Vec<MessageAndReceipts>)>; 120type MessageFetchResult = IambResult<(bool, Vec<MessageAndReceipts>)>;
121 121
122fn initial_devname() -> String { 122fn initial_devname() -> String {
@@ -462,7 +462,7 @@ async fn get_receipts_for_timeline_events(
462 }, 462 },
463 }; 463 };
464 464
465 msgs.push((msg, thread, receipts)); 465 msgs.push((msg, ev.thread_summary, thread, receipts));
466 } 466 }
467 467
468 if !redecryption_requests.is_empty() { 468 if !redecryption_requests.is_empty() {
@@ -505,7 +505,7 @@ fn insert_msgs_and_receipts(
505 previews: &mut PreviewManager, 505 previews: &mut PreviewManager,
506 settings: &ApplicationSettings, 506 settings: &ApplicationSettings,
507) { 507) {
508 for (msg, thread, receipts) in msgs { 508 for (msg, thread_summary, thread, receipts) in msgs {
509 let sender = msg.sender().to_owned(); 509 let sender = msg.sender().to_owned();
510 let _ = presences.get_or_default(sender); 510 let _ = presences.get_or_default(sender);
511 511
@@ -515,25 +515,25 @@ fn insert_msgs_and_receipts(
515 515
516 match msg { 516 match msg {
517 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomEncrypted(msg)) => { 517 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomEncrypted(msg)) => {
518 info.insert_encrypted(msg); 518 info.insert_encrypted(msg, thread_summary);
519 }, 519 },
520 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(msg)) => { 520 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(msg)) => {
521 info.insert_message(msg, settings, previews); 521 info.insert_message(msg, thread_summary, settings, previews);
522 }, 522 },
523 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::Reaction(ev)) => { 523 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::Reaction(ev)) => {
524 info.insert_reaction_with_preview(ev, settings, previews); 524 info.insert_reaction_with_preview(ev, settings, previews);
525 }, 525 },
526 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::Sticker(ev)) => { 526 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::Sticker(ev)) => {
527 info.insert_sticker(ev, settings, previews); 527 info.insert_sticker(ev, thread_summary, settings, previews);
528 }, 528 },
529 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomRedaction(..)) => { 529 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomRedaction(..)) => {
530 // ignoring redaction events because we get them bundled with the redacted event 530 // ignoring redaction events because we get them bundled with the redacted event
531 }, 531 },
532 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollStart(ev)) => { 532 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);
534 }, 534 },
535 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::UnstablePollStart(ev)) => { 535 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);
537 }, 537 },
538 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollResponse(ev)) => { 538 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollResponse(ev)) => {
539 if let MessageLikeEvent::Original(ev) = ev { 539 if let MessageLikeEvent::Original(ev) = ev {
@@ -977,7 +977,9 @@ fn insert_local_echo(
977 // XXX: Show echo on edited message 977 // XXX: Show echo on edited message
978 return Ok(()); 978 return Ok(());
979 }, 979 },
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 },
981 _ => None, 983 _ => None,
982 }; 984 };
983 985
@@ -989,7 +991,7 @@ fn insert_local_echo(
989 info.echo_keys 991 info.echo_keys
990 .insert(transaction_id, EchoLocation::Message(thread.clone(), key.clone())); 992 .insert(transaction_id, EchoLocation::Message(thread.clone(), key.clone()));
991 993
992 let thread = info.get_thread_mut(thread); 994 let thread = info.get_messages_mut(thread);
993 thread.insert(key, msg); 995 thread.insert(key, msg);
994 }, 996 },
995 LocalEchoContent::Redaction { .. } => { 997 LocalEchoContent::Redaction { .. } => {
@@ -1044,7 +1046,7 @@ async fn subscribe_sendqueue_forever(client: &Client, store: &AsyncProgramStore)
1044 continue; 1046 continue;
1045 }; 1047 };
1046 1048
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 {
1048 tracing::debug!(?transaction_id, "replaced local echo not found"); 1050 tracing::debug!(?transaction_id, "replaced local echo not found");
1049 continue; 1051 continue;
1050 }; 1052 };
@@ -1070,7 +1072,7 @@ async fn subscribe_sendqueue_forever(client: &Client, store: &AsyncProgramStore)
1070 let location = std::mem::replace(location, EchoLocation::Replaced(event_id)); 1072 let location = std::mem::replace(location, EchoLocation::Replaced(event_id));
1071 1073
1072 if let EchoLocation::Message(thread, key) = location { 1074 if let EchoLocation::Message(thread, key) = location {
1073 info.get_thread_mut(thread).remove(&key); 1075 info.get_messages_mut(thread).remove(&key);
1074 } 1076 }
1075 } 1077 }
1076 }, 1078 },
@@ -1805,7 +1807,7 @@ impl ClientWorker {
1805 let info = rooms.get_or_default(room_id.to_owned()); 1807 let info = rooms.get_or_default(room_id.to_owned());
1806 1808
1807 let full_ev = ev.into_full_event(room_id.to_owned()); 1809 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);
1809 1811
1810 update_event_receipts(info, &room, event_id).await; 1812 update_event_receipts(info, &room, event_id).await;
1811 } 1813 }
@@ -1857,7 +1859,7 @@ impl ClientWorker {
1857 let info = rooms.get_or_default(room_id.to_owned()); 1859 let info = rooms.get_or_default(room_id.to_owned());
1858 1860
1859 let full_ev = ev.into_full_event(room_id.to_owned()); 1861 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);
1861 1863
1862 update_event_receipts(info, &room, event_id).await; 1864 update_event_receipts(info, &room, event_id).await;
1863 } 1865 }
@@ -1908,7 +1910,11 @@ impl ClientWorker {
1908 let info = rooms.get_or_default(room_id.to_owned()); 1910 let info = rooms.get_or_default(room_id.to_owned());
1909 1911
1910 let full_ev = ev.into_full_event(room_id.to_owned()); 1912 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 );
1912 1918
1913 update_event_receipts(info, &room, event_id).await; 1919 update_event_receipts(info, &room, event_id).await;
1914 } 1920 }
@@ -1933,7 +1939,11 @@ impl ClientWorker {
1933 let info = rooms.get_or_default(room_id.to_owned()); 1939 let info = rooms.get_or_default(room_id.to_owned());
1934 1940
1935 let full_ev = ev.into_full_event(room_id.to_owned()); 1941 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 );
1937 1947
1938 update_event_receipts(info, &room, event_id).await; 1948 update_event_receipts(info, &room, event_id).await;
1939 } 1949 }