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()`
This commit is contained in:
Benjamin Bouvier
2024-02-12 16:15:21 +01:00
parent e97b7838c5
commit 7e99e812dd
3 changed files with 15 additions and 26 deletions

View File

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

View File

@@ -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))?;

View File

@@ -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]