From dedfc2649aef651def98ddea92a8899486d34ad4 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 1 May 2024 12:15:18 +0200 Subject: [PATCH] ffi: get rid of `name()`, and use the `computed_display_name()` everywhere This should make it more regular, in all the places, to use the same string: - Room - RoomListItem - RoomInfo --- bindings/matrix-sdk-ffi/src/room.rs | 14 +++++--------- bindings/matrix-sdk-ffi/src/room_info.rs | 4 +++- bindings/matrix-sdk-ffi/src/room_list.rs | 2 +- crates/matrix-sdk-base/src/rooms/normal.rs | 3 ++- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index dd755aaab..c0d270dd2 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -77,8 +77,11 @@ impl Room { self.inner.room_id().to_string() } - pub fn name(&self) -> Option { - self.inner.name() + /// Returns the room's name from the state event if available, otherwise + /// compute a room name based on the room's nature (DM or not) and number of + /// members. + pub fn name(&self) -> Result { + Ok(RUNTIME.block_on(self.inner.computed_display_name())?.to_string()) } pub fn topic(&self) -> Option { @@ -210,13 +213,6 @@ impl Room { Ok(Timeline::new(timeline)) } - /// Returns the room's name from the state event if available, otherwise - /// compute a room name based on the room's nature (DM or not) and number of - /// members. - pub fn computed_display_name(&self) -> Result { - Ok(RUNTIME.block_on(self.inner.computed_display_name())?.to_string()) - } - pub async fn is_encrypted(&self) -> Result { Ok(self.inner.is_encrypted().await?) } diff --git a/bindings/matrix-sdk-ffi/src/room_info.rs b/bindings/matrix-sdk-ffi/src/room_info.rs index 5ac7acb1a..57b5885c4 100644 --- a/bindings/matrix-sdk-ffi/src/room_info.rs +++ b/bindings/matrix-sdk-ffi/src/room_info.rs @@ -11,6 +11,8 @@ use crate::{ #[derive(uniffi::Record)] pub struct RoomInfo { id: String, + /// The room's name from the room state event if received from sync, or one + /// that's been computed otherwise. name: Option, topic: Option, avatar_url: Option, @@ -67,7 +69,7 @@ impl RoomInfo { Ok(Self { id: room.room_id().to_string(), - name: room.name(), + name: room.computed_display_name().await.ok().map(|name| name.to_string()), topic: room.topic(), avatar_url: avatar_url.map(Into::into), is_direct: room.is_direct().await?, diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 82594ca2e..d534f8bf0 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -493,7 +493,7 @@ impl RoomListItem { /// Returns the room's name from the state event if available, otherwise /// compute a room name based on the room's nature (DM or not) and number of /// members. - fn computed_display_name(&self) -> Option { + fn name(&self) -> Option { RUNTIME.block_on(self.inner.computed_display_name()) } diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index 95088787c..7994acd16 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -413,7 +413,8 @@ impl Room { /// Get the `m.room.name` of this room. /// - /// The returned string is guaranteed not to be empty. + /// The returned string may be empty if the event has been redacted, or it's + /// missing from storage. pub fn name(&self) -> Option { self.inner.read().name().map(ToOwned::to_owned) }