[fractal/fractal-next] room-details: Hide users already in the room from invite dialog



commit e25ecb04c8c424a02ea21688a453e0de8a558832
Author: Julian Sparber <julian sparber net>
Date:   Thu Dec 9 02:25:43 2021 +0100

    room-details: Hide users already in the room from invite dialog

 .../content/room_details/invite_subpage/invitee_list.rs     | 13 +++++++++----
 src/session/room/member_list.rs                             |  7 +++++++
 2 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/src/session/content/room_details/invite_subpage/invitee_list.rs 
b/src/session/content/room_details/invite_subpage/invitee_list.rs
index cac22810..d88713ec 100644
--- a/src/session/content/room_details/invite_subpage/invitee_list.rs
+++ b/src/session/content/room_details/invite_subpage/invitee_list.rs
@@ -226,6 +226,7 @@ impl InviteeList {
         response: Result<search_users::Response, HttpError>,
     ) {
         let session = self.room().session();
+        let member_list = self.room().members();
 
         if Some(search_term) != self.search_term() {
             return;
@@ -240,12 +241,16 @@ impl InviteeList {
                 let users: Vec<Invitee> = response
                     .results
                     .into_iter()
-                    .map(|item| {
-                        if let Some(user) = self.get_invitee(&item.user_id) {
+                    .filter_map(|item| {
+                        // Skip over users that are already in the room
+                        if member_list.contains(&item.user_id) {
+                            self.remove_invitee(&item.user_id);
+                            None
+                        } else if let Some(user) = self.get_invitee(&item.user_id) {
                             // The avatar or the display name may have changed in the mean time
                             user.set_avatar_url(item.avatar_url);
                             user.set_display_name(item.display_name);
-                            user
+                            Some(user)
                         } else {
                             let user = Invitee::new(
                                 &session,
@@ -265,7 +270,7 @@ impl InviteeList {
                                 }),
                             );
 
-                            user
+                            Some(user)
                         }
                     })
                     .collect();
diff --git a/src/session/room/member_list.rs b/src/session/room/member_list.rs
index 7ca90a96..a3e9895b 100644
--- a/src/session/room/member_list.rs
+++ b/src/session/room/member_list.rs
@@ -156,4 +156,11 @@ impl MemberList {
         self.member_by_id(&event.sender)
             .update_from_member_event(event);
     }
+
+    /// Returns whether the given user id is present in `MemberList`
+    pub fn contains(&self, user_id: &UserId) -> bool {
+        let priv_ = imp::MemberList::from_instance(self);
+
+        priv_.members.borrow().contains_key(user_id)
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]