From 7e99e812dd55ddc169444e3e951ff515a047caef Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 12 Feb 2024 16:15:21 +0100 Subject: [PATCH] ffi/sdk: rename `mark_read` into `set_unread_flag` This slightly changes the API when interacting from the FFI layer: - instead of `mark_as_unread` and `mark_as_read`, there's now a single method `set_unread_flag(bool)`, which callers may call with true (i.e. unread) or false (i.e. not unread). - there's a new method `mark_as_read` which sends a read receipt to the latest event in the timeline, using other commits from the same PR, - forcing a room as read requires calling first `set_unread_flag(false)` then `mark_as_read()` --- bindings/matrix-sdk-ffi/src/room.rs | 29 ++++++------------- crates/matrix-sdk/src/room/mod.rs | 6 ++-- .../tests/integration/room/joined.rs | 6 ++-- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 89f361e84..6f3af113f 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -539,32 +539,21 @@ impl Room { }))) } - /// Sets a flag on the room to indicate that the user has explicitly marked - /// it as unread - pub async fn mark_as_unread(&self) -> Result<(), ClientError> { - Ok(self.inner.mark_unread(true).await?) + /// Set (or unset) a flag on the room to indicate that the user has + /// explicitly marked it as unread. + pub async fn set_unread_flag(&self, new_value: bool) -> Result<(), ClientError> { + Ok(self.inner.set_unread_flag(new_value).await?) } - /// Reverts a previously set unread flag. - pub async fn mark_as_read(&self) -> Result<(), ClientError> { - Ok(self.inner.mark_unread(false).await?) - } - - /// Reverts a previously set unread flag and sends a read receipt to the - /// latest event in the room. + /// Mark a room as read, by attaching a read receipt on the latest event. /// - /// Sending read receipts is useful when executing this from the room list - /// but shouldn't be use when entering the room, the timeline should be - /// left to its own devices in that case. - pub async fn mark_as_read_and_send_read_receipt( - &self, - receipt_type: ReceiptType, - ) -> Result<(), ClientError> { + /// Note: this does NOT unset the unread flag; it's the caller's + /// responsibility to do so, if needs be. + pub async fn mark_as_read(&self, receipt_type: ReceiptType) -> Result<(), ClientError> { let timeline = self.timeline().await?; timeline.mark_as_read(receipt_type).await?; - - self.mark_as_read().await + Ok(()) } pub async fn build_power_level_changes_from_current( diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 65a1d3e37..c416d269e 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -2490,9 +2490,9 @@ impl Room { Ok(self.client.send(request, None).await?) } - /// Sets a flag on the room to indicate that the user has explicitly marked - /// it as (un)read - pub async fn mark_unread(&self, unread: bool) -> Result<()> { + /// Set a flag on the room to indicate that the user has explicitly marked + /// it as (un)read. + pub async fn set_unread_flag(&self, unread: bool) -> Result<()> { let user_id = self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?; diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 986e131af..3cafa0ebf 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -159,7 +159,7 @@ async fn unban_user() { } #[async_test] -async fn mark_as_unread() { +async fn test_mark_as_unread() { let (client, server) = logged_in_client().await; Mock::given(method("PUT")) @@ -179,9 +179,9 @@ async fn mark_as_unread() { let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); - room.mark_unread(true).await.unwrap(); + room.set_unread_flag(true).await.unwrap(); - room.mark_unread(false).await.unwrap(); + room.set_unread_flag(false).await.unwrap(); } #[async_test]