feat(sdk): Unset the unread flag when sending unthreaded receipts in Room

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 <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2025-05-19 11:33:37 +02:00
committed by Ivan Enderlin
parent 91815ab678
commit 63eb429843

View File

@@ -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(())
}