Commit ad8b4a60d2

ad8b4a60d2c9fb4f0301db24633d3c5f2c46db1c

parent: 4935899aed

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-05-13 00:42 UTC

ChatStore::set_receipts locks up app for bad connections (#99)

Layout: unified · split

src/base.rs +5 −6
@@ -666,7 +666,10 @@ impl ChatStore {
666 .unwrap_or_else(|| "Untitled Matrix Room".to_string()) 666 .unwrap_or_else(|| "Untitled Matrix Room".to_string())
667 } 667 }
668 668
669 pub async fn set_receipts(&mut self, receipts: Vec<(OwnedRoomId, Receipts)>) { 669 pub async fn set_receipts(
670 &mut self,
671 receipts: Vec<(OwnedRoomId, Receipts)>,
672 ) -> Vec<(OwnedRoomId, OwnedEventId)> {
670 let mut updates = vec![]; 673 let mut updates = vec![];
671 674
672 for (room_id, receipts) in receipts.into_iter() { 675 for (room_id, receipts) in receipts.into_iter() {
@@ -679,11 +682,7 @@ impl ChatStore {
679 } 682 }
680 } 683 }
681 684
682 for (room_id, read_till) in updates.into_iter() { 685 return updates;
683 if let Some(room) = self.worker.client.get_joined_room(&room_id) {
684 let _ = room.read_receipt(read_till.as_ref()).await;
685 }
686 }
687 } 686 }
688 687
689 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) { 688 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) {
src/worker.rs +18 −1
@@ -56,6 +56,7 @@ use matrix_sdk::{
56 room::RoomType, 56 room::RoomType,
57 serde::Raw, 57 serde::Raw,
58 EventEncryptionAlgorithm, 58 EventEncryptionAlgorithm,
59 OwnedEventId,
59 OwnedRoomId, 60 OwnedRoomId,
60 OwnedRoomOrAliasId, 61 OwnedRoomOrAliasId,
61 OwnedUserId, 62 OwnedUserId,
@@ -905,6 +906,7 @@ impl ClientWorker {
905 self.rcpt_handle = tokio::spawn({ 906 self.rcpt_handle = tokio::spawn({
906 let store = store.clone(); 907 let store = store.clone();
907 let client = self.client.clone(); 908 let client = self.client.clone();
909 let mut sent = HashMap::<OwnedRoomId, OwnedEventId>::default();
908 910
909 async move { 911 async move {
910 // Update the displayed read receipts every 5 seconds. 912 // Update the displayed read receipts every 5 seconds.
@@ -914,7 +916,22 @@ impl ClientWorker {
914 interval.tick().await; 916 interval.tick().await;
915 917
916 let receipts = update_receipts(&client).await; 918 let receipts = update_receipts(&client).await;
917 store.lock().await.application.set_receipts(receipts).await; 919 let read = store.lock().await.application.set_receipts(receipts).await;
920
921 for (room_id, read_till) in read.into_iter() {
922 if let Some(read_sent) = sent.get(&room_id) {
923 if read_sent == &read_till {
924 // Skip unchanged receipts.
925 continue;
926 }
927 }
928
929 if let Some(room) = client.get_joined_room(&room_id) {
930 if room.read_receipt(&read_till).await.is_ok() {
931 sent.insert(room_id, read_till);
932 }
933 }
934 }
918 } 935 }
919 } 936 }
920 }) 937 })