base: Rename the method to get joined/invited members.
parent
45db95742a
commit
b4edaffbe1
|
@ -27,6 +27,7 @@ use matrix_sdk_common::{
|
|||
identifiers::{RoomId, UserId},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::info;
|
||||
|
||||
use crate::{responses::UnreadNotificationsCount, store::Store};
|
||||
|
||||
|
@ -82,7 +83,7 @@ impl Room {
|
|||
self.inner.lock().unwrap().members_synced
|
||||
}
|
||||
|
||||
pub async fn get_j_members(&self) -> impl Stream<Item = RoomMember> + '_ {
|
||||
pub async fn get_active_members(&self) -> impl Stream<Item = RoomMember> + '_ {
|
||||
let joined = self.store.get_joined_user_ids(self.room_id()).await;
|
||||
let invited = self.store.get_invited_user_ids(self.room_id()).await;
|
||||
|
||||
|
@ -136,16 +137,14 @@ impl Room {
|
|||
let heroes_count = inner.summary.heroes.len() as u64;
|
||||
let invited_joined = (invited + joined).saturating_sub(1);
|
||||
|
||||
let members = self.get_j_members().await;
|
||||
let members = self.get_active_members().await;
|
||||
|
||||
// info!(
|
||||
// "Calculating name for {}, hero count {} members {:#?}",
|
||||
// self.room_id(),
|
||||
// heroes_count,
|
||||
// members
|
||||
// );
|
||||
// TODO: This should use `self.heroes` but it is always empty??
|
||||
//
|
||||
info!(
|
||||
"Calculating name for {}, hero count {} heroes {:#?}",
|
||||
self.room_id(),
|
||||
heroes_count,
|
||||
inner.summary.heroes
|
||||
);
|
||||
let own_user_id = self.own_user_id.clone();
|
||||
|
||||
let is_own_member = |m: &RoomMember| m.user_id() == &*own_user_id;
|
||||
|
|
|
@ -47,13 +47,6 @@ impl StrippedRoom {
|
|||
}
|
||||
}
|
||||
|
||||
/// Calculate the canonical display name of the room, taking into account
|
||||
/// its name, aliases and members.
|
||||
///
|
||||
/// The display name is calculated according to [this algorithm][spec].
|
||||
///
|
||||
/// [spec]:
|
||||
/// <https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room>
|
||||
pub async fn calculate_name(&self) -> String {
|
||||
let inner = self.inner.lock().unwrap();
|
||||
|
||||
|
@ -64,75 +57,8 @@ impl StrippedRoom {
|
|||
let alias = alias.alias().trim();
|
||||
alias.to_string()
|
||||
} else {
|
||||
todo!()
|
||||
// let joined = inner.summary.joined_member_count;
|
||||
// let invited = inner.summary.invited_member_count;
|
||||
// let heroes_count = inner.summary.heroes.len() as u64;
|
||||
// let invited_joined = (invited + joined).saturating_sub(1);
|
||||
|
||||
// let members = self.get_j_members().await;
|
||||
|
||||
// info!(
|
||||
// "Calculating name for {}, hero count {} members {:#?}",
|
||||
// self.room_id(),
|
||||
// heroes_count,
|
||||
// members
|
||||
// );
|
||||
// TODO: This should use `self.heroes` but it is always empty??
|
||||
//
|
||||
// let own_user_id = self.own_user_id.clone();
|
||||
|
||||
// let is_own_member = |m: &RoomMember| m.user_id() == &*own_user_id;
|
||||
|
||||
// if !inner.summary.heroes.is_empty() {
|
||||
// let mut names = stream::iter(inner.summary.heroes.iter())
|
||||
// .take(3)
|
||||
// .filter_map(|u| async move {
|
||||
// let user_id = UserId::try_from(u.as_str()).ok()?;
|
||||
// self.get_member(&user_id).await
|
||||
// })
|
||||
// .map(|mem| {
|
||||
// mem.display_name()
|
||||
// .map(|d| d.to_string())
|
||||
// .unwrap_or_else(|| mem.user_id().localpart().to_string())
|
||||
// })
|
||||
// .collect::<Vec<String>>()
|
||||
// .await;
|
||||
// names.sort();
|
||||
// names.join(", ")
|
||||
// } else if heroes_count >= invited_joined {
|
||||
// let mut names = members
|
||||
// .filter(|m| future::ready(is_own_member(m)))
|
||||
// .take(3)
|
||||
// .map(|mem| {
|
||||
// mem.display_name()
|
||||
// .map(|d| d.to_string())
|
||||
// .unwrap_or_else(|| mem.user_id().localpart().to_string())
|
||||
// })
|
||||
// .collect::<Vec<String>>()
|
||||
// .await;
|
||||
// // stabilize ordering
|
||||
// names.sort();
|
||||
// names.join(", ")
|
||||
// } else if heroes_count < invited_joined && invited + joined > 1 {
|
||||
// let mut names = members
|
||||
// .filter(|m| future::ready(is_own_member(m)))
|
||||
// .take(3)
|
||||
// .map(|mem| {
|
||||
// mem.display_name()
|
||||
// .map(|d| d.to_string())
|
||||
// .unwrap_or_else(|| mem.user_id().localpart().to_string())
|
||||
// })
|
||||
// .collect::<Vec<String>>()
|
||||
// .await;
|
||||
// names.sort();
|
||||
|
||||
// // TODO: What length does the spec want us to use here and in
|
||||
// // the `else`?
|
||||
// format!("{}, and {} others", names.join(", "), (joined + invited))
|
||||
// } else {
|
||||
// "Empty room".to_string()
|
||||
// }
|
||||
// TODO
|
||||
self.room_id.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue