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
This commit is contained in:
Benjamin Bouvier
2024-05-01 12:15:18 +02:00
parent 90bed18415
commit dedfc2649a
4 changed files with 11 additions and 12 deletions

View File

@@ -77,8 +77,11 @@ impl Room {
self.inner.room_id().to_string()
}
pub fn name(&self) -> Option<String> {
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<String, ClientError> {
Ok(RUNTIME.block_on(self.inner.computed_display_name())?.to_string())
}
pub fn topic(&self) -> Option<String> {
@@ -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<String, ClientError> {
Ok(RUNTIME.block_on(self.inner.computed_display_name())?.to_string())
}
pub async fn is_encrypted(&self) -> Result<bool, ClientError> {
Ok(self.inner.is_encrypted().await?)
}

View File

@@ -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<String>,
topic: Option<String>,
avatar_url: Option<String>,
@@ -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?,

View File

@@ -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<String> {
fn name(&self) -> Option<String> {
RUNTIME.block_on(self.inner.computed_display_name())
}

View File

@@ -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<String> {
self.inner.read().name().map(ToOwned::to_owned)
}