diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index d6c3563cf..de725ab5e 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -529,7 +529,10 @@ impl Timeline { /// first if the receipt points to an event in this timeline that is more /// recent than the current ones, to avoid unnecessary requests. /// - /// Returns a boolean indicating if it sent the request or not. + /// If an unthreaded receipt is sent, this will also unset the unread flag + /// of the room if necessary. + /// + /// Returns a boolean indicating if it sent the receipt or not. #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] pub async fn send_single_receipt( &self, @@ -541,6 +544,12 @@ impl Timeline { trace!( "not sending receipt, because we already cover the event with a previous receipt" ); + + if thread == ReceiptThread::Unthreaded && self.room().is_marked_unread() { + // Unset the read marker. + self.room().set_unread_flag(false).await?; + } + return Ok(false); } @@ -555,6 +564,8 @@ impl Timeline { /// checks first if the receipts point to events in this timeline that /// are more recent than the current ones, to avoid unnecessary /// requests. + /// + /// This also unsets the unread marker of the room if necessary. #[instrument(skip(self))] pub async fn send_multiple_receipts(&self, mut receipts: Receipts) -> Result<()> { if let Some(fully_read) = &receipts.fully_read { @@ -595,7 +606,13 @@ impl Timeline { } } - self.room().send_multiple_receipts(receipts).await + if !receipts.is_empty() { + self.room().send_multiple_receipts(receipts).await?; + } else if self.room().is_marked_unread() { + self.room().set_unread_flag(false).await?; + } + + Ok(()) } /// Mark the room as read by sending an unthreaded read receipt on the @@ -605,13 +622,21 @@ impl Timeline { /// reply also belongs to the unthreaded timeline. No threaded receipt /// will be sent here (see also #3123). /// - /// Returns a boolean indicating if we sent the request or not. + /// This also unsets the unread marker of the room if necessary. + /// + /// Returns a boolean indicating if it sent the receipt or not. #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] pub async fn mark_as_read(&self, receipt_type: ReceiptType) -> Result { if let Some(event_id) = self.controller.latest_event_id().await { self.send_single_receipt(receipt_type, ReceiptThread::Unthreaded, event_id).await } else { trace!("can't mark room as read because there's no latest event id"); + + if self.room().is_marked_unread() { + // Unset the read marker. + self.room().set_unread_flag(false).await?; + } + Ok(false) } }