From 63eb4298434e6180caabf50c05baccf84bcd9206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 19 May 2025 11:33:37 +0200 Subject: [PATCH] feat(sdk): Unset the unread flag when sending unthreaded receipts in Room MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the unread flag or the room in `Room::send_single_receipt()` and `Room::send_multiple_receipts()` if the room is marked as unread and the receipts are unthreaded. Signed-off-by: Kévin Commaille --- crates/matrix-sdk/src/room/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 5cd274637..5b0fb4578 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -1595,6 +1595,9 @@ impl Room { /// Send a request to set a single receipt. /// + /// If an unthreaded receipt is sent, this will also unset the unread flag + /// of the room if necessary. + /// /// # Arguments /// /// * `receipt_type` - The type of the receipt to set. Note that it is @@ -1622,6 +1625,10 @@ impl Room { .locks .read_receipt_deduplicated_handler .run((request_key, event_id.clone()), async { + // We will unset the unread flag if we send an unthreaded receipt. + let unset_unread_flag = + thread == ReceiptThread::Unthreaded && self.is_marked_unread(); + let mut request = create_receipt::v3::Request::new( self.room_id().to_owned(), receipt_type, @@ -1630,6 +1637,11 @@ impl Room { request.thread = thread; self.client.send(request).await?; + + if unset_unread_flag { + self.set_unread_flag(false).await?; + } + Ok(()) }) .await @@ -1637,6 +1649,8 @@ impl Room { /// Send a request to set multiple receipts at once. /// + /// This will also unset the unread flag of the room if necessary. + /// /// # Arguments /// /// * `receipts` - The `Receipts` to send. @@ -1656,6 +1670,11 @@ impl Room { }); self.client.send(request).await?; + + if self.is_marked_unread() { + self.set_unread_flag(false).await?; + } + Ok(()) }