Call runs expand on their count and fold back with a chevron
Browse files at this commite488e411edf3ccbc6fb2eb2647bb95584c1a0c74Parent: bc51e6e- feat
- call runs expand on their count and fold back with a chevron
- friends leave the sidebar, the friends button sheet lists them with search, a click opens the chat
3 changed files +135 -46
- crates/client/src/gui/chat.rs +91 -12
- crates/client/src/gui/sidebar.rs +42 -33
- crates/client/src/gui/social.rs +2 -1
crates/client/src/gui/chat.rsmodified+91 -12
| @@ -147,6 +147,7 @@ pub struct Chat { | |||
| 147 | pub(super) message_input: Entity<TextareaState>, | 147 | pub(super) message_input: Entity<TextareaState>, |
| 148 | pub(super) search_input: Entity<InputState>, | 148 | pub(super) search_input: Entity<InputState>, |
| 149 | pub(super) friends_open: bool, | 149 | pub(super) friends_open: bool, |
| 150 | + pub(super) open_calls: HashSet<Id>, | ||
| 150 | pub(super) member_input: Entity<InputState>, | 151 | pub(super) member_input: Entity<InputState>, |
| 151 | pub(super) community_search: Entity<InputState>, | 152 | pub(super) community_search: Entity<InputState>, |
| 152 | pub(super) community_hits: Vec<MessageHit>, | 153 | pub(super) community_hits: Vec<MessageHit>, |
| @@ -426,6 +427,7 @@ impl Chat { | |||
| 426 | message_input, | 427 | message_input, |
| 427 | search_input, | 428 | search_input, |
| 428 | friends_open: false, | 429 | friends_open: false, |
| 430 | + open_calls: HashSet::new(), | ||
| 429 | member_input, | 431 | member_input, |
| 430 | community_search, | 432 | community_search, |
| 431 | community_hits: vec![], | 433 | community_hits: vec![], |
| @@ -606,6 +608,14 @@ impl Chat { | |||
| 606 | } | 608 | } |
| 607 | } | 609 | } |
| 608 | 610 | ||
| 611 | + pub(super) fn call_run_end(&self, index: usize) -> Id { | ||
| 612 | + let calls = self.messages[index..] | ||
| 613 | + .iter() | ||
| 614 | + .take_while(|message| message.call.is_some()) | ||
| 615 | + .count(); | ||
| 616 | + self.messages[index + calls.max(1) - 1].id | ||
| 617 | + } | ||
| 618 | + | ||
| 609 | pub fn name_of(&self, user_id: Id) -> String { | 619 | pub fn name_of(&self, user_id: Id) -> String { |
| 610 | self.author(user_id) | 620 | self.author(user_id) |
| 611 | .map_or_else(|| user_id.to_string(), |user| user.username.clone()) | 621 | .map_or_else(|| user_id.to_string(), |user| user.username.clone()) |
| @@ -1359,7 +1369,7 @@ impl Yumush { | |||
| 1359 | .flex_row() | 1369 | .flex_row() |
| 1360 | .size_full() | 1370 | .size_full() |
| 1361 | .when(self.chat.view == View::Chat, |page| { | 1371 | .when(self.chat.view == View::Chat, |page| { |
| 1362 | - page.child(self.sidebar(&entity, palette)) | 1372 | + page.child(self.sidebar(&entity, cx, palette)) |
| 1363 | }) | 1373 | }) |
| 1364 | .relative() | 1374 | .relative() |
| 1365 | .on_mouse_move({ | 1375 | .on_mouse_move({ |
| @@ -1690,6 +1700,10 @@ impl Yumush { | |||
| 1690 | .messages | 1700 | .messages |
| 1691 | .get(index + 1) | 1701 | .get(index + 1) |
| 1692 | .is_none_or(|next| next.call.is_none()) | 1702 | .is_none_or(|next| next.call.is_none()) |
| 1703 | + || self | ||
| 1704 | + .chat | ||
| 1705 | + .open_calls | ||
| 1706 | + .contains(&self.chat.call_run_end(*index)) | ||
| 1693 | }) | 1707 | }) |
| 1694 | .map(|(index, message)| { | 1708 | .map(|(index, message)| { |
| 1695 | let calls = self.chat.messages[..=index] | 1709 | let calls = self.chat.messages[..=index] |
| @@ -1711,11 +1725,34 @@ impl Yumush { | |||
| 1711 | } | 1725 | } |
| 1712 | } | 1726 | } |
| 1713 | }; | 1727 | }; |
| 1728 | + let run = match message.call { | ||
| 1729 | + Some(_) | ||
| 1730 | + if self | ||
| 1731 | + .chat | ||
| 1732 | + .open_calls | ||
| 1733 | + .contains(&self.chat.call_run_end(index)) => | ||
| 1734 | + { | ||
| 1735 | + if self.chat.call_run_end(index) == message.id { | ||
| 1736 | + CallRun::Open | ||
| 1737 | + } else { | ||
| 1738 | + CallRun::Single | ||
| 1739 | + } | ||
| 1740 | + } | ||
| 1741 | + _ if calls > 1 => CallRun::Folded(calls), | ||
| 1742 | + _ => CallRun::Single, | ||
| 1743 | + }; | ||
| 1744 | + let first = first | ||
| 1745 | + && !(message.call.is_some() | ||
| 1746 | + && index != start | ||
| 1747 | + && self | ||
| 1748 | + .chat | ||
| 1749 | + .open_calls | ||
| 1750 | + .contains(&self.chat.call_run_end(index))); | ||
| 1714 | let row = render_message( | 1751 | let row = render_message( |
| 1715 | message, | 1752 | message, |
| 1716 | first, | 1753 | first, |
| 1717 | start > 0, | 1754 | start > 0, |
| 1718 | - calls, | 1755 | + run, |
| 1719 | &self.chat, | 1756 | &self.chat, |
| 1720 | self.user.as_ref(), | 1757 | self.user.as_ref(), |
| 1721 | entity, | 1758 | entity, |
| @@ -3069,27 +3106,60 @@ fn call_duration(seconds: u64) -> String { | |||
| 3069 | } | 3106 | } |
| 3070 | } | 3107 | } |
| 3071 | 3108 | ||
| 3109 | +#[derive(Clone, Copy)] | ||
| 3110 | +enum CallRun { | ||
| 3111 | + Single, | ||
| 3112 | + Folded(usize), | ||
| 3113 | + Open, | ||
| 3114 | +} | ||
| 3115 | + | ||
| 3072 | fn render_call( | 3116 | fn render_call( |
| 3073 | message: &Message, | 3117 | message: &Message, |
| 3074 | call: CallLog, | 3118 | call: CallLog, |
| 3075 | - calls: usize, | 3119 | + run: CallRun, |
| 3076 | spaced: bool, | 3120 | spaced: bool, |
| 3077 | chat: &Chat, | 3121 | chat: &Chat, |
| 3078 | me: Option<&User>, | 3122 | me: Option<&User>, |
| 3123 | + entity: &Entity<Yumush>, | ||
| 3079 | palette: Palette, | 3124 | palette: Palette, |
| 3080 | ) -> AnyElement { | 3125 | ) -> AnyElement { |
| 3081 | let mine = me.is_some_and(|me| me.id == message.user_id); | 3126 | let mine = me.is_some_and(|me| me.id == message.user_id); |
| 3082 | let author = chat | 3127 | let author = chat |
| 3083 | .author(message.user_id) | 3128 | .author(message.user_id) |
| 3084 | .map_or("unknown", |user| user.username.as_str()); | 3129 | .map_or("unknown", |user| user.username.as_str()); |
| 3130 | + let message_id = message.id; | ||
| 3131 | + let entity = entity.clone(); | ||
| 3132 | + let toggle = match run { | ||
| 3133 | + CallRun::Single => None, | ||
| 3134 | + CallRun::Folded(calls) => Some( | ||
| 3135 | + div() | ||
| 3136 | + .hover(|style| style.underline()) | ||
| 3137 | + .child(format!("\u{a0}· {calls} calls")), | ||
| 3138 | + ), | ||
| 3139 | + CallRun::Open => Some( | ||
| 3140 | + div() | ||
| 3141 | + .pl(px(space::XS)) | ||
| 3142 | + .child(Icon::new(IconName::ChevronUp).size(px(size::ICON_SM))), | ||
| 3143 | + ), | ||
| 3144 | + }; | ||
| 3085 | call_line(call, author, mine, palette) | 3145 | call_line(call, author, mine, palette) |
| 3086 | - .when(calls > 1, |this| { | 3146 | + .children(toggle.map(|toggle| { |
| 3087 | - this.child( | 3147 | + toggle |
| 3088 | - div() | 3148 | + .id(format!("calls_{message_id}")) |
| 3089 | - .text_color(palette.tokens.faint()) | 3149 | + .cursor_pointer() |
| 3090 | - .child(format!("\u{a0}· {calls} calls")), | 3150 | + .text_color(palette.tokens.faint()) |
| 3091 | - ) | 3151 | + .on_click(move |_, _, cx| { |
| 3092 | - }) | 3152 | + entity.update(cx, |yumush, cx| { |
| 3153 | + if !yumush.chat.open_calls.remove(&message_id) { | ||
| 3154 | + yumush.chat.open_calls.insert(message_id); | ||
| 3155 | + } | ||
| 3156 | + if !yumush.chat.away() { | ||
| 3157 | + yumush.chat.jump_to_bottom(); | ||
| 3158 | + } | ||
| 3159 | + cx.notify(); | ||
| 3160 | + }) | ||
| 3161 | + }) | ||
| 3162 | + })) | ||
| 3093 | .id(format!("message_row_{}", message.id)) | 3163 | .id(format!("message_row_{}", message.id)) |
| 3094 | .relative() | 3164 | .relative() |
| 3095 | .when(spaced, |this| this.mt(px(space::LG))) | 3165 | .when(spaced, |this| this.mt(px(space::LG))) |
| @@ -3132,14 +3202,23 @@ fn render_message( | |||
| 3132 | message: &Message, | 3202 | message: &Message, |
| 3133 | first: bool, | 3203 | first: bool, |
| 3134 | spaced: bool, | 3204 | spaced: bool, |
| 3135 | - calls: usize, | 3205 | + run: CallRun, |
| 3136 | chat: &Chat, | 3206 | chat: &Chat, |
| 3137 | me: Option<&User>, | 3207 | me: Option<&User>, |
| 3138 | entity: &Entity<Yumush>, | 3208 | entity: &Entity<Yumush>, |
| 3139 | palette: Palette, | 3209 | palette: Palette, |
| 3140 | ) -> AnyElement { | 3210 | ) -> AnyElement { |
| 3141 | if let Some(call) = message.call { | 3211 | if let Some(call) = message.call { |
| 3142 | - return render_call(message, call, calls, first && spaced, chat, me, palette); | 3212 | + return render_call( |
| 3213 | + message, | ||
| 3214 | + call, | ||
| 3215 | + run, | ||
| 3216 | + first && spaced, | ||
| 3217 | + chat, | ||
| 3218 | + me, | ||
| 3219 | + entity, | ||
| 3220 | + palette, | ||
| 3221 | + ); | ||
| 3143 | } | 3222 | } |
| 3144 | let author = chat.author(message.user_id); | 3223 | let author = chat.author(message.user_id); |
| 3145 | let username = author.map_or("unknown", |user| user.username.as_str()); | 3224 | let username = author.map_or("unknown", |user| user.username.as_str()); |
crates/client/src/gui/sidebar.rsmodified+42 -33
| @@ -32,7 +32,12 @@ use super::{ | |||
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | impl Yumush { | 34 | impl Yumush { |
| 35 | - pub(super) fn sidebar(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement { | 35 | + pub(super) fn sidebar( |
| 36 | + &self, | ||
| 37 | + entity: &Entity<Self>, | ||
| 38 | + cx: &App, | ||
| 39 | + palette: Palette, | ||
| 40 | + ) -> impl IntoElement { | ||
| 36 | let collapsed = self.chat.sidebar_collapsed; | 41 | let collapsed = self.chat.sidebar_collapsed; |
| 37 | let (from, to, id) = if collapsed { | 42 | let (from, to, id) = if collapsed { |
| 38 | (size::SIDEBAR, size::ROW, "sidebar_collapsing") | 43 | (size::SIDEBAR, size::ROW, "sidebar_collapsing") |
| @@ -42,7 +47,7 @@ impl Yumush { | |||
| 42 | let content = if collapsed { | 47 | let content = if collapsed { |
| 43 | self.collapsed_sidebar(entity, palette).into_any_element() | 48 | self.collapsed_sidebar(entity, palette).into_any_element() |
| 44 | } else { | 49 | } else { |
| 45 | - self.expanded_sidebar(entity, palette) | 50 | + self.expanded_sidebar(entity, cx, palette) |
| 46 | }; | 51 | }; |
| 47 | 52 | ||
| 48 | let sidebar = div() | 53 | let sidebar = div() |
| @@ -85,7 +90,7 @@ impl Yumush { | |||
| 85 | ) | 90 | ) |
| 86 | } | 91 | } |
| 87 | 92 | ||
| 88 | - fn expanded_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement { | 93 | + fn expanded_sidebar(&self, entity: &Entity<Self>, cx: &App, palette: Palette) -> AnyElement { |
| 89 | let friends_alert = | 94 | let friends_alert = |
| 90 | !self.chat.friends.incoming.is_empty() || !self.chat.invitations.is_empty(); | 95 | !self.chat.friends.incoming.is_empty() || !self.chat.invitations.is_empty(); |
| 91 | 96 | ||
| @@ -174,15 +179,14 @@ impl Yumush { | |||
| 174 | .flex_col() | 179 | .flex_col() |
| 175 | .gap(px(space::XXS)) | 180 | .gap(px(space::XXS)) |
| 176 | .child(self.notes_row(entity, palette)) | 181 | .child(self.notes_row(entity, palette)) |
| 177 | - .children(self.direct_rows(entity, "", palette)) | 182 | + .children(self.direct_rows(entity, "", palette)), |
| 178 | - .children(self.friend_rooms(entity, palette)), | ||
| 179 | ), | 183 | ), |
| 180 | ) | 184 | ) |
| 181 | .children(self.account_row(entity, palette)) | 185 | .children(self.account_row(entity, palette)) |
| 182 | .children( | 186 | .children( |
| 183 | self.chat | 187 | self.chat |
| 184 | .friends_open | 188 | .friends_open |
| 185 | - .then(|| self.friends_sheet(entity, palette)), | 189 | + .then(|| self.friends_sheet(entity, cx, palette)), |
| 186 | ) | 190 | ) |
| 187 | .into_any_element() | 191 | .into_any_element() |
| 188 | } | 192 | } |
| @@ -444,8 +448,17 @@ impl Yumush { | |||
| 444 | cx.notify(); | 448 | cx.notify(); |
| 445 | } | 449 | } |
| 446 | 450 | ||
| 447 | - fn friends_sheet(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement { | 451 | + fn friends_sheet(&self, entity: &Entity<Self>, cx: &App, palette: Palette) -> impl IntoElement { |
| 448 | - let found = self.chat.found.as_ref(); | 452 | + let query = super::widget::search_text(&self.chat.search_input, cx); |
| 453 | + let found = self.chat.found.as_ref().filter(|found| { | ||
| 454 | + !self | ||
| 455 | + .chat | ||
| 456 | + .friends | ||
| 457 | + .friends | ||
| 458 | + .iter() | ||
| 459 | + .any(|user| user.id == found.id) | ||
| 460 | + }); | ||
| 461 | + let friends = self.friend_list(entity, &query, palette); | ||
| 449 | let close = entity.clone(); | 462 | let close = entity.clone(); |
| 450 | gpui_kit::deferred( | 463 | gpui_kit::deferred( |
| 451 | super::parts::popover(palette.tokens) | 464 | super::parts::popover(palette.tokens) |
| @@ -463,45 +476,47 @@ impl Yumush { | |||
| 463 | }) | 476 | }) |
| 464 | .child(input_box(&self.chat.search_input, palette)) | 477 | .child(input_box(&self.chat.search_input, palette)) |
| 465 | .children(found.map(|user| self.found_row(entity, user, palette))) | 478 | .children(found.map(|user| self.found_row(entity, user, palette))) |
| 466 | - .children(self.requests(entity, palette)), | 479 | + .children(self.requests(entity, palette)) |
| 480 | + .when(!friends.is_empty(), |sheet| { | ||
| 481 | + sheet.child( | ||
| 482 | + div() | ||
| 483 | + .id("friends_list") | ||
| 484 | + .max_h(px(size::POPOVER)) | ||
| 485 | + .overflow_y_scroll() | ||
| 486 | + .flex() | ||
| 487 | + .flex_col() | ||
| 488 | + .gap(px(space::XXS)) | ||
| 489 | + .children(friends), | ||
| 490 | + ) | ||
| 491 | + }), | ||
| 467 | ) | 492 | ) |
| 468 | } | 493 | } |
| 469 | 494 | ||
| 470 | - fn friend_rooms(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> { | 495 | + fn friend_list(&self, entity: &Entity<Self>, query: &str, palette: Palette) -> Vec<AnyElement> { |
| 471 | let mut friends: Vec<&User> = self | 496 | let mut friends: Vec<&User> = self |
| 472 | .chat | 497 | .chat |
| 473 | .friends | 498 | .friends |
| 474 | .friends | 499 | .friends |
| 475 | .iter() | 500 | .iter() |
| 476 | - .filter(|user| !self.has_direct(user.id)) | 501 | + .filter(|user| matches_query(&user.username, query)) |
| 477 | .collect(); | 502 | .collect(); |
| 478 | - friends.sort_by_key(|user| self.doing(user.id)); | 503 | + friends.sort_by_key(|user| (self.doing(user.id), user.username.to_lowercase())); |
| 479 | friends | 504 | friends |
| 480 | .into_iter() | 505 | .into_iter() |
| 481 | .map(|user| { | 506 | .map(|user| { |
| 482 | let user_id = user.id; | 507 | let user_id = user.id; |
| 483 | let open = entity.clone(); | 508 | let open = entity.clone(); |
| 484 | let remove = entity.clone(); | 509 | let remove = entity.clone(); |
| 485 | - let face = presence_avatar( | ||
| 486 | - avatar( | ||
| 487 | - palette, | ||
| 488 | - user, | ||
| 489 | - px(size::AVATAR), | ||
| 490 | - text(text::CAPTION), | ||
| 491 | - &self.chat.avatars, | ||
| 492 | - ), | ||
| 493 | - self.presence_of(user.id), | ||
| 494 | - px(size::AVATAR), | ||
| 495 | - palette, | ||
| 496 | - ) | ||
| 497 | - .into_any_element(); | ||
| 498 | hoverable( | 510 | hoverable( |
| 499 | format!("friend_{}", user.id), | 511 | format!("friend_{}", user.id), |
| 500 | - room_row(palette, false, Some(face), user.username.clone(), None), | 512 | + self.user_row(palette, user, None), |
| 501 | palette, | 513 | palette, |
| 502 | ) | 514 | ) |
| 503 | .on_click(move |_, window, cx| { | 515 | .on_click(move |_, window, cx| { |
| 504 | - open.update(cx, |yumush, cx| yumush.open_direct(user_id, window, cx)) | 516 | + open.update(cx, |yumush, cx| { |
| 517 | + yumush.close_friends(cx); | ||
| 518 | + yumush.open_direct(user_id, window, cx) | ||
| 519 | + }) | ||
| 505 | }) | 520 | }) |
| 506 | .context_menu(move |menu, _, _| { | 521 | .context_menu(move |menu, _, _| { |
| 507 | menu_action( | 522 | menu_action( |
| @@ -538,12 +553,6 @@ impl Yumush { | |||
| 538 | .into_any_element() | 553 | .into_any_element() |
| 539 | } | 554 | } |
| 540 | 555 | ||
| 541 | - fn has_direct(&self, user_id: Id) -> bool { | ||
| 542 | - self.chat.communities.iter().any(|community| { | ||
| 543 | - matches!(&community.kind, CommunityKind::Direct { peer } if peer.id == user_id) | ||
| 544 | - }) | ||
| 545 | - } | ||
| 546 | - | ||
| 547 | fn communities_list(&self, entity: &Entity<Self>, palette: Palette) -> Div { | 556 | fn communities_list(&self, entity: &Entity<Self>, palette: Palette) -> Div { |
| 548 | div().flex().flex_col().gap(px(space::XXS)).children( | 557 | div().flex().flex_col().gap(px(space::XXS)).children( |
| 549 | self.unread_first( | 558 | self.unread_first( |
crates/client/src/gui/social.rsmodified+2 -1
| @@ -190,8 +190,9 @@ impl Yumush { | |||
| 190 | .detach(); | 190 | .detach(); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | - pub(super) fn open_found(&self, window: &mut Window, cx: &mut Context<Self>) { | 193 | + pub(super) fn open_found(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 194 | if let Some(user) = &self.chat.found { | 194 | if let Some(user) = &self.chat.found { |
| 195 | + self.chat.friends_open = false; | ||
| 195 | self.open_direct(user.id, window, cx); | 196 | self.open_direct(user.id, window, cx); |
| 196 | } | 197 | } |
| 197 | } | 198 | } |