diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 0cf4492..d87ba51 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -27,7 +27,7 @@ use crate::gui::{ sidebar::unread_badge, snippet, voice_note::{self, VoiceNote}, - widget::{ok_or_notify, search_text, spawn_done}, + widget::{icon_button, ok_or_notify, search_text, spawn_done}, }; use crate::net::Levels; use crate::settings::VOLUME; @@ -51,14 +51,12 @@ use common::{ }; use gpui_kit::{ Anchor, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image, - InteractiveElement, IntoElement, ParentElement, RenderOnce, ScrollHandle, - StatefulInteractiveElement, Styled, Subscription, Task, Window, + InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement, + Styled, Subscription, Task, Window, assets::IconName, - base::Selectable, component::{ Icon, IndexPath, WindowExt, input::{InputEvent, InputState, Textarea, TextareaState}, - popover::Popover, searchable_list::SearchableVec, select::SelectState, slider::{SliderEvent, SliderState}, @@ -136,7 +134,7 @@ pub struct Chat { pub(super) selected_community_id: Option, pub(super) opened: Option, pub(super) ghost: bool, - members: Vec, + pub(super) members: Vec, pub(super) messages: Vec, pub(super) pins: Vec, history: History, @@ -269,6 +267,7 @@ pub struct Chat { pub(super) followed: Option<(Id, common::stats::Stats)>, pub(super) share_loss: HashMap<(Id, Kind), VecDeque>, pub(super) stats_at: Option, + pub(super) members_open: bool, pub(super) usage_monitor: crate::usage::Monitor, pub(super) ringing: HashSet, pub(super) ring_task: Option>, @@ -536,6 +535,7 @@ impl Chat { followed: None, share_loss: HashMap::new(), stats_at: None, + members_open: false, usage_monitor: { let monitor = crate::usage::Monitor::default(); if let Some(dir) = crate::config_dir() { @@ -1320,46 +1320,6 @@ pub(super) fn create_community( .detach(); } -#[derive(IntoElement)] -struct MembersTrigger { - palette: Palette, - members: Vec, -} - -impl Selectable for MembersTrigger { - fn selected(self, _: bool) -> Self { - self - } - - fn is_selected(&self) -> bool { - false - } -} - -impl RenderOnce for MembersTrigger { - fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement { - let palette = self.palette; - - hoverable( - "members_trigger", - div() - .h(px(size::CONTROL_SM)) - .px(px(space::SM)) - .flex() - .items_center() - .gap(px(space::SM)) - .rounded(px(radius::MD)) - .text_size(text(text::LABEL)) - .text_color(palette.muted) - .child(match self.members.len() { - 1 => "1 person".to_string(), - count => format!("{count} people"), - }), - palette, - ) - } -} - impl Yumush { pub(super) fn toggle_stats(&mut self, at: StatsAt) { self.chat.stats_at = (self.chat.stats_at != Some(at)).then_some(at); @@ -1419,19 +1379,24 @@ impl Yumush { .children(self.stage_strip(entity, themed)) .children(self.unread_bar(entity, themed)) .children(self.poll_banner(entity, themed)) - .child(div().flex_1().min_h_0().flex().child( - div().flex_1().min_w_0().flex().flex_col().map(|panel| { - match self.inline_viewer(entity, themed) { - Some(viewer) => panel.child(viewer), - None => match self.stage_grid(entity, themed) { - Some(grid) => panel.child(grid), - None => panel - .child(self.message_area(entity, themed)) - .child(self.composer(entity, themed, cx)), - }, - } - }), - )), + .child( + div() + .flex_1() + .min_h_0() + .flex() + .child(div().flex_1().min_w_0().flex().flex_col().map(|panel| { + match self.inline_viewer(entity, themed) { + Some(viewer) => panel.child(viewer), + None => match self.stage_grid(entity, themed) { + Some(grid) => panel.child(grid), + None => panel + .child(self.message_area(entity, themed)) + .child(self.composer(entity, themed, cx)), + }, + } + })) + .children(members_column(entity, self, themed)), + ), None => panel.child(empty_state(palette)), }, }) @@ -1503,7 +1468,6 @@ impl Yumush { super::parts::Ink::Paper, palette.tokens, )) - .children(group.then(|| members_popover(entity, self, palette))) .child(div().flex_1()) .children( community @@ -1522,6 +1486,21 @@ impl Yumush { (community.is_some() && !self.chat.pins.is_empty()) .then(|| message_actions::pins_popover(&self.chat, entity, palette)), ) + .children(group.then(|| { + icon_button( + "members_button", + palette, + IconName::Users, + "People", + entity_action(entity, |yumush, _, cx| { + yumush.chat.members_open = !yumush.chat.members_open; + cx.notify(); + }), + ) + .when(self.chat.members_open, |button| { + button.text_color(palette.text) + }) + })) } fn message_area(&self, entity: &Entity, palette: Palette) -> impl IntoElement { @@ -2734,12 +2713,14 @@ impl Yumush { .flex() .items_center() .gap(px(space::SM)) - .child( - div() - .text_size(text(text::LABEL)) - .text_color(palette.muted) - .child(format!("{} in call", users.len())), - ) + .when(!self.is_direct(community_id), |stack| { + stack.child( + div() + .text_size(text(text::LABEL)) + .text_color(palette.muted) + .child(format!("{} in call", users.len())), + ) + }) .children(self.in_stage_chat().then(|| { div() .ml(px(space::SM)) @@ -2780,13 +2761,20 @@ struct MemberRow { presence: Presence, } -fn members_popover(entity: &Entity, yumush: &Yumush, palette: Palette) -> impl IntoElement { +fn members_column( + entity: &Entity, + yumush: &Yumush, + palette: Palette, +) -> Option> { let chat = &yumush.chat; - let entity = entity.clone(); - let voice = chat - .selected_community_id - .map(|community_id| chat.voice_ids(community_id)) - .unwrap_or_default(); + let community_id = chat.selected_community_id?; + let group = chat + .selected_community() + .is_some_and(|community| matches!(community.kind, CommunityKind::Group)); + if !chat.members_open || !group { + return None; + } + let voice = chat.voice_ids(community_id); let members: Vec = chat .members .iter() @@ -2798,97 +2786,115 @@ fn members_popover(entity: &Entity, yumush: &Yumush, palette: Palette) - presence: yumush.presence_of(member.user.id), }) .collect(); - let avatars = chat.avatars.clone(); - - Popover::new("members_popover") - .anchor(Anchor::TopRight) - .appearance(false) - .trigger(MembersTrigger { - palette, - members: members.iter().map(|row| row.user.clone()).collect(), - }) - .content(move |_, _, _| { - let entity = entity.clone(); - - div() - .w(px(size::SIDEBAR)) - .p(px(space::XS)) - .flex() - .flex_col() - .rounded(px(radius::LG)) - .bg(palette.field) - .children(members.iter().map( - |MemberRow { - user, - rank, - in_voice, - muted, - presence, - }| { - profile_popover( - format!("member_{}", user.id), - Anchor::TopRight, - user, - &entity, - hoverable( - format!("member_trigger_{}", user.id), + let avatars = &chat.avatars; + let entity = entity.clone(); + let row = |MemberRow { + user, + rank, + in_voice, + muted, + presence, + }: &MemberRow| { + profile_popover( + format!("member_{}", user.id), + Anchor::TopRight, + user, + &entity, + hoverable( + format!("member_trigger_{}", user.id), + div() + .h(px(size::CONTROL)) + .px(px(space::SM)) + .flex() + .items_center() + .gap(px(space::SM)) + .rounded(px(radius::MD)) + .child(presence_avatar( + avatar(palette, user, px(size::ICON), text(text::CAPTION), &avatars), + *presence, + px(size::ICON), + palette, + )) + .child( + div() + .flex_1() + .min_w_0() + .flex() + .flex_col() + .child( div() - .h(px(size::CONTROL)) - .px(px(space::SM)) .flex() .items_center() .gap(px(space::SM)) - .rounded(px(radius::MD)) - .child(presence_avatar( - avatar( - palette, - user, - px(size::ICON), - text(text::CAPTION), - &avatars, - ), - *presence, - px(size::ICON), - palette, - )) - .child( - div() - .flex_1() - .min_w_0() - .flex() - .flex_col() - .child( - div() - .flex() - .items_center() - .gap(px(space::SM)) - .child(user.username.clone()) - .children(rank_tag(*rank, palette)) - .children(in_voice.then(|| { - Icon::new(IconName::Headphones) - .size(px(size::ICON_SM)) - .text_color(palette.muted) - })) - .children(muted.then(|| { - Icon::new(IconName::MicOff) - .size(px(size::ICON_SM)) - .text_color(palette.danger) - })), - ) - .children((!user.status.is_empty()).then(|| { - div() - .text_size(text(text::CAPTION)) - .text_color(palette.muted) - .truncate() - .child(user.status.clone()) - })), - ), - palette, - ), - ) - }, - )) + .child(user.username.clone()) + .children(rank_tag(*rank, palette)) + .children(in_voice.then(|| { + Icon::new(IconName::Headphones) + .size(px(size::ICON_SM)) + .text_color(palette.muted) + })) + .children(muted.then(|| { + Icon::new(IconName::MicOff) + .size(px(size::ICON_SM)) + .text_color(palette.danger) + })), + ) + .children((!user.status.is_empty()).then(|| { + div() + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .truncate() + .child(user.status.clone()) + })), + ), + palette, + ), + ) + }; + let section = |title: &'static str, rows: Vec<&MemberRow>| { + (!rows.is_empty()).then(|| { + div() + .flex() + .flex_col() + .child( + div() + .px(px(space::SM)) + .pb(px(space::XS)) + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .child(format!("{title} ยท {}", rows.len())), + ) + .children(rows.into_iter().map(row)) }) + }; + let in_call = members.iter().filter(|row| row.in_voice).collect(); + let online = members + .iter() + .filter(|row| !row.in_voice && row.presence != Presence::Offline) + .collect(); + let offline = members + .iter() + .filter(|row| !row.in_voice && row.presence == Presence::Offline) + .collect(); + + Some( + div() + .id("members_column") + .w(px(size::SIDEBAR)) + .flex_none() + .h_full() + .overflow_y_scroll() + .px(px(space::SM)) + .py(px(space::MD)) + .flex() + .flex_col() + .gap(px(space::LG)) + .border_l_1() + .border_color(palette.border) + .children(section("In call", in_call)) + .children(section("Online", online)) + .children(section("Offline", offline)), + ) } fn accent_bar(palette: Palette) -> Div { diff --git a/crates/client/src/gui/jump.rs b/crates/client/src/gui/jump.rs index 5f9bb46..b0d79f7 100644 --- a/crates/client/src/gui/jump.rs +++ b/crates/client/src/gui/jump.rs @@ -21,6 +21,7 @@ const SHOWN: usize = 8; #[derive(Clone, Copy, PartialEq)] pub(super) enum Place { Room(Id), + Person(Id), Notes, Friends, Settings(usize), @@ -52,9 +53,9 @@ impl Yumush { rooms.sort_by_key(|community| (Some(community.id) != call, !unread(community.id))); let rooms = rooms.into_iter().map(|community| { let hint = if community.kind.is_direct() { - "direct" + "person" } else { - "room" + "community" }; ( Place::Room(community.id), @@ -62,6 +63,29 @@ impl Yumush { hint, ) }); + let directs: Vec = self + .chat + .communities + .iter() + .filter_map(|community| match &community.kind { + CommunityKind::Direct { peer } => Some(peer.id), + _ => None, + }) + .collect(); + let mut seen = std::collections::HashSet::new(); + let people = self + .chat + .friends + .friends + .iter() + .chain(self.chat.members.iter().map(|member| &member.user)) + .filter(|user| { + !directs.contains(&user.id) + && self.user.as_ref().is_none_or(|me| me.id != user.id) + && seen.insert(user.id) + }) + .map(|user| (Place::Person(user.id), user.username.to_string(), "person")) + .collect::>(); let pages = [ (Place::Notes, "Notes".to_string(), "page"), (Place::Friends, "Friends".to_string(), "page"), @@ -80,6 +104,7 @@ impl Yumush { .map(|tab| (Place::Builder(tab), tab.label().to_string(), "builder")), ); rooms + .chain(people) .chain(pages) .filter(|(_, label, _)| label.to_lowercase().contains(&query)) .take(SHOWN) @@ -128,6 +153,10 @@ impl Yumush { self.show_view(View::Chat, window, cx); self.select_community(id, window, cx); } + Place::Person(id) => { + self.show_view(View::Chat, window, cx); + self.open_direct(id, window, cx); + } Place::Notes => self.open_notes(window, cx), Place::Friends => self.show_view(View::Friends, window, cx), Place::Settings(index) => { diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index de2ec87..74a29ce 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -194,12 +194,14 @@ impl Yumush { .child(super::parts::voice_line(wave, voice, palette.tokens)), ) }) - .child( - div() - .text_size(text(text::CAPTION)) - .text_color(palette.muted) - .child(ids.len().to_string()), - ) + .when(!self.is_direct(community_id), |this| { + this.child( + div() + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .child(ids.len().to_string()), + ) + }) .into_any_element() } @@ -449,9 +451,16 @@ impl Yumush { entry( palette, active, - Icon::new(IconName::Bookmark) - .size(px(size::ICON)) - .text_color(palette.accent), + div() + .size(px(size::AVATAR)) + .flex() + .items_center() + .justify_center() + .child( + Icon::new(IconName::Bookmark) + .size(px(size::ICON_SM)) + .text_color(palette.accent), + ), "Notes", unread_badge(palette, false, unread), ), @@ -527,6 +536,21 @@ impl Yumush { } else { Some(self.voice_chip(community_id, palette)) }; + let face = match &community.kind { + CommunityKind::Direct { peer } => Some(presence_avatar( + avatar( + palette, + peer, + px(size::AVATAR), + text(text::CAPTION), + &self.chat.avatars, + ), + self.presence_of(peer.id), + px(size::AVATAR), + palette, + )), + CommunityKind::Group | CommunityKind::Notes => None, + }; hoverable( format!("{key}_{}", community.id), div() @@ -535,9 +559,10 @@ impl Yumush { .rounded(px(radius::MD)) .flex() .items_center() - .gap(px(space::XS)) + .gap(px(space::SM)) .text_color(if active { palette.text } else { palette.muted }) .when(active, |row| row.font_weight(FontWeight::MEDIUM)) + .children(face) .child( div() .min_w_0()