From b4edaffbe1fe04f7cb28ab0d8bb40f7a81218112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Dec 2020 15:54:49 +0100 Subject: [PATCH] base: Rename the method to get joined/invited members. --- matrix_sdk_base/src/rooms/normal.rs | 19 ++++--- matrix_sdk_base/src/rooms/stripped.rs | 78 +-------------------------- 2 files changed, 11 insertions(+), 86 deletions(-) diff --git a/matrix_sdk_base/src/rooms/normal.rs b/matrix_sdk_base/src/rooms/normal.rs index 99804cb6..5b61dddd 100644 --- a/matrix_sdk_base/src/rooms/normal.rs +++ b/matrix_sdk_base/src/rooms/normal.rs @@ -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 + '_ { + pub async fn get_active_members(&self) -> impl Stream + '_ { 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; diff --git a/matrix_sdk_base/src/rooms/stripped.rs b/matrix_sdk_base/src/rooms/stripped.rs index df905caf..0a2adf18 100644 --- a/matrix_sdk_base/src/rooms/stripped.rs +++ b/matrix_sdk_base/src/rooms/stripped.rs @@ -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]: - /// 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::>() - // .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::>() - // .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::>() - // .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() } }