From c81d3180985ee6cd0ff9d08424d48a1af9ee9dde Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 24 Jan 2024 09:45:26 -0800 Subject: [PATCH] Start work on allowing mentions for all users in call --- crates/channel/src/channel_store.rs | 1 + .../src/chat_panel/message_editor.rs | 37 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/crates/channel/src/channel_store.rs b/crates/channel/src/channel_store.rs index 59b69405a5..6e58381d60 100644 --- a/crates/channel/src/channel_store.rs +++ b/crates/channel/src/channel_store.rs @@ -118,6 +118,7 @@ pub struct MembershipSortKey<'a> { pub enum ChannelEvent { ChannelCreated(ChannelId), ChannelRenamed(ChannelId), + ChannelParticipantsChanged(ChannelId), } impl EventEmitter for ChannelStore {} diff --git a/crates/collab_ui/src/chat_panel/message_editor.rs b/crates/collab_ui/src/chat_panel/message_editor.rs index 9bbf512877..f6f609d572 100644 --- a/crates/collab_ui/src/chat_panel/message_editor.rs +++ b/crates/collab_ui/src/chat_panel/message_editor.rs @@ -1,7 +1,7 @@ use anyhow::Result; use channel::{ChannelId, ChannelMembership, ChannelStore, MessageParams}; -use client::UserId; -use collections::HashMap; +use client::{User, UserId}; +use collections::{HashMap, HashSet}; use editor::{AnchorRangeExt, CompletionProvider, Editor, EditorElement, EditorStyle}; use fuzzy::StringMatchCandidate; use gpui::{ @@ -30,7 +30,7 @@ lazy_static! { pub struct MessageEditor { pub editor: View, channel_store: Model, - users: HashMap, + channel_members: HashMap, mentions: Vec, mentions_task: Option>, channel_id: Option, @@ -108,7 +108,7 @@ impl MessageEditor { Self { editor, channel_store, - users: HashMap::default(), + channel_members: HashMap::default(), channel_id: None, mentions: Vec::new(), mentions_task: None, @@ -147,14 +147,22 @@ impl MessageEditor { } pub fn set_members(&mut self, members: Vec, _: &mut ViewContext) { - self.users.clear(); - self.users.extend( + self.channel_members.clear(); + self.channel_members.extend( members .into_iter() .map(|member| (member.user.github_login.clone(), member.user.id)), ); } + pub fn update_users(&mut self, users: &Vec>, cx: &mut ViewContext) { + self.channel_members.extend( + users + .into_iter() + .map(|user| (user.github_login.clone(), user.id)), + ); + } + pub fn take_message(&mut self, cx: &mut ViewContext) -> MessageParams { self.editor.update(cx, |editor, cx| { let highlights = editor.text_highlights::(cx); @@ -221,9 +229,18 @@ impl MessageEditor { let start_offset = end_offset - query.len(); let start_anchor = buffer.read(cx).anchor_before(start_offset); - let candidates = self - .users - .keys() + let names = HashSet::new(); + for (github_login, _) in self.channel_members { + names.insert(github_login.clone()); + } + if let Some(channel_id) = channel_id { + for participant in self.channel_store.read(cx).channel_participants(channel_id) { + names.insert(participant.github_login.clone()); + } + } + + let candidates = names + .into_iter() .map(|user| StringMatchCandidate { id: 0, string: user.clone(), @@ -283,7 +300,7 @@ impl MessageEditor { text.clear(); text.extend(buffer.text_for_range(range.clone())); if let Some(username) = text.strip_prefix("@") { - if let Some(user_id) = this.users.get(username) { + if let Some(user_id) = this.channel_members.get(username) { let start = multi_buffer.anchor_after(range.start); let end = multi_buffer.anchor_after(range.end);