| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::button::{Button, ButtonVariants as _}; |
| 3 | use gpui_kit::component::h_flex; |
| 4 | use gpui_kit::prelude::FluentBuilder as _; |
| 5 | use gpui_kit::*; |
| 6 | |
| 7 | use super::ConversationView; |
| 8 | use crate::app_state::Selection; |
| 9 | use crate::data::Directory; |
| 10 | use crate::find_in_chat::FIND_IN_CHAT; |
| 11 | use crate::theme; |
| 12 | use crate::views::chat_pop_out::{self, POP_OUT_CHAT_LABEL}; |
| 13 | use crate::views::avatar::status_glyph; |
| 14 | use crate::views::widgets::{icon, symbol}; |
| 15 | |
| 16 | const BUTTON_SIZE: f32 = 32.; |
| 17 | const COUNT_GLYPH: f32 = 16.; |
| 18 | |
| 19 | impl ConversationView { |
| 20 | fn header_chat_id(&self) -> Option<&str> { |
| 21 | match &self.current.as_ref()?.selection { |
| 22 | Selection::Chat(chat_id) if !self.draft_active => Some(chat_id), |
| 23 | _ => None, |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | pub(super) fn chat_find_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> { |
| 28 | self.header_chat_id().filter(|_| !self.pinned)?; |
| 29 | Some( |
| 30 | Button::new("chat-find") |
| 31 | .icon(IconName::Search) |
| 32 | .ghost() |
| 33 | .size(px(BUTTON_SIZE)) |
| 34 | .rounded(px(8.)) |
| 35 | .tooltip(FIND_IN_CHAT) |
| 36 | .on_click(cx.listener(|this, _, window, cx| this.open_find(window, cx))) |
| 37 | .into_any_element(), |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | pub(super) fn pop_out_button(&self) -> Option<AnyElement> { |
| 42 | let chat_id = self |
| 43 | .header_chat_id() |
| 44 | .filter(|_| !self.popped_out && !self.pinned)? |
| 45 | .to_owned(); |
| 46 | let app = self.app.clone(); |
| 47 | Some( |
| 48 | Button::new("chat-pop-out") |
| 49 | .icon(IconName::ExternalLink) |
| 50 | .ghost() |
| 51 | .size(px(BUTTON_SIZE)) |
| 52 | .rounded(px(8.)) |
| 53 | .tooltip(POP_OUT_CHAT_LABEL) |
| 54 | .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&app, &chat_id, cx)) |
| 55 | .into_any_element(), |
| 56 | ) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | pub fn member_count(count: usize) -> Div { |
| 61 | h_flex() |
| 62 | .gap(px(4.)) |
| 63 | .items_center() |
| 64 | .text_size(px(13.)) |
| 65 | .text_color(theme::text_soft()) |
| 66 | .child(icon(IconName::Users, COUNT_GLYPH, theme::text_soft())) |
| 67 | .child(count.to_string()) |
| 68 | } |
| 69 | |
| 70 | const TITLE_NAMES: usize = 3; |
| 71 | const NAME_DOT: f32 = 10.; |
| 72 | |
| 73 | pub fn group_title(directory: &Directory, faces: &[(Option<String>, String)]) -> Div { |
| 74 | let hidden = faces.len().saturating_sub(TITLE_NAMES); |
| 75 | h_flex() |
| 76 | .min_w_0() |
| 77 | .gap(px(6.)) |
| 78 | .items_center() |
| 79 | .children(faces.iter().take(TITLE_NAMES).map(|(user_id, name)| { |
| 80 | let first = name.split_whitespace().next().unwrap_or(name).to_owned(); |
| 81 | let dot = user_id |
| 82 | .as_deref() |
| 83 | .and_then(|id| status_glyph(directory.presence_of(id).kind())) |
| 84 | .map(|(glyph, color)| symbol(glyph, NAME_DOT, color)); |
| 85 | h_flex() |
| 86 | .flex_none() |
| 87 | .gap(px(3.)) |
| 88 | .items_center() |
| 89 | .child(first) |
| 90 | .children(dot) |
| 91 | })) |
| 92 | .when(hidden > 0, |row| row.child(format!("+{hidden}"))) |
| 93 | } |