chat mentions for newly joined users (#5099)

Release Notes:

- Added chat mentions for everyone in the call
This commit is contained in:
Conrad Irwin 2024-01-24 13:33:23 -07:00 committed by GitHub
commit 4ac3095a15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
use anyhow::Result; use anyhow::Result;
use channel::{ChannelId, ChannelMembership, ChannelStore, MessageParams}; use channel::{ChannelId, ChannelMembership, ChannelStore, MessageParams};
use client::UserId; use client::UserId;
use collections::HashMap; use collections::{HashMap, HashSet};
use editor::{AnchorRangeExt, CompletionProvider, Editor, EditorElement, EditorStyle}; use editor::{AnchorRangeExt, CompletionProvider, Editor, EditorElement, EditorStyle};
use fuzzy::StringMatchCandidate; use fuzzy::StringMatchCandidate;
use gpui::{ use gpui::{
@ -30,7 +30,7 @@ lazy_static! {
pub struct MessageEditor { pub struct MessageEditor {
pub editor: View<Editor>, pub editor: View<Editor>,
channel_store: Model<ChannelStore>, channel_store: Model<ChannelStore>,
users: HashMap<String, UserId>, channel_members: HashMap<String, UserId>,
mentions: Vec<UserId>, mentions: Vec<UserId>,
mentions_task: Option<Task<()>>, mentions_task: Option<Task<()>>,
channel_id: Option<ChannelId>, channel_id: Option<ChannelId>,
@ -108,7 +108,7 @@ impl MessageEditor {
Self { Self {
editor, editor,
channel_store, channel_store,
users: HashMap::default(), channel_members: HashMap::default(),
channel_id: None, channel_id: None,
mentions: Vec::new(), mentions: Vec::new(),
mentions_task: None, mentions_task: None,
@ -147,8 +147,8 @@ impl MessageEditor {
} }
pub fn set_members(&mut self, members: Vec<ChannelMembership>, _: &mut ViewContext<Self>) { pub fn set_members(&mut self, members: Vec<ChannelMembership>, _: &mut ViewContext<Self>) {
self.users.clear(); self.channel_members.clear();
self.users.extend( self.channel_members.extend(
members members
.into_iter() .into_iter()
.map(|member| (member.user.github_login.clone(), member.user.id)), .map(|member| (member.user.github_login.clone(), member.user.id)),
@ -221,9 +221,18 @@ impl MessageEditor {
let start_offset = end_offset - query.len(); let start_offset = end_offset - query.len();
let start_anchor = buffer.read(cx).anchor_before(start_offset); let start_anchor = buffer.read(cx).anchor_before(start_offset);
let candidates = self let mut names = HashSet::default();
.users for (github_login, _) in self.channel_members.iter() {
.keys() names.insert(github_login.clone());
}
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());
}
}
let candidates = names
.into_iter()
.map(|user| StringMatchCandidate { .map(|user| StringMatchCandidate {
id: 0, id: 0,
string: user.clone(), string: user.clone(),
@ -283,7 +292,7 @@ impl MessageEditor {
text.clear(); text.clear();
text.extend(buffer.text_for_range(range.clone())); text.extend(buffer.text_for_range(range.clone()));
if let Some(username) = text.strip_prefix("@") { 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 start = multi_buffer.anchor_after(range.start);
let end = multi_buffer.anchor_after(range.end); let end = multi_buffer.anchor_after(range.end);