feat(ui): Unset the unread flag when sending unthreaded receipts in Timeline

Updates the unread flag or the room in `Timeline::send_single_receipt()`
and `Timeline::send_multiple_receipts()` if the room is marked as unread
and the receipts are unthreaded.

Updates it also in `Timeline::mark_as_read()`, even if there is no
latest event ID.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2025-05-19 11:52:33 +02:00
committed by Ivan Enderlin
parent dff1886015
commit bf7d5e7841

View File

@@ -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<bool> {
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)
}
}