From 73f977986e372adad1b7b2edc514ea202bba1659 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 6 Jun 2024 12:03:04 +0200 Subject: [PATCH] sdk: use the cached computed display name in more places --- bindings/matrix-sdk-ffi/src/room.rs | 4 ++-- bindings/matrix-sdk-ffi/src/room_info.rs | 2 +- bindings/matrix-sdk-ffi/src/room_list.rs | 2 +- crates/matrix-sdk-ui/src/room_list_service/room.rs | 4 ++-- crates/matrix-sdk-ui/tests/integration/room_list_service.rs | 6 +++--- labs/multiverse/src/main.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 93707af6d..6b2c9d675 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -81,8 +81,8 @@ impl Room { /// 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 display_name(&self) -> Result { - Ok(RUNTIME.block_on(self.inner.computed_display_name())?.to_string()) + pub fn display_name(&self) -> Option { + Some(self.inner.cached_computed_display_name()?.to_string()) } /// The raw name as present in the room state event. diff --git a/bindings/matrix-sdk-ffi/src/room_info.rs b/bindings/matrix-sdk-ffi/src/room_info.rs index 9abaeecac..64cbedbc3 100644 --- a/bindings/matrix-sdk-ffi/src/room_info.rs +++ b/bindings/matrix-sdk-ffi/src/room_info.rs @@ -69,7 +69,7 @@ impl RoomInfo { Ok(Self { id: room.room_id().to_string(), - display_name: room.computed_display_name().await.ok().map(|name| name.to_string()), + display_name: room.cached_computed_display_name().map(|name| name.to_string()), raw_name: room.name(), topic: room.topic(), avatar_url: room.avatar_url().map(Into::into), diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 4e76cb075..8a3571a06 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -489,7 +489,7 @@ impl RoomListItem { /// compute a room name based on the room's nature (DM or not) and number of /// members. fn display_name(&self) -> Option { - RUNTIME.block_on(self.inner.computed_display_name()) + self.inner.cached_display_name() } fn avatar_url(&self) -> Option { diff --git a/crates/matrix-sdk-ui/src/room_list_service/room.rs b/crates/matrix-sdk-ui/src/room_list_service/room.rs index 667ed1fde..a2acec107 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/room.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/room.rs @@ -84,8 +84,8 @@ impl Room { } /// Get a computed room name for the room. - pub async fn computed_display_name(&self) -> Option { - Some(self.inner.room.computed_display_name().await.ok()?.to_string()) + pub fn cached_display_name(&self) -> Option { + Some(self.inner.room.cached_computed_display_name()?.to_string()) } /// Get the underlying [`matrix_sdk::Room`]. diff --git a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs index 602684186..8981f7047 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs @@ -2075,7 +2075,7 @@ async fn test_room() -> Result<(), Error> { let room0 = room_list.room(room_id_0).await?; // Room has received a name from sliding sync. - assert_eq!(room0.computed_display_name().await, Some("Room #0".to_owned())); + assert_eq!(room0.cached_display_name(), Some("Room #0".to_owned())); // Room has received an avatar from sliding sync. assert_eq!(room0.avatar_url(), Some(mxc_uri!("mxc://homeserver/media").to_owned())); @@ -2083,7 +2083,7 @@ async fn test_room() -> Result<(), Error> { let room1 = room_list.room(room_id_1).await?; // Room has not received a name from sliding sync, then it's calculated. - assert_eq!(room1.computed_display_name().await, Some("Empty Room".to_owned())); + assert_eq!(room1.cached_display_name(), Some("Empty Room".to_owned())); // Room has not received an avatar from sliding sync, then it's calculated, but // there is nothing to calculate from, so there is no URL. @@ -2129,7 +2129,7 @@ async fn test_room() -> Result<(), Error> { }; // Room has _now_ received a name from sliding sync! - assert_eq!(room1.computed_display_name().await, Some("Room #1".to_owned())); + assert_eq!(room1.cached_display_name(), Some("Room #1".to_owned())); // Room has _now_ received an avatar URL from sliding sync! assert_eq!(room1.avatar_url(), Some(mxc_uri!("mxc://homeserver/other-media").to_owned())); diff --git a/labs/multiverse/src/main.rs b/labs/multiverse/src/main.rs index 1d836eba1..84396636d 100644 --- a/labs/multiverse/src/main.rs +++ b/labs/multiverse/src/main.rs @@ -272,7 +272,7 @@ impl App { for (room_id, room) in &new_ui_rooms { let raw_name = room.name(); - let display_name = room.computed_display_name().await; + let display_name = room.cached_display_name(); room_infos .lock() .unwrap()