mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-02-16 10:32:43 -05:00
sdk: use the cached computed display name in more places
This commit is contained in:
@@ -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<String, ClientError> {
|
||||
Ok(RUNTIME.block_on(self.inner.computed_display_name())?.to_string())
|
||||
pub fn display_name(&self) -> Option<String> {
|
||||
Some(self.inner.cached_computed_display_name()?.to_string())
|
||||
}
|
||||
|
||||
/// The raw name as present in the room state event.
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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<String> {
|
||||
RUNTIME.block_on(self.inner.computed_display_name())
|
||||
self.inner.cached_display_name()
|
||||
}
|
||||
|
||||
fn avatar_url(&self) -> Option<String> {
|
||||
|
||||
@@ -84,8 +84,8 @@ impl Room {
|
||||
}
|
||||
|
||||
/// Get a computed room name for the room.
|
||||
pub async fn computed_display_name(&self) -> Option<String> {
|
||||
Some(self.inner.room.computed_display_name().await.ok()?.to_string())
|
||||
pub fn cached_display_name(&self) -> Option<String> {
|
||||
Some(self.inner.room.cached_computed_display_name()?.to_string())
|
||||
}
|
||||
|
||||
/// Get the underlying [`matrix_sdk::Room`].
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user