diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 863ed77..10888d8 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -147,6 +147,7 @@ pub struct Chat { pub(super) message_input: Entity, pub(super) search_input: Entity, pub(super) friends_open: bool, + pub(super) open_calls: HashSet, pub(super) member_input: Entity, pub(super) community_search: Entity, pub(super) community_hits: Vec, @@ -426,6 +427,7 @@ impl Chat { message_input, search_input, friends_open: false, + open_calls: HashSet::new(), member_input, community_search, community_hits: vec![], @@ -606,6 +608,14 @@ impl Chat { } } + pub(super) fn call_run_end(&self, index: usize) -> Id { + let calls = self.messages[index..] + .iter() + .take_while(|message| message.call.is_some()) + .count(); + self.messages[index + calls.max(1) - 1].id + } + pub fn name_of(&self, user_id: Id) -> String { self.author(user_id) .map_or_else(|| user_id.to_string(), |user| user.username.clone()) @@ -1359,7 +1369,7 @@ impl Yumush { .flex_row() .size_full() .when(self.chat.view == View::Chat, |page| { - page.child(self.sidebar(&entity, palette)) + page.child(self.sidebar(&entity, cx, palette)) }) .relative() .on_mouse_move({ @@ -1690,6 +1700,10 @@ impl Yumush { .messages .get(index + 1) .is_none_or(|next| next.call.is_none()) + || self + .chat + .open_calls + .contains(&self.chat.call_run_end(*index)) }) .map(|(index, message)| { let calls = self.chat.messages[..=index] @@ -1711,11 +1725,34 @@ impl Yumush { } } }; + let run = match message.call { + Some(_) + if self + .chat + .open_calls + .contains(&self.chat.call_run_end(index)) => + { + if self.chat.call_run_end(index) == message.id { + CallRun::Open + } else { + CallRun::Single + } + } + _ if calls > 1 => CallRun::Folded(calls), + _ => CallRun::Single, + }; + let first = first + && !(message.call.is_some() + && index != start + && self + .chat + .open_calls + .contains(&self.chat.call_run_end(index))); let row = render_message( message, first, start > 0, - calls, + run, &self.chat, self.user.as_ref(), entity, @@ -3069,27 +3106,60 @@ fn call_duration(seconds: u64) -> String { } } +#[derive(Clone, Copy)] +enum CallRun { + Single, + Folded(usize), + Open, +} + fn render_call( message: &Message, call: CallLog, - calls: usize, + run: CallRun, spaced: bool, chat: &Chat, me: Option<&User>, + entity: &Entity, palette: Palette, ) -> AnyElement { let mine = me.is_some_and(|me| me.id == message.user_id); let author = chat .author(message.user_id) .map_or("unknown", |user| user.username.as_str()); + let message_id = message.id; + let entity = entity.clone(); + let toggle = match run { + CallRun::Single => None, + CallRun::Folded(calls) => Some( + div() + .hover(|style| style.underline()) + .child(format!("\u{a0}· {calls} calls")), + ), + CallRun::Open => Some( + div() + .pl(px(space::XS)) + .child(Icon::new(IconName::ChevronUp).size(px(size::ICON_SM))), + ), + }; call_line(call, author, mine, palette) - .when(calls > 1, |this| { - this.child( - div() - .text_color(palette.tokens.faint()) - .child(format!("\u{a0}· {calls} calls")), - ) - }) + .children(toggle.map(|toggle| { + toggle + .id(format!("calls_{message_id}")) + .cursor_pointer() + .text_color(palette.tokens.faint()) + .on_click(move |_, _, cx| { + entity.update(cx, |yumush, cx| { + if !yumush.chat.open_calls.remove(&message_id) { + yumush.chat.open_calls.insert(message_id); + } + if !yumush.chat.away() { + yumush.chat.jump_to_bottom(); + } + cx.notify(); + }) + }) + })) .id(format!("message_row_{}", message.id)) .relative() .when(spaced, |this| this.mt(px(space::LG))) @@ -3132,14 +3202,23 @@ fn render_message( message: &Message, first: bool, spaced: bool, - calls: usize, + run: CallRun, chat: &Chat, me: Option<&User>, entity: &Entity, palette: Palette, ) -> AnyElement { if let Some(call) = message.call { - return render_call(message, call, calls, first && spaced, chat, me, palette); + return render_call( + message, + call, + run, + first && spaced, + chat, + me, + entity, + palette, + ); } let author = chat.author(message.user_id); let username = author.map_or("unknown", |user| user.username.as_str()); diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index 84349a6..d3b9300 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -32,7 +32,12 @@ use super::{ }; impl Yumush { - pub(super) fn sidebar(&self, entity: &Entity, palette: Palette) -> impl IntoElement { + pub(super) fn sidebar( + &self, + entity: &Entity, + cx: &App, + palette: Palette, + ) -> impl IntoElement { let collapsed = self.chat.sidebar_collapsed; let (from, to, id) = if collapsed { (size::SIDEBAR, size::ROW, "sidebar_collapsing") @@ -42,7 +47,7 @@ impl Yumush { let content = if collapsed { self.collapsed_sidebar(entity, palette).into_any_element() } else { - self.expanded_sidebar(entity, palette) + self.expanded_sidebar(entity, cx, palette) }; let sidebar = div() @@ -85,7 +90,7 @@ impl Yumush { ) } - fn expanded_sidebar(&self, entity: &Entity, palette: Palette) -> AnyElement { + fn expanded_sidebar(&self, entity: &Entity, cx: &App, palette: Palette) -> AnyElement { let friends_alert = !self.chat.friends.incoming.is_empty() || !self.chat.invitations.is_empty(); @@ -174,15 +179,14 @@ impl Yumush { .flex_col() .gap(px(space::XXS)) .child(self.notes_row(entity, palette)) - .children(self.direct_rows(entity, "", palette)) - .children(self.friend_rooms(entity, palette)), + .children(self.direct_rows(entity, "", palette)), ), ) .children(self.account_row(entity, palette)) .children( self.chat .friends_open - .then(|| self.friends_sheet(entity, palette)), + .then(|| self.friends_sheet(entity, cx, palette)), ) .into_any_element() } @@ -444,8 +448,17 @@ impl Yumush { cx.notify(); } - fn friends_sheet(&self, entity: &Entity, palette: Palette) -> impl IntoElement { - let found = self.chat.found.as_ref(); + fn friends_sheet(&self, entity: &Entity, cx: &App, palette: Palette) -> impl IntoElement { + let query = super::widget::search_text(&self.chat.search_input, cx); + let found = self.chat.found.as_ref().filter(|found| { + !self + .chat + .friends + .friends + .iter() + .any(|user| user.id == found.id) + }); + let friends = self.friend_list(entity, &query, palette); let close = entity.clone(); gpui_kit::deferred( super::parts::popover(palette.tokens) @@ -463,45 +476,47 @@ impl Yumush { }) .child(input_box(&self.chat.search_input, palette)) .children(found.map(|user| self.found_row(entity, user, palette))) - .children(self.requests(entity, palette)), + .children(self.requests(entity, palette)) + .when(!friends.is_empty(), |sheet| { + sheet.child( + div() + .id("friends_list") + .max_h(px(size::POPOVER)) + .overflow_y_scroll() + .flex() + .flex_col() + .gap(px(space::XXS)) + .children(friends), + ) + }), ) } - fn friend_rooms(&self, entity: &Entity, palette: Palette) -> Vec { + fn friend_list(&self, entity: &Entity, query: &str, palette: Palette) -> Vec { let mut friends: Vec<&User> = self .chat .friends .friends .iter() - .filter(|user| !self.has_direct(user.id)) + .filter(|user| matches_query(&user.username, query)) .collect(); - friends.sort_by_key(|user| self.doing(user.id)); + friends.sort_by_key(|user| (self.doing(user.id), user.username.to_lowercase())); friends .into_iter() .map(|user| { let user_id = user.id; let open = entity.clone(); let remove = entity.clone(); - let face = presence_avatar( - avatar( - palette, - user, - px(size::AVATAR), - text(text::CAPTION), - &self.chat.avatars, - ), - self.presence_of(user.id), - px(size::AVATAR), - palette, - ) - .into_any_element(); hoverable( format!("friend_{}", user.id), - room_row(palette, false, Some(face), user.username.clone(), None), + self.user_row(palette, user, None), palette, ) .on_click(move |_, window, cx| { - open.update(cx, |yumush, cx| yumush.open_direct(user_id, window, cx)) + open.update(cx, |yumush, cx| { + yumush.close_friends(cx); + yumush.open_direct(user_id, window, cx) + }) }) .context_menu(move |menu, _, _| { menu_action( @@ -538,12 +553,6 @@ impl Yumush { .into_any_element() } - fn has_direct(&self, user_id: Id) -> bool { - self.chat.communities.iter().any(|community| { - matches!(&community.kind, CommunityKind::Direct { peer } if peer.id == user_id) - }) - } - fn communities_list(&self, entity: &Entity, palette: Palette) -> Div { div().flex().flex_col().gap(px(space::XXS)).children( self.unread_first( diff --git a/crates/client/src/gui/social.rs b/crates/client/src/gui/social.rs index c0cff6e..1ea93d8 100644 --- a/crates/client/src/gui/social.rs +++ b/crates/client/src/gui/social.rs @@ -190,8 +190,9 @@ impl Yumush { .detach(); } - pub(super) fn open_found(&self, window: &mut Window, cx: &mut Context) { + pub(super) fn open_found(&mut self, window: &mut Window, cx: &mut Context) { if let Some(user) = &self.chat.found { + self.chat.friends_open = false; self.open_direct(user.id, window, cx); } }