base: Really fix the holding on across await points issue for room names

master
Damir Jelić 2021-01-11 13:40:35 +01:00
parent 6c4888a123
commit 077c20ed74
1 changed files with 15 additions and 7 deletions

View File

@ -221,19 +221,26 @@ impl Room {
/// [spec]: /// [spec]:
/// <https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room> /// <https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room>
async fn calculate_name(&self) -> String { async fn calculate_name(&self) -> String {
let inner = self.inner.read().unwrap(); let name;
let alias;
if let Some(name) = &inner.base_info.name { {
let inner = self.inner.read().unwrap();
name = inner.base_info.name.clone();
alias = inner.base_info.canonical_alias.clone();
}
if let Some(name) = name {
let name = name.trim(); let name = name.trim();
name.to_string() name.to_string()
} else if let Some(alias) = &inner.base_info.canonical_alias { } else if let Some(alias) = alias {
let alias = alias.alias().trim(); let alias = alias.alias().trim();
alias.to_string() alias.to_string()
} else { } else {
// TODO what should we do here? We have correct counts only if lazy // TODO what should we do here? We have correct counts only if lazy
// loading is used. // loading is used.
let summary = inner.summary.clone(); let summary = { self.inner.read().unwrap().summary.clone() };
drop(inner);
let joined = summary.joined_member_count; let joined = summary.joined_member_count;
let invited = summary.invited_member_count; let invited = summary.invited_member_count;
let heroes_count = summary.heroes.len() as u64; let heroes_count = summary.heroes.len() as u64;
@ -267,8 +274,9 @@ impl Room {
summary.heroes summary.heroes
); );
let inner = self.inner.read().unwrap(); self.inner
inner .read()
.unwrap()
.base_info .base_info
.calculate_room_name(joined, invited, members) .calculate_room_name(joined, invited, members)
} }