From c81d3180985ee6cd0ff9d08424d48a1af9ee9dde Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 24 Jan 2024 09:45:26 -0800 Subject: [PATCH 1/4] 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); From c1df166700ab98bb04c66bda5ff4f6ed0bdacc60 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 24 Jan 2024 10:51:46 -0700 Subject: [PATCH 2/4] Allow completions of everyone in the call --- crates/channel/src/channel_store.rs | 1 - crates/collab_ui/src/chat_panel/message_editor.rs | 14 +++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/crates/channel/src/channel_store.rs b/crates/channel/src/channel_store.rs index 6e58381d60..59b69405a5 100644 --- a/crates/channel/src/channel_store.rs +++ b/crates/channel/src/channel_store.rs @@ -118,7 +118,6 @@ 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 f6f609d572..be5755ad5e 100644 --- a/crates/collab_ui/src/chat_panel/message_editor.rs +++ b/crates/collab_ui/src/chat_panel/message_editor.rs @@ -155,14 +155,6 @@ impl MessageEditor { ); } - 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); @@ -229,11 +221,11 @@ impl MessageEditor { let start_offset = end_offset - query.len(); let start_anchor = buffer.read(cx).anchor_before(start_offset); - let names = HashSet::new(); - for (github_login, _) in self.channel_members { + let mut names = HashSet::new(); + for (github_login, _) in self.channel_members.iter() { names.insert(github_login.clone()); } - if let Some(channel_id) = channel_id { + if let Some(channel_id) = self.channel_id { for participant in self.channel_store.read(cx).channel_participants(channel_id) { names.insert(participant.github_login.clone()); } From c5ad1728f98e287f27e3d5f66625a22ad36580a5 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 24 Jan 2024 11:18:17 -0700 Subject: [PATCH 3/4] Clippy --- crates/collab_ui/src/chat_panel/message_editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/collab_ui/src/chat_panel/message_editor.rs b/crates/collab_ui/src/chat_panel/message_editor.rs index be5755ad5e..a9f075b0a2 100644 --- a/crates/collab_ui/src/chat_panel/message_editor.rs +++ b/crates/collab_ui/src/chat_panel/message_editor.rs @@ -1,6 +1,6 @@ use anyhow::Result; use channel::{ChannelId, ChannelMembership, ChannelStore, MessageParams}; -use client::{User, UserId}; +use client::UserId; use collections::{HashMap, HashSet}; use editor::{AnchorRangeExt, CompletionProvider, Editor, EditorElement, EditorStyle}; use fuzzy::StringMatchCandidate; From e072c9600387f76952dc11924f9d8fd3e267d05f Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 24 Jan 2024 11:35:10 -0700 Subject: [PATCH 4/4] Fix tests --- crates/collab_ui/src/chat_panel/message_editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/collab_ui/src/chat_panel/message_editor.rs b/crates/collab_ui/src/chat_panel/message_editor.rs index a9f075b0a2..06501fe3fc 100644 --- a/crates/collab_ui/src/chat_panel/message_editor.rs +++ b/crates/collab_ui/src/chat_panel/message_editor.rs @@ -221,7 +221,7 @@ impl MessageEditor { let start_offset = end_offset - query.len(); let start_anchor = buffer.read(cx).anchor_before(start_offset); - let mut names = HashSet::new(); + let mut names = HashSet::default(); for (github_login, _) in self.channel_members.iter() { names.insert(github_login.clone()); }