From 756372f3cf55efa0b5ab48177233c58352703e40 Mon Sep 17 00:00:00 2001 From: Phil Kulak Date: Sat, 13 May 2023 13:56:50 -0700 Subject: [PATCH] Be more efficient about how we find room members. --- src/widgets/chat.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/widgets/chat.rs b/src/widgets/chat.rs index 8c6d9fa..dc2a3df 100644 --- a/src/widgets/chat.rs +++ b/src/widgets/chat.rs @@ -528,23 +528,19 @@ impl Chat { members.push(member); } - if members.len() > 5 { + if members.len() > 5 || members.len() == self.members.len() { break; } } - let names: Vec<&str> = members - .iter() - .map(|m| { - m.display_name() - .unwrap_or_else(|| m.user_id().localpart()) - .split_whitespace() - .next() - .unwrap_or_default() - }) - .collect(); - - let iter = names.into_iter().map(|n| n.to_string()); + let iter = members.iter().map(|m| { + m.display_name() + .unwrap_or_else(|| m.user_id().localpart()) + .split_whitespace() + .next() + .unwrap_or_default() + .to_string() + }); pretty_list(limit_list(iter, 5, self.members.len(), Some("at least"))) })