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 {
666666 .unwrap_or_else(|| "Untitled Matrix Room".to_string())
667667 }
668668
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)> {
670673 let mut updates = vec![];
671674
672675 for (room_id, receipts) in receipts.into_iter() {
@@ -679,11 +682,7 @@ impl ChatStore {
679682 }
680683 }
681684
682 for (room_id, read_till) in updates.into_iter() {
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 }
685 return updates;
687686 }
688687
689688 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) {
src/worker.rs +18 −1
@@ -56,6 +56,7 @@ use matrix_sdk::{
5656 room::RoomType,
5757 serde::Raw,
5858 EventEncryptionAlgorithm,
59 OwnedEventId,
5960 OwnedRoomId,
6061 OwnedRoomOrAliasId,
6162 OwnedUserId,
@@ -905,6 +906,7 @@ impl ClientWorker {
905906 self.rcpt_handle = tokio::spawn({
906907 let store = store.clone();
907908 let client = self.client.clone();
909 let mut sent = HashMap::<OwnedRoomId, OwnedEventId>::default();
908910
909911 async move {
910912 // Update the displayed read receipts every 5 seconds.
@@ -914,7 +916,22 @@ impl ClientWorker {
914916 interval.tick().await;
915917
916918 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 }
918935 }
919936 }
920937 })