diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 5f60c0f..fdf4ac9 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -1169,13 +1169,11 @@ impl Yumush { pub(super) fn is_direct(&self, community_id: Id) -> bool { self.chat - .communities() - .iter() - .find(|community| community.id == community_id) + .community(community_id) .is_some_and(|community| community.kind.is_direct()) } - fn is_me(&self, user_id: Id) -> bool { + pub(super) fn is_me(&self, user_id: Id) -> bool { self.user.as_ref().is_some_and(|me| me.id == user_id) } diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 7e2ead0..6b0b299 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -1069,7 +1069,7 @@ impl Chat { } } - fn community(&self, community_id: Id) -> Option<&Community> { + pub fn community(&self, community_id: Id) -> Option<&Community> { self.communities .iter() .chain(self.opened.as_ref()) @@ -2073,19 +2073,7 @@ impl Yumush { "composer_emoji", &entity, palette, - std::rc::Rc::new({ - let entity = entity.clone(); - move |emoji, window, cx| { - entity.update(cx, |yumush, cx| { - let input = yumush.chat.message_input.clone(); - input.update(cx, |state, cx| { - state.insert(emoji, window, cx); - state.focus(window, cx); - }); - input.update(cx, |state, cx| state.mark(cx)); - }) - } - }), + super::glyph::insert_into(self.chat.message_input.clone()), )) .when(!ready, |this| { this.child(voice_note::mic_button(&entity, palette)) @@ -2182,7 +2170,26 @@ impl Yumush { return; }; let _ = this.update(cx, |yumush, cx| { + let known: HashSet = yumush.chat.communities.iter().map(|c| c.id).collect(); yumush.chat.replace_communities(communities); + let calls: Vec = yumush + .chat + .communities + .iter() + .filter(|community| !known.contains(&community.id)) + .filter(|community| { + community.kind.is_direct() + && !yumush.chat.in_voice(community.id) + && yumush + .chat + .voice_ids(community.id) + .iter() + .any(|id| !yumush.is_me(*id)) + }) + .map(|community| community.id) + .collect(); + yumush.chat.ringing.extend(calls); + yumush.update_ringing(cx); yumush.request_social_avatars(cx); cx.notify(); }); diff --git a/crates/client/src/gui/community_settings.rs b/crates/client/src/gui/community_settings.rs index 22595a9..8071420 100644 --- a/crates/client/src/gui/community_settings.rs +++ b/crates/client/src/gui/community_settings.rs @@ -132,6 +132,7 @@ impl Yumush { input: &self.chat.community_name_input, current: &name, save: Yumush::save_community_name, + emoji: None, }, entity, palette, diff --git a/crates/client/src/gui/glyph.rs b/crates/client/src/gui/glyph.rs index f71c297..4cbb6c9 100644 --- a/crates/client/src/gui/glyph.rs +++ b/crates/client/src/gui/glyph.rs @@ -110,6 +110,9 @@ pub trait Fill { fn mark(&mut self, cx: &mut Context) where Self: Sized; + fn put(&mut self, emoji: &'static str, window: &mut Window, cx: &mut Context) + where + Self: Sized; } macro_rules! fill { @@ -128,6 +131,11 @@ macro_rules! fill { let content = content(&self.text().to_string()); let _ = self.set_tokens(content, cx); } + + fn put(&mut self, emoji: &'static str, window: &mut Window, cx: &mut Context) { + self.insert(emoji, window, cx); + self.focus(window, cx); + } } }; } @@ -172,6 +180,13 @@ pub fn extensions() -> MarkdownExtensions { pub type Pick = std::rc::Rc; +pub fn insert_into(input: Entity) -> Pick { + std::rc::Rc::new(move |emoji, window, cx| { + input.update(cx, |state, cx| state.put(emoji, window, cx)); + input.update(cx, |state, cx| state.mark(cx)); + }) +} + pub fn picker_button( id: &'static str, entity: &Entity, diff --git a/crates/client/src/gui/profile.rs b/crates/client/src/gui/profile.rs index e97ee8b..01fe219 100644 --- a/crates/client/src/gui/profile.rs +++ b/crates/client/src/gui/profile.rs @@ -429,13 +429,7 @@ impl Card { "status_emoji", entity, palette, - std::rc::Rc::new(move |emoji, window, cx| { - status.update(cx, |state, cx| { - state.insert(emoji, window, cx); - state.focus(window, cx); - }); - status.update(cx, |state, cx| state.mark(cx)); - }), + super::glyph::insert_into(status), )), ); } diff --git a/crates/client/src/gui/settings_page.rs b/crates/client/src/gui/settings_page.rs index f4046b0..9e500c1 100644 --- a/crates/client/src/gui/settings_page.rs +++ b/crates/client/src/gui/settings_page.rs @@ -150,6 +150,7 @@ impl Yumush { input: &self.chat.username_input, current: &user.username, save: Yumush::save_username, + emoji: None, }, entity, palette, @@ -162,6 +163,7 @@ impl Yumush { input: &self.chat.status_input, current: &user.status, save: Yumush::save_status, + emoji: Some("status_settings_emoji"), }, entity, palette, @@ -834,6 +836,7 @@ pub(super) struct Editable<'a> { pub input: &'a Entity, pub current: &'a str, pub save: fn(&mut Yumush, &mut Window, &mut Context), + pub emoji: Option<&'static str>, } pub(super) fn text_row( @@ -843,6 +846,14 @@ pub(super) fn text_row( cx: &App, ) -> Div { let dirty = editable.input.read(cx).text() != editable.current; + let picker = editable.emoji.map(|id| { + super::glyph::picker_button( + id, + entity, + palette, + super::glyph::insert_into(editable.input.clone()), + ) + }); let entity = entity.clone(); let save = editable.save; @@ -862,6 +873,7 @@ pub(super) fn text_row( .items_center() .gap(px(space::SM)) .child(field(palette, editable.input).flex_1()) + .children(picker) .when(dirty, |this| { this.child( clickable(editable.id, palette, move |window, cx| {