base: Rename the method to get joined/invited members.

master
Damir Jelić 2020-12-14 15:54:49 +01:00
parent 45db95742a
commit b4edaffbe1
2 changed files with 11 additions and 86 deletions

View File

@ -27,6 +27,7 @@ use matrix_sdk_common::{
identifiers::{RoomId, UserId}, identifiers::{RoomId, UserId},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::info;
use crate::{responses::UnreadNotificationsCount, store::Store}; use crate::{responses::UnreadNotificationsCount, store::Store};
@ -82,7 +83,7 @@ impl Room {
self.inner.lock().unwrap().members_synced 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 joined = self.store.get_joined_user_ids(self.room_id()).await;
let invited = self.store.get_invited_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 heroes_count = inner.summary.heroes.len() as u64;
let invited_joined = (invited + joined).saturating_sub(1); let invited_joined = (invited + joined).saturating_sub(1);
let members = self.get_j_members().await; let members = self.get_active_members().await;
// info!( info!(
// "Calculating name for {}, hero count {} members {:#?}", "Calculating name for {}, hero count {} heroes {:#?}",
// self.room_id(), self.room_id(),
// heroes_count, heroes_count,
// members inner.summary.heroes
// ); );
// TODO: This should use `self.heroes` but it is always empty??
//
let own_user_id = self.own_user_id.clone(); let own_user_id = self.own_user_id.clone();
let is_own_member = |m: &RoomMember| m.user_id() == &*own_user_id; let is_own_member = |m: &RoomMember| m.user_id() == &*own_user_id;

View File

@ -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 { pub async fn calculate_name(&self) -> String {
let inner = self.inner.lock().unwrap(); let inner = self.inner.lock().unwrap();
@ -64,75 +57,8 @@ impl StrippedRoom {
let alias = alias.alias().trim(); let alias = alias.alias().trim();
alias.to_string() alias.to_string()
} else { } else {
todo!() // TODO
// let joined = inner.summary.joined_member_count; self.room_id.to_string()
// 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()
// }
} }
} }