Commit f880358a83
Unregistered key
Layout: unified · split
src/base.rs +88 −21
| @@ -12,6 +12,7 @@ use std::sync::Arc; | ||
| 12 | 12 | use std::time::{Duration, Instant}; |
| 13 | 13 | |
| 14 | 14 | use emojis::Emoji; |
| 15 | use matrix_sdk::ruma::events::receipt::ReceiptThread; | |
| 15 | 16 | use ratatui::{ |
| 16 | 17 | buffer::Buffer, |
| 17 | 18 | layout::{Alignment, Rect}, |
| @@ -869,7 +870,6 @@ impl UnreadInfo { | ||
| 869 | 870 | } |
| 870 | 871 | |
| 871 | 872 | /// Information about room's the user's joined. |
| 872 | #[derive(Default)] | |
| 873 | 873 | pub struct RoomInfo { |
| 874 | 874 | /// The display name for this room. |
| 875 | 875 | pub name: Option<String>, |
| @@ -884,15 +884,13 @@ pub struct RoomInfo { | ||
| 884 | 884 | messages: Messages, |
| 885 | 885 | |
| 886 | 886 | /// A map of read markers to display on different events. |
| 887 | pub event_receipts: HashMap<OwnedEventId, HashSet<OwnedUserId>>, | |
| 888 | ||
| 887 | pub event_receipts: HashMap<ReceiptThread, HashMap<OwnedEventId, HashSet<OwnedUserId>>>, | |
| 889 | 888 | /// A map of the most recent read marker for each user. |
| 890 | 889 | /// |
| 891 | 890 | /// Every receipt in this map should also have an entry in [`event_receipts`](`Self::event_receipts`), |
| 892 | 891 | /// however not every user has an entry. If a user's most recent receipt is |
| 893 | 892 | /// older than the oldest loaded event, that user will not be included. |
| 894 | pub user_receipts: HashMap<OwnedUserId, OwnedEventId>, | |
| 895 | ||
| 893 | pub user_receipts: HashMap<ReceiptThread, HashMap<OwnedUserId, OwnedEventId>>, | |
| 896 | 894 | /// A map of message identifiers to a map of reaction events. |
| 897 | 895 | pub reactions: HashMap<OwnedEventId, MessageReactions>, |
| 898 | 896 | |
| @@ -918,6 +916,28 @@ pub struct RoomInfo { | ||
| 918 | 916 | pub draw_last: Option<Instant>, |
| 919 | 917 | } |
| 920 | 918 | |
| 919 | impl 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 | ||
| 921 | 941 | impl RoomInfo { |
| 922 | 942 | pub fn get_thread(&self, root: Option<&EventId>) -> Option<&Messages> { |
| 923 | 943 | if let Some(thread_root) = root { |
| @@ -929,7 +949,9 @@ impl RoomInfo { | ||
| 929 | 949 | |
| 930 | 950 | pub fn get_thread_mut(&mut self, root: Option<OwnedEventId>) -> &mut Messages { |
| 931 | 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 | 955 | } else { |
| 934 | 956 | &mut self.messages |
| 935 | 957 | } |
| @@ -1069,7 +1091,9 @@ impl RoomInfo { | ||
| 1069 | 1091 | }; |
| 1070 | 1092 | |
| 1071 | 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 | 1097 | } else { |
| 1074 | 1098 | &mut self.messages |
| 1075 | 1099 | }; |
| @@ -1108,13 +1132,20 @@ impl RoomInfo { | ||
| 1108 | 1132 | /// Indicates whether this room has unread messages. |
| 1109 | 1133 | pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo { |
| 1110 | 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 | 1140 | match (last_message, last_receipt) { |
| 1114 | 1141 | (Some(((ts, recent), _)), Some(last_read)) => { |
| 1115 | 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 | 1149 | (None, _) => UnreadInfo::default(), |
| 1119 | 1150 | } |
| 1120 | 1151 | } |
| @@ -1142,7 +1173,10 @@ impl RoomInfo { | ||
| 1142 | 1173 | let event_id = msg.event_id().to_owned(); |
| 1143 | 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 | 1180 | let loc = EventLocation::Message(Some(thread_root), key.clone()); |
| 1147 | 1181 | self.keys.insert(event_id, loc); |
| 1148 | 1182 | replies.insert_message(key, msg); |
| @@ -1205,37 +1239,70 @@ impl RoomInfo { | ||
| 1205 | 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<()> { | |
| 1209 | let old_event_id = self.user_receipts.get(user_id)?; | |
| 1210 | let old_receipts = self.event_receipts.get_mut(old_event_id)?; | |
| 1242 | fn clear_receipt(&mut self, thread: &ReceiptThread, user_id: &OwnedUserId) -> Option<()> { | |
| 1243 | let 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 | 1247 | old_receipts.remove(user_id); |
| 1212 | 1248 | |
| 1213 | 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 | 1256 | None |
| 1218 | 1257 | } |
| 1219 | 1258 | |
| 1220 | pub fn set_receipt(&mut self, user_id: OwnedUserId, event_id: OwnedEventId) { | |
| 1221 | self.clear_receipt(&user_id); | |
| 1259 | pub fn set_receipt( | |
| 1260 | &mut self, | |
| 1261 | thread: ReceiptThread, | |
| 1262 | user_id: OwnedUserId, | |
| 1263 | event_id: OwnedEventId, | |
| 1264 | ) { | |
| 1265 | self.clear_receipt(&thread, &user_id); | |
| 1222 | 1266 | self.event_receipts |
| 1267 | .entry(thread.clone()) | |
| 1268 | .or_default() | |
| 1223 | 1269 | .entry(event_id.clone()) |
| 1224 | 1270 | .or_default() |
| 1225 | 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 | 1276 | let Some(((_, event_id), _)) = self.messages.last_key_value() else { |
| 1231 | 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> { | |
| 1238 | self.user_receipts.get(user_id) | |
| 1299 | pub fn receipts<'a>( | |
| 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 | 1308 | fn get_typers(&self) -> &[OwnedUserId] { |
src/config.rs +1 −1
| @@ -982,7 +982,7 @@ impl ApplicationSettings { | ||
| 982 | 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 | 986 | let (color, c) = self |
| 987 | 987 | .tunables |
| 988 | 988 | .users |
src/main.rs +1 −1
| @@ -559,7 +559,7 @@ impl Application { | ||
| 559 | 559 | |
| 560 | 560 | for room_id in store.application.sync_info.chats() { |
| 561 | 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 @@ | ||
| 2 | 2 | use std::borrow::Cow; |
| 3 | 3 | use std::cmp::{Ord, Ordering, PartialOrd}; |
| 4 | 4 | use std::collections::hash_map::DefaultHasher; |
| 5 | use std::collections::hash_set; | |
| 6 | 5 | use std::collections::BTreeMap; |
| 7 | 6 | use std::convert::{TryFrom, TryInto}; |
| 8 | 7 | use std::fmt::{self, Display}; |
| @@ -11,6 +10,7 @@ use std::ops::{Deref, DerefMut}; | ||
| 11 | 10 | |
| 12 | 11 | use chrono::{DateTime, Local as LocalTz}; |
| 13 | 12 | use humansize::{format_size, DECIMAL}; |
| 13 | use matrix_sdk::ruma::events::receipt::ReceiptThread; | |
| 14 | 14 | use serde_json::json; |
| 15 | 15 | use unicode_width::UnicodeWidthStr; |
| 16 | 16 | |
| @@ -77,8 +77,7 @@ type ProtocolPreview<'a> = (&'a Protocol, u16, u16); | ||
| 77 | 77 | |
| 78 | 78 | pub type MessageKey = (MessageTimeStamp, OwnedEventId); |
| 79 | 79 | |
| 80 | #[derive(Default)] | |
| 81 | pub struct Messages(BTreeMap<MessageKey, Message>); | |
| 80 | pub struct Messages(BTreeMap<MessageKey, Message>, pub ReceiptThread); | |
| 82 | 81 | |
| 83 | 82 | impl Deref for Messages { |
| 84 | 83 | type Target = BTreeMap<MessageKey, Message>; |
| @@ -95,6 +94,18 @@ impl DerefMut for Messages { | ||
| 95 | 94 | } |
| 96 | 95 | |
| 97 | 96 | impl 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 | 109 | pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) { |
| 99 | 110 | let event_id = key.1.clone(); |
| 100 | 111 | let msg = msg.into(); |
| @@ -633,8 +644,8 @@ struct MessageFormatter<'a> { | ||
| 633 | 644 | /// The date the message was sent. |
| 634 | 645 | date: Option<Span<'a>>, |
| 635 | 646 | |
| 636 | /// Iterator over the users who have read up to this message. | |
| 637 | read: Option<hash_set::Iter<'a, OwnedUserId>>, | |
| 647 | /// The users who have read up to this message. | |
| 648 | read: Vec<OwnedUserId>, | |
| 638 | 649 | } |
| 639 | 650 | |
| 640 | 651 | impl<'a> MessageFormatter<'a> { |
| @@ -667,13 +678,11 @@ impl<'a> MessageFormatter<'a> { | ||
| 667 | 678 | line.push(time); |
| 668 | 679 | |
| 669 | 680 | // Show read receipts. |
| 670 | let user_char = | |
| 671 | |user: &'a OwnedUserId| -> Span<'a> { settings.get_user_char_span(user) }; | |
| 672 | let mut read = self.read.iter_mut().flatten(); | |
| 681 | let user_char = |user: OwnedUserId| -> Span { settings.get_user_char_span(&user) }; | |
| 673 | 682 | |
| 674 | let a = read.next().map(user_char).unwrap_or_else(|| Span::raw(" ")); | |
| 675 | let b = read.next().map(user_char).unwrap_or_else(|| Span::raw(" ")); | |
| 676 | let c = read.next().map(user_char).unwrap_or_else(|| Span::raw(" ")); | |
| 683 | let a = self.read.pop().map(user_char).unwrap_or_else(|| Span::raw(" ")); | |
| 684 | let b = self.read.pop().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 | 687 | line.push(Span::raw(" ")); |
| 679 | 688 | line.push(c); |
| @@ -944,7 +953,13 @@ impl Message { | ||
| 944 | 953 | let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER; |
| 945 | 954 | let user = self.show_sender(prev, true, info, settings); |
| 946 | 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 | 964 | MessageFormatter { settings, cols, orig, fill, user, date, time, read } |
| 950 | 965 | } else if user_gutter + TIME_GUTTER + MIN_MSG_LEN <= width { |
| @@ -952,7 +967,7 @@ impl Message { | ||
| 952 | 967 | let fill = width - user_gutter - TIME_GUTTER; |
| 953 | 968 | let user = self.show_sender(prev, true, info, settings); |
| 954 | 969 | let time = self.timestamp.show_time(); |
| 955 | let read = None; | |
| 970 | let read = Vec::new(); | |
| 956 | 971 | |
| 957 | 972 | MessageFormatter { settings, cols, orig, fill, user, date, time, read } |
| 958 | 973 | } else if user_gutter + MIN_MSG_LEN <= width { |
| @@ -960,7 +975,7 @@ impl Message { | ||
| 960 | 975 | let fill = width - user_gutter; |
| 961 | 976 | let user = self.show_sender(prev, true, info, settings); |
| 962 | 977 | let time = None; |
| 963 | let read = None; | |
| 978 | let read = Vec::new(); | |
| 964 | 979 | |
| 965 | 980 | MessageFormatter { settings, cols, orig, fill, user, date, time, read } |
| 966 | 981 | } else { |
| @@ -968,7 +983,7 @@ impl Message { | ||
| 968 | 983 | let fill = width.saturating_sub(2); |
| 969 | 984 | let user = self.show_sender(prev, false, info, settings); |
| 970 | 985 | let time = None; |
| 971 | let read = None; | |
| 986 | let read = Vec::new(); | |
| 972 | 987 | |
| 973 | 988 | MessageFormatter { settings, cols, orig, fill, user, date, time, read } |
| 974 | 989 | } |
| @@ -1281,7 +1296,7 @@ pub mod tests { | ||
| 1281 | 1296 | assert_eq!(k6, &MSG1_KEY.clone()); |
| 1282 | 1297 | |
| 1283 | 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 | 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 | |
| 139 | 139 | pub fn mock_messages() -> Messages { |
| 140 | let mut messages = Messages::default(); | |
| 140 | let mut messages = Messages::main(); | |
| 141 | 141 | |
| 142 | 142 | messages.insert(MSG1_KEY.clone(), mock_message1()); |
| 143 | 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 | 1429 | // If the cursor is at the last message, then update the read marker. |
| 1430 | 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 | 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 | 301 | let event_id = msg.event_id(); |
| 302 | 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 | 304 | .await |
| 305 | 305 | { |
| 306 | 306 | Ok(receipts) => receipts.into_iter().map(|(u, _)| u).collect(), |
| @@ -338,7 +338,7 @@ fn load_insert( | ||
| 338 | 338 | let _ = presences.get_or_default(sender); |
| 339 | 339 | |
| 340 | 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 | 344 | match msg { |
| @@ -497,31 +497,32 @@ async fn refresh_rooms_forever(client: &Client, store: &AsyncProgramStore) { | ||
| 497 | 497 | |
| 498 | 498 | async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { |
| 499 | 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 | 502 | loop { |
| 503 | 503 | interval.tick().await; |
| 504 | 504 | |
| 505 | 505 | let locked = store.lock().await; |
| 506 | 506 | let user_id = &locked.application.settings.profile.user_id; |
| 507 | let updates = client | |
| 508 | .joined_rooms() | |
| 509 | .into_iter() | |
| 510 | .filter_map(|room| { | |
| 511 | let room_id = room.room_id().to_owned(); | |
| 512 | let info = locked.application.rooms.get(&room_id)?; | |
| 513 | let new_receipt = info.get_receipt(user_id)?; | |
| 514 | let old_receipt = sent.get(&room_id); | |
| 515 | if Some(new_receipt) != old_receipt { | |
| 516 | Some((room_id, new_receipt.clone())) | |
| 517 | } else { | |
| 518 | None | |
| 519 | } | |
| 520 | }) | |
| 521 | .collect::<Vec<_>>(); | |
| 507 | ||
| 508 | let mut updates = Vec::new(); | |
| 509 | for room in client.joined_rooms() { | |
| 510 | let room_id = room.room_id(); | |
| 511 | let Some(info) = locked.application.rooms.get(&room_id) else { | |
| 512 | continue; | |
| 513 | }; | |
| 514 | ||
| 515 | let changed = info.receipts(user_id).filter_map(|(thread, new_receipt)| { | |
| 516 | let old_receipt = sent.get(room_id).and_then(|ts| ts.get(thread)); | |
| 517 | let changed = Some(new_receipt) != old_receipt; | |
| 518 | changed.then(|| (room_id.to_owned(), thread.to_owned(), new_receipt.to_owned())) | |
| 519 | }); | |
| 520 | ||
| 521 | updates.extend(changed); | |
| 522 | } | |
| 522 | 523 | drop(locked); |
| 523 | 524 | |
| 524 | for (room_id, new_receipt) in updates { | |
| 525 | for (room_id, thread, new_receipt) in updates { | |
| 525 | 526 | use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType; |
| 526 | 527 | |
| 527 | 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 | 532 | match room |
| 532 | .send_single_receipt( | |
| 533 | ReceiptType::Read, | |
| 534 | ReceiptThread::Unthreaded, | |
| 535 | new_receipt.clone(), | |
| 536 | ) | |
| 533 | .send_single_receipt(ReceiptType::Read, thread.to_owned(), new_receipt.clone()) | |
| 537 | 534 | .await |
| 538 | 535 | { |
| 539 | 536 | Ok(()) => { |
| 540 | sent.insert(room_id, new_receipt); | |
| 537 | sent.entry(room_id).or_default().insert(thread, new_receipt); | |
| 541 | 538 | }, |
| 542 | 539 | Err(e) => tracing::warn!(?room_id, "Failed to set read receipt: {e}"), |
| 543 | 540 | } |
| @@ -1050,11 +1047,12 @@ impl ClientWorker { | ||
| 1050 | 1047 | let Some(receipts) = receipts.get(&ReceiptType::Read) else { |
| 1051 | 1048 | continue; |
| 1052 | 1049 | }; |
| 1053 | for (user_id, _) in receipts | |
| 1054 | .iter() | |
| 1055 | .filter(|(_, rcpt)| rcpt.thread == ReceiptThread::Unthreaded) | |
| 1056 | { | |
| 1057 | info.set_receipt(user_id.to_owned(), event_id.clone()); | |
| 1050 | for (user_id, rcpt) in receipts.iter() { | |
| 1051 | info.set_receipt( | |
| 1052 | rcpt.thread.clone(), | |
| 1053 | user_id.to_owned(), | |
| 1054 | event_id.clone(), | |
| 1055 | ); | |
| 1058 | 1056 | } |
| 1059 | 1057 | } |
| 1060 | 1058 | } |