Commit f880358a83

f880358a83829fbd8191c0fe89bfee1b6b7ceba1

parent: f0de97a049

Unregistered key

VAWVAW <git@nlih.de> · 2025-06-06 01:11 UTC
committer: <noreply@github.com>

Implement receipts per thread (#438)

Layout: unified · split

src/base.rs +88 −21
@@ -12,6 +12,7 @@ use std::sync::Arc;
12use std::time::{Duration, Instant}; 12use std::time::{Duration, Instant};
13 13
14use emojis::Emoji; 14use emojis::Emoji;
15use matrix_sdk::ruma::events::receipt::ReceiptThread;
15use ratatui::{ 16use ratatui::{
16 buffer::Buffer, 17 buffer::Buffer,
17 layout::{Alignment, Rect}, 18 layout::{Alignment, Rect},
@@ -869,7 +870,6 @@ impl UnreadInfo {
869} 870}
870 871
871/// Information about room's the user's joined. 872/// Information about room's the user's joined.
872#[derive(Default)]
873pub struct RoomInfo { 873pub struct RoomInfo {
874 /// The display name for this room. 874 /// The display name for this room.
875 pub name: Option<String>, 875 pub name: Option<String>,
@@ -884,15 +884,13 @@ pub struct RoomInfo {
884 messages: Messages, 884 messages: Messages,
885 885
886 /// A map of read markers to display on different events. 886 /// A map of read markers to display on different events.
887 pub event_receipts: HashMap<OwnedEventId, HashSet<OwnedUserId>>, 887 pub event_receipts: HashMap<ReceiptThread, HashMap<OwnedEventId, HashSet<OwnedUserId>>>,
888
889 /// A map of the most recent read marker for each user. 888 /// A map of the most recent read marker for each user.
890 /// 889 ///
891 /// Every receipt in this map should also have an entry in [`event_receipts`](`Self::event_receipts`), 890 /// Every receipt in this map should also have an entry in [`event_receipts`](`Self::event_receipts`),
892 /// however not every user has an entry. If a user's most recent receipt is 891 /// however not every user has an entry. If a user's most recent receipt is
893 /// older than the oldest loaded event, that user will not be included. 892 /// older than the oldest loaded event, that user will not be included.
894 pub user_receipts: HashMap<OwnedUserId, OwnedEventId>, 893 pub user_receipts: HashMap<ReceiptThread, HashMap<OwnedUserId, OwnedEventId>>,
895
896 /// A map of message identifiers to a map of reaction events. 894 /// A map of message identifiers to a map of reaction events.
897 pub reactions: HashMap<OwnedEventId, MessageReactions>, 895 pub reactions: HashMap<OwnedEventId, MessageReactions>,
898 896
@@ -918,6 +916,28 @@ pub struct RoomInfo {
918 pub draw_last: Option<Instant>, 916 pub draw_last: Option<Instant>,
919} 917}
920 918
919impl Default for RoomInfo {
920 fn default() -> Self {
921 Self {
922 messages: Messages::new(ReceiptThread::Main),
923
924 name: Default::default(),
925 tags: Default::default(),
926 keys: Default::default(),
927 event_receipts: Default::default(),
928 user_receipts: Default::default(),
929 reactions: Default::default(),
930 threads: Default::default(),
931 fetching: Default::default(),
932 fetch_id: Default::default(),
933 fetch_last: Default::default(),
934 users_typing: Default::default(),
935 display_names: Default::default(),
936 draw_last: Default::default(),
937 }
938 }
939}
940
921impl RoomInfo { 941impl RoomInfo {
922 pub fn get_thread(&self, root: Option<&EventId>) -> Option<&Messages> { 942 pub fn get_thread(&self, root: Option<&EventId>) -> Option<&Messages> {
923 if let Some(thread_root) = root { 943 if let Some(thread_root) = root {
@@ -929,7 +949,9 @@ impl RoomInfo {
929 949
930 pub fn get_thread_mut(&mut self, root: Option<OwnedEventId>) -> &mut Messages { 950 pub fn get_thread_mut(&mut self, root: Option<OwnedEventId>) -> &mut Messages {
931 if let Some(thread_root) = root { 951 if let Some(thread_root) = root {
932 self.threads.entry(thread_root).or_default() 952 self.threads
953 .entry(thread_root.clone())
954 .or_insert_with(|| Messages::thread(thread_root))
933 } else { 955 } else {
934 &mut self.messages 956 &mut self.messages
935 } 957 }
@@ -1069,7 +1091,9 @@ impl RoomInfo {
1069 }; 1091 };
1070 1092
1071 let source = if let Some(thread) = thread { 1093 let source = if let Some(thread) = thread {
1072 self.threads.entry(thread.clone()).or_default() 1094 self.threads
1095 .entry(thread.clone())
1096 .or_insert_with(|| Messages::thread(thread.clone()))
1073 } else { 1097 } else {
1074 &mut self.messages 1098 &mut self.messages
1075 }; 1099 };
@@ -1108,13 +1132,20 @@ impl RoomInfo {
1108 /// Indicates whether this room has unread messages. 1132 /// Indicates whether this room has unread messages.
1109 pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo { 1133 pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo {
1110 let last_message = self.messages.last_key_value(); 1134 let last_message = self.messages.last_key_value();
1111 let last_receipt = self.get_receipt(&settings.profile.user_id); 1135 let last_receipt = self
1136 .user_receipts
1137 .get(&ReceiptThread::Main)
1138 .and_then(|receipts| receipts.get(&settings.profile.user_id));
1112 1139
1113 match (last_message, last_receipt) { 1140 match (last_message, last_receipt) {
1114 (Some(((ts, recent), _)), Some(last_read)) => { 1141 (Some(((ts, recent), _)), Some(last_read)) => {
1115 UnreadInfo { unread: last_read != recent, latest: Some(*ts) } 1142 UnreadInfo { unread: last_read != recent, latest: Some(*ts) }
1116 }, 1143 },
1117 (Some(((ts, _), _)), None) => UnreadInfo { unread: false, latest: Some(*ts) }, 1144 (Some(((ts, _), _)), None) => {
1145 // If we've never loaded/generated a room's receipt (example,
1146 // a newly joined but never viewed room), show it as unread.
1147 UnreadInfo { unread: true, latest: Some(*ts) }
1148 },
1118 (None, _) => UnreadInfo::default(), 1149 (None, _) => UnreadInfo::default(),
1119 } 1150 }
1120 } 1151 }
@@ -1142,7 +1173,10 @@ impl RoomInfo {
1142 let event_id = msg.event_id().to_owned(); 1173 let event_id = msg.event_id().to_owned();
1143 let key = (msg.origin_server_ts().into(), event_id.clone()); 1174 let key = (msg.origin_server_ts().into(), event_id.clone());
1144 1175
1145 let replies = self.threads.entry(thread_root.clone()).or_default(); 1176 let replies = self
1177 .threads
1178 .entry(thread_root.clone())
1179 .or_insert_with(|| Messages::thread(thread_root.clone()));
1146 let loc = EventLocation::Message(Some(thread_root), key.clone()); 1180 let loc = EventLocation::Message(Some(thread_root), key.clone());
1147 self.keys.insert(event_id, loc); 1181 self.keys.insert(event_id, loc);
1148 replies.insert_message(key, msg); 1182 replies.insert_message(key, msg);
@@ -1205,37 +1239,70 @@ impl RoomInfo {
1205 self.fetch_last.is_some_and(|i| i.elapsed() < ROOM_FETCH_DEBOUNCE) 1239 self.fetch_last.is_some_and(|i| i.elapsed() < ROOM_FETCH_DEBOUNCE)
1206 } 1240 }
1207 1241
1208 fn clear_receipt(&mut self, user_id: &OwnedUserId) -> Option<()> { 1242 fn clear_receipt(&mut self, thread: &ReceiptThread, user_id: &OwnedUserId) -> Option<()> {
1209 let old_event_id = self.user_receipts.get(user_id)?; 1243 let old_event_id =
1210 let old_receipts = self.event_receipts.get_mut(old_event_id)?; 1244 self.user_receipts.get(thread).and_then(|receipts| receipts.get(user_id))?;
1245 let old_thread = self.event_receipts.get_mut(thread)?;
1246 let old_receipts = old_thread.get_mut(old_event_id)?;
1211 old_receipts.remove(user_id); 1247 old_receipts.remove(user_id);
1212 1248
1213 if old_receipts.is_empty() { 1249 if old_receipts.is_empty() {
1214 self.event_receipts.remove(old_event_id); 1250 old_thread.remove(old_event_id);
1251 }
1252 if old_thread.is_empty() {
1253 self.event_receipts.remove(thread);
1215 } 1254 }
1216 1255
1217 None 1256 None
1218 } 1257 }
1219 1258
1220 pub fn set_receipt(&mut self, user_id: OwnedUserId, event_id: OwnedEventId) { 1259 pub fn set_receipt(
1221 self.clear_receipt(&user_id); 1260 &mut self,
1261 thread: ReceiptThread,
1262 user_id: OwnedUserId,
1263 event_id: OwnedEventId,
1264 ) {
1265 self.clear_receipt(&thread, &user_id);
1222 self.event_receipts 1266 self.event_receipts
1267 .entry(thread.clone())
1268 .or_default()
1223 .entry(event_id.clone()) 1269 .entry(event_id.clone())
1224 .or_default() 1270 .or_default()
1225 .insert(user_id.clone()); 1271 .insert(user_id.clone());
1226 self.user_receipts.insert(user_id, event_id); 1272 self.user_receipts.entry(thread).or_default().insert(user_id, event_id);
1227 } 1273 }
1228 1274
1229 pub fn fully_read(&mut self, user_id: OwnedUserId) { 1275 pub fn fully_read(&mut self, user_id: &UserId) {
1230 let Some(((_, event_id), _)) = self.messages.last_key_value() else { 1276 let Some(((_, event_id), _)) = self.messages.last_key_value() else {
1231 return; 1277 return;
1232 }; 1278 };
1233 1279
1234 self.set_receipt(user_id, event_id.clone()); 1280 self.set_receipt(ReceiptThread::Main, user_id.to_owned(), event_id.clone());
1281
1282 let newest = self
1283 .threads
1284 .iter()
1285 .filter_map(|(thread_id, messages)| {
1286 let thread = ReceiptThread::Thread(thread_id.to_owned());
1287
1288 messages
1289 .last_key_value()
1290 .map(|((_, event_id), _)| (thread, event_id.to_owned()))
1291 })
1292 .collect::<Vec<_>>();
1293
1294 for (thread, event_id) in newest.into_iter() {
1295 self.set_receipt(thread, user_id.to_owned(), event_id.clone());
1296 }
1235 } 1297 }
1236 1298
1237 pub fn get_receipt(&self, user_id: &UserId) -> Option<&OwnedEventId> { 1299 pub fn receipts<'a>(
1238 self.user_receipts.get(user_id) 1300 &'a self,
1301 user_id: &'a UserId,
1302 ) -> impl Iterator<Item = (&'a ReceiptThread, &'a OwnedEventId)> + 'a {
1303 self.user_receipts
1304 .iter()
1305 .filter_map(move |(t, rs)| rs.get(user_id).map(|r| (t, r)))
1239 } 1306 }
1240 1307
1241 fn get_typers(&self) -> &[OwnedUserId] { 1308 fn get_typers(&self) -> &[OwnedUserId] {
src/config.rs +1 −1
@@ -982,7 +982,7 @@ impl ApplicationSettings {
982 Ok(()) 982 Ok(())
983 } 983 }
984 984
985 pub fn get_user_char_span<'a>(&self, user_id: &'a UserId) -> Span<'a> { 985 pub fn get_user_char_span(&self, user_id: &UserId) -> Span {
986 let (color, c) = self 986 let (color, c) = self
987 .tunables 987 .tunables
988 .users 988 .users
src/main.rs +1 −1
@@ -559,7 +559,7 @@ impl Application {
559 559
560 for room_id in store.application.sync_info.chats() { 560 for room_id in store.application.sync_info.chats() {
561 if let Some(room) = store.application.rooms.get_mut(room_id) { 561 if let Some(room) = store.application.rooms.get_mut(room_id) {
562 room.fully_read(user_id.clone()); 562 room.fully_read(user_id);
563 } 563 }
564 } 564 }
565 565
src/message/mod.rs +31 −16
@@ -2,7 +2,6 @@
2use std::borrow::Cow; 2use std::borrow::Cow;
3use std::cmp::{Ord, Ordering, PartialOrd}; 3use std::cmp::{Ord, Ordering, PartialOrd};
4use std::collections::hash_map::DefaultHasher; 4use std::collections::hash_map::DefaultHasher;
5use std::collections::hash_set;
6use std::collections::BTreeMap; 5use std::collections::BTreeMap;
7use std::convert::{TryFrom, TryInto}; 6use std::convert::{TryFrom, TryInto};
8use std::fmt::{self, Display}; 7use std::fmt::{self, Display};
@@ -11,6 +10,7 @@ use std::ops::{Deref, DerefMut};
11 10
12use chrono::{DateTime, Local as LocalTz}; 11use chrono::{DateTime, Local as LocalTz};
13use humansize::{format_size, DECIMAL}; 12use humansize::{format_size, DECIMAL};
13use matrix_sdk::ruma::events::receipt::ReceiptThread;
14use serde_json::json; 14use serde_json::json;
15use unicode_width::UnicodeWidthStr; 15use unicode_width::UnicodeWidthStr;
16 16
@@ -77,8 +77,7 @@ type ProtocolPreview<'a> = (&'a Protocol, u16, u16);
77 77
78pub type MessageKey = (MessageTimeStamp, OwnedEventId); 78pub type MessageKey = (MessageTimeStamp, OwnedEventId);
79 79
80#[derive(Default)] 80pub struct Messages(BTreeMap<MessageKey, Message>, pub ReceiptThread);
81pub struct Messages(BTreeMap<MessageKey, Message>);
82 81
83impl Deref for Messages { 82impl Deref for Messages {
84 type Target = BTreeMap<MessageKey, Message>; 83 type Target = BTreeMap<MessageKey, Message>;
@@ -95,6 +94,18 @@ impl DerefMut for Messages {
95} 94}
96 95
97impl Messages { 96impl Messages {
97 pub fn new(thread: ReceiptThread) -> Self {
98 Self(Default::default(), thread)
99 }
100
101 pub fn main() -> Self {
102 Self::new(ReceiptThread::Main)
103 }
104
105 pub fn thread(root: OwnedEventId) -> Self {
106 Self::new(ReceiptThread::Thread(root))
107 }
108
98 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) { 109 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) {
99 let event_id = key.1.clone(); 110 let event_id = key.1.clone();
100 let msg = msg.into(); 111 let msg = msg.into();
@@ -633,8 +644,8 @@ struct MessageFormatter<'a> {
633 /// The date the message was sent. 644 /// The date the message was sent.
634 date: Option<Span<'a>>, 645 date: Option<Span<'a>>,
635 646
636 /// Iterator over the users who have read up to this message. 647 /// The users who have read up to this message.
637 read: Option<hash_set::Iter<'a, OwnedUserId>>, 648 read: Vec<OwnedUserId>,
638} 649}
639 650
640impl<'a> MessageFormatter<'a> { 651impl<'a> MessageFormatter<'a> {
@@ -667,13 +678,11 @@ impl<'a> MessageFormatter<'a> {
667 line.push(time); 678 line.push(time);
668 679
669 // Show read receipts. 680 // Show read receipts.
670 let user_char = 681 let user_char = |user: OwnedUserId| -> Span { settings.get_user_char_span(&user) };
671 |user: &'a OwnedUserId| -> Span<'a> { settings.get_user_char_span(user) };
672 let mut read = self.read.iter_mut().flatten();
673 682
674 let a = read.next().map(user_char).unwrap_or_else(|| Span::raw(" ")); 683 let a = self.read.pop().map(user_char).unwrap_or_else(|| Span::raw(" "));
675 let b = read.next().map(user_char).unwrap_or_else(|| Span::raw(" ")); 684 let b = self.read.pop().map(user_char).unwrap_or_else(|| Span::raw(" "));
676 let c = read.next().map(user_char).unwrap_or_else(|| Span::raw(" ")); 685 let c = self.read.pop().map(user_char).unwrap_or_else(|| Span::raw(" "));
677 686
678 line.push(Span::raw(" ")); 687 line.push(Span::raw(" "));
679 line.push(c); 688 line.push(c);
@@ -944,7 +953,13 @@ impl Message {
944 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER; 953 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER;
945 let user = self.show_sender(prev, true, info, settings); 954 let user = self.show_sender(prev, true, info, settings);
946 let time = self.timestamp.show_time(); 955 let time = self.timestamp.show_time();
947 let read = info.event_receipts.get(self.event.event_id()).map(|read| read.iter()); 956 let read = info
957 .event_receipts
958 .values()
959 .filter_map(|receipts| receipts.get(self.event.event_id()))
960 .flat_map(|read| read.iter())
961 .map(|user_id| user_id.to_owned())
962 .collect();
948 963
949 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 964 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
950 } else if user_gutter + TIME_GUTTER + MIN_MSG_LEN <= width { 965 } else if user_gutter + TIME_GUTTER + MIN_MSG_LEN <= width {
@@ -952,7 +967,7 @@ impl Message {
952 let fill = width - user_gutter - TIME_GUTTER; 967 let fill = width - user_gutter - TIME_GUTTER;
953 let user = self.show_sender(prev, true, info, settings); 968 let user = self.show_sender(prev, true, info, settings);
954 let time = self.timestamp.show_time(); 969 let time = self.timestamp.show_time();
955 let read = None; 970 let read = Vec::new();
956 971
957 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 972 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
958 } else if user_gutter + MIN_MSG_LEN <= width { 973 } else if user_gutter + MIN_MSG_LEN <= width {
@@ -960,7 +975,7 @@ impl Message {
960 let fill = width - user_gutter; 975 let fill = width - user_gutter;
961 let user = self.show_sender(prev, true, info, settings); 976 let user = self.show_sender(prev, true, info, settings);
962 let time = None; 977 let time = None;
963 let read = None; 978 let read = Vec::new();
964 979
965 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 980 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
966 } else { 981 } else {
@@ -968,7 +983,7 @@ impl Message {
968 let fill = width.saturating_sub(2); 983 let fill = width.saturating_sub(2);
969 let user = self.show_sender(prev, false, info, settings); 984 let user = self.show_sender(prev, false, info, settings);
970 let time = None; 985 let time = None;
971 let read = None; 986 let read = Vec::new();
972 987
973 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 988 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
974 } 989 }
@@ -1281,7 +1296,7 @@ pub mod tests {
1281 assert_eq!(k6, &MSG1_KEY.clone()); 1296 assert_eq!(k6, &MSG1_KEY.clone());
1282 1297
1283 // MessageCursor::latest() fails to convert for a room w/o messages. 1298 // MessageCursor::latest() fails to convert for a room w/o messages.
1284 let messages_empty = Messages::default(); 1299 let messages_empty = Messages::new(ReceiptThread::Main);
1285 assert_eq!(mc6.to_key(&messages_empty), None); 1300 assert_eq!(mc6.to_key(&messages_empty), None);
1286 } 1301 }
1287 1302
src/tests.rs +1 −1
@@ -137,7 +137,7 @@ pub fn mock_keys() -> HashMap<OwnedEventId, EventLocation> {
137} 137}
138 138
139pub fn mock_messages() -> Messages { 139pub fn mock_messages() -> Messages {
140 let mut messages = Messages::default(); 140 let mut messages = Messages::main();
141 141
142 messages.insert(MSG1_KEY.clone(), mock_message1()); 142 messages.insert(MSG1_KEY.clone(), mock_message1());
143 messages.insert(MSG2_KEY.clone(), mock_message2()); 143 messages.insert(MSG2_KEY.clone(), mock_message2());
src/windows/room/scrollback.rs +1 −1
@@ -1428,7 +1428,7 @@ impl StatefulWidget for Scrollback<'_> {
1428 { 1428 {
1429 // If the cursor is at the last message, then update the read marker. 1429 // If the cursor is at the last message, then update the read marker.
1430 if let Some((k, _)) = thread.last_key_value() { 1430 if let Some((k, _)) = thread.last_key_value() {
1431 info.set_receipt(settings.profile.user_id.clone(), k.1.clone()); 1431 info.set_receipt(thread.1.clone(), settings.profile.user_id.clone(), k.1.clone());
1432 } 1432 }
1433 } 1433 }
1434 1434
src/worker.rs +29 −31
@@ -210,7 +210,7 @@ async fn update_event_receipts(info: &mut RoomInfo, room: &MatrixRoom, event_id:
210 }; 210 };
211 211
212 for (user_id, _) in receipts { 212 for (user_id, _) in receipts {
213 info.set_receipt(user_id, event_id.to_owned()); 213 info.set_receipt(ReceiptThread::Main, user_id, event_id.to_owned());
214 } 214 }
215} 215}
216 216
@@ -300,7 +300,7 @@ async fn load_older_one(
300 300
301 let event_id = msg.event_id(); 301 let event_id = msg.event_id();
302 let receipts = match room 302 let receipts = match room
303 .load_event_receipts(ReceiptType::Read, ReceiptThread::Unthreaded, event_id) 303 .load_event_receipts(ReceiptType::Read, ReceiptThread::Main, event_id)
304 .await 304 .await
305 { 305 {
306 Ok(receipts) => receipts.into_iter().map(|(u, _)| u).collect(), 306 Ok(receipts) => receipts.into_iter().map(|(u, _)| u).collect(),
@@ -338,7 +338,7 @@ fn load_insert(
338 let _ = presences.get_or_default(sender); 338 let _ = presences.get_or_default(sender);
339 339
340 for user_id in receipts { 340 for user_id in receipts {
341 info.set_receipt(user_id, msg.event_id().to_owned()); 341 info.set_receipt(ReceiptThread::Main, user_id, msg.event_id().to_owned());
342 } 342 }
343 343
344 match msg { 344 match msg {
@@ -497,31 +497,32 @@ async fn refresh_rooms_forever(client: &Client, store: &AsyncProgramStore) {
497 497
498async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { 498async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
499 let mut interval = tokio::time::interval(Duration::from_secs(2)); 499 let mut interval = tokio::time::interval(Duration::from_secs(2));
500 let mut sent = HashMap::<OwnedRoomId, OwnedEventId>::default(); 500 let mut sent: HashMap<OwnedRoomId, HashMap<ReceiptThread, OwnedEventId>> = Default::default();
501 501
502 loop { 502 loop {
503 interval.tick().await; 503 interval.tick().await;
504 504
505 let locked = store.lock().await; 505 let locked = store.lock().await;
506 let user_id = &locked.application.settings.profile.user_id; 506 let user_id = &locked.application.settings.profile.user_id;
507 let updates = client 507
508 .joined_rooms() 508 let mut updates = Vec::new();
509 .into_iter() 509 for room in client.joined_rooms() {
510 .filter_map(|room| { 510 let room_id = room.room_id();
511 let room_id = room.room_id().to_owned(); 511 let Some(info) = locked.application.rooms.get(&room_id) else {
512 let info = locked.application.rooms.get(&room_id)?; 512 continue;
513 let new_receipt = info.get_receipt(user_id)?; 513 };
514 let old_receipt = sent.get(&room_id); 514
515 if Some(new_receipt) != old_receipt { 515 let changed = info.receipts(user_id).filter_map(|(thread, new_receipt)| {
516 Some((room_id, new_receipt.clone())) 516 let old_receipt = sent.get(room_id).and_then(|ts| ts.get(thread));
517 } else { 517 let changed = Some(new_receipt) != old_receipt;
518 None 518 changed.then(|| (room_id.to_owned(), thread.to_owned(), new_receipt.to_owned()))
519 } 519 });
520 }) 520
521 .collect::<Vec<_>>(); 521 updates.extend(changed);
522 }
522 drop(locked); 523 drop(locked);
523 524
524 for (room_id, new_receipt) in updates { 525 for (room_id, thread, new_receipt) in updates {
525 use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType; 526 use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType;
526 527
527 let Some(room) = client.get_room(&room_id) else { 528 let Some(room) = client.get_room(&room_id) else {
@@ -529,15 +530,11 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
529 }; 530 };
530 531
531 match room 532 match room
532 .send_single_receipt( 533 .send_single_receipt(ReceiptType::Read, thread.to_owned(), new_receipt.clone())
533 ReceiptType::Read,
534 ReceiptThread::Unthreaded,
535 new_receipt.clone(),
536 )
537 .await 534 .await
538 { 535 {
539 Ok(()) => { 536 Ok(()) => {
540 sent.insert(room_id, new_receipt); 537 sent.entry(room_id).or_default().insert(thread, new_receipt);
541 }, 538 },
542 Err(e) => tracing::warn!(?room_id, "Failed to set read receipt: {e}"), 539 Err(e) => tracing::warn!(?room_id, "Failed to set read receipt: {e}"),
543 } 540 }
@@ -1050,11 +1047,12 @@ impl ClientWorker {
1050 let Some(receipts) = receipts.get(&ReceiptType::Read) else { 1047 let Some(receipts) = receipts.get(&ReceiptType::Read) else {
1051 continue; 1048 continue;
1052 }; 1049 };
1053 for (user_id, _) in receipts 1050 for (user_id, rcpt) in receipts.iter() {
1054 .iter() 1051 info.set_receipt(
1055 .filter(|(_, rcpt)| rcpt.thread == ReceiptThread::Unthreaded) 1052 rcpt.thread.clone(),
1056 { 1053 user_id.to_owned(),
1057 info.set_receipt(user_id.to_owned(), event_id.clone()); 1054 event_id.clone(),
1055 );
1058 } 1056 }
1059 } 1057 }
1060 } 1058 }