| 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::component::menu::{DropdownMenu as _, PopupMenu, PopupMenuItem}; |
| 5 | use gpui_kit::prelude::FluentBuilder as _; |
| 6 | use gpui_kit::*; |
| 7 | |
| 8 | use teams_core::is_notes_chat; |
| 9 | |
| 10 | use super::ConversationView; |
| 11 | use crate::app_state::Selection; |
| 12 | use crate::data::Directory; |
| 13 | use crate::find_in_chat::FIND_IN_CHAT; |
| 14 | use crate::theme; |
| 15 | use crate::views::avatar::status_glyph; |
| 16 | use crate::views::chat_menu::{ChatMenuTarget, MenuContext, chat_menu}; |
| 17 | use crate::views::composer::plus_menu::chat_invitees; |
| 18 | use crate::views::new_meeting_dialog::open_new_meeting_with; |
| 19 | use crate::views::sidebar::channel_menu; |
| 20 | use crate::views::widgets::{icon, menu_icon, symbol}; |
| 21 | |
| 22 | pub const CHAT_HEADER_MORE_TAG: &str = "chat-header-more"; |
| 23 | pub const CHANNEL_HEADER_MORE_TAG: &str = "channel-header-more"; |
| 24 | const SCHEDULE_MEETING_LABEL: &str = "Schedule meeting"; |
| 25 | const BUTTON_SIZE: f32 = 32.; |
| 26 | const HEADER_COMPACT_WIDTH: f32 = 480.; |
| 27 | const COUNT_GLYPH: f32 = 16.; |
| 28 | |
| 29 | impl ConversationView { |
| 30 | fn header_chat_id(&self) -> Option<&str> { |
| 31 | match &self.current.as_ref()?.selection { |
| 32 | Selection::Chat(chat_id) if !self.draft_active => Some(chat_id), |
| 33 | _ => None, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | pub(super) fn chat_find_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> { |
| 38 | self.header_chat_id().filter(|_| !self.pinned)?; |
| 39 | Some( |
| 40 | Button::new("chat-find") |
| 41 | .icon(IconName::Search) |
| 42 | .ghost() |
| 43 | .size(px(BUTTON_SIZE)) |
| 44 | .rounded(px(8.)) |
| 45 | .tooltip(FIND_IN_CHAT) |
| 46 | .on_click(cx.listener(|this, _, window, cx| this.open_find(window, cx))) |
| 47 | .into_any_element(), |
| 48 | ) |
| 49 | } |
| 50 | |
| 51 | pub(super) fn channel_more_button(&self, cx: &App) -> Option<AnyElement> { |
| 52 | let Selection::Channel(channel_id) = &self.current.as_ref()?.selection else { |
| 53 | return None; |
| 54 | }; |
| 55 | if self.pinned || self.popped_out { |
| 56 | return None; |
| 57 | } |
| 58 | let notifications = self |
| 59 | .app |
| 60 | .read(cx) |
| 61 | .sidebar |
| 62 | .teams |
| 63 | .iter() |
| 64 | .find(|entry| { |
| 65 | entry |
| 66 | .channels |
| 67 | .iter() |
| 68 | .any(|channel| &channel.id == channel_id) |
| 69 | })? |
| 70 | .channel_notifications(channel_id); |
| 71 | let (state, channel_id) = (self.app.clone(), channel_id.clone()); |
| 72 | Some( |
| 73 | Button::new(CHANNEL_HEADER_MORE_TAG) |
| 74 | .icon(IconName::Ellipsis) |
| 75 | .ghost() |
| 76 | .size(px(BUTTON_SIZE)) |
| 77 | .rounded(px(8.)) |
| 78 | .tooltip("More channel options") |
| 79 | .debug_selector(|| CHANNEL_HEADER_MORE_TAG.into()) |
| 80 | .dropdown_menu(move |popup, window, cx| { |
| 81 | channel_menu(popup, window, cx, state.clone(), &channel_id, notifications) |
| 82 | }) |
| 83 | .into_any_element(), |
| 84 | ) |
| 85 | } |
| 86 | |
| 87 | pub(super) fn header_overflows(&self) -> bool { |
| 88 | let width = self.header_width.get(); |
| 89 | width > 0. |
| 90 | && width < HEADER_COMPACT_WIDTH |
| 91 | && !self.popped_out |
| 92 | && !self.pinned |
| 93 | && self.header_chat_id().is_some() |
| 94 | } |
| 95 | |
| 96 | pub(super) fn chat_more_button( |
| 97 | &self, |
| 98 | overflow: bool, |
| 99 | cx: &Context<Self>, |
| 100 | ) -> Option<AnyElement> { |
| 101 | let chat_id = self |
| 102 | .header_chat_id() |
| 103 | .filter(|_| !self.popped_out && !self.pinned)?; |
| 104 | let target = ChatMenuTarget::for_chat(self.app.read(cx), chat_id)?; |
| 105 | let context = MenuContext::new(&self.app, cx); |
| 106 | let view = cx.entity().downgrade(); |
| 107 | let (open_details, close_details) = self.details_labels(); |
| 108 | let details_label = if self.channel_details_open { |
| 109 | close_details |
| 110 | } else { |
| 111 | open_details |
| 112 | }; |
| 113 | let copilot_label = self.copilot_label(cx); |
| 114 | Some( |
| 115 | Button::new(CHAT_HEADER_MORE_TAG) |
| 116 | .icon(IconName::Ellipsis) |
| 117 | .ghost() |
| 118 | .size(px(BUTTON_SIZE)) |
| 119 | .rounded(px(8.)) |
| 120 | .tooltip("More chat options") |
| 121 | .debug_selector(|| CHAT_HEADER_MORE_TAG.into()) |
| 122 | .dropdown_menu(move |popup, window, cx| { |
| 123 | let popup = if overflow { |
| 124 | overflow_items(popup, view.clone(), copilot_label.clone(), details_label) |
| 125 | } else { |
| 126 | popup |
| 127 | }; |
| 128 | let popup = if is_notes_chat(&target.id) { |
| 129 | popup |
| 130 | } else { |
| 131 | schedule_meeting_item(popup, &context, &target.id) |
| 132 | }; |
| 133 | chat_menu(popup, window, cx, &context, &target) |
| 134 | }) |
| 135 | .into_any_element(), |
| 136 | ) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | fn overflow_items( |
| 141 | popup: PopupMenu, |
| 142 | view: WeakEntity<ConversationView>, |
| 143 | copilot_label: String, |
| 144 | details_label: &'static str, |
| 145 | ) -> PopupMenu { |
| 146 | let (find_view, details_view) = (view.clone(), view.clone()); |
| 147 | popup |
| 148 | .item( |
| 149 | PopupMenuItem::new(FIND_IN_CHAT) |
| 150 | .icon(menu_icon(IconName::Search)) |
| 151 | .on_click(move |_, window, cx| { |
| 152 | find_view |
| 153 | .update(cx, |this, cx| this.open_find(window, cx)) |
| 154 | .ok(); |
| 155 | }), |
| 156 | ) |
| 157 | .item( |
| 158 | PopupMenuItem::new(copilot_label) |
| 159 | .icon(menu_icon(IconName::Bot)) |
| 160 | .on_click(move |_, window, cx| { |
| 161 | view.update(cx, |this, cx| this.toggle_copilot(window, cx)) |
| 162 | .ok(); |
| 163 | }), |
| 164 | ) |
| 165 | .item( |
| 166 | PopupMenuItem::new(details_label) |
| 167 | .icon(menu_icon(IconName::PanelRight)) |
| 168 | .on_click(move |_, _, cx| { |
| 169 | details_view |
| 170 | .update(cx, |this, cx| this.toggle_details(cx)) |
| 171 | .ok(); |
| 172 | }), |
| 173 | ) |
| 174 | .separator() |
| 175 | } |
| 176 | |
| 177 | fn schedule_meeting_item(popup: PopupMenu, context: &MenuContext, chat_id: &str) -> PopupMenu { |
| 178 | let (state, chat_id) = (context.state.clone(), chat_id.to_owned()); |
| 179 | popup |
| 180 | .item( |
| 181 | PopupMenuItem::new(SCHEDULE_MEETING_LABEL) |
| 182 | .icon(menu_icon(IconName::Calendar)) |
| 183 | .on_click(move |_, window, cx| { |
| 184 | let invitees = chat_invitees(state.read(cx), &chat_id); |
| 185 | open_new_meeting_with(state.clone(), invitees, window, cx); |
| 186 | }), |
| 187 | ) |
| 188 | .separator() |
| 189 | } |
| 190 | |
| 191 | pub fn member_count(count: usize) -> Div { |
| 192 | h_flex() |
| 193 | .gap(px(4.)) |
| 194 | .items_center() |
| 195 | .text_size(px(13.)) |
| 196 | .text_color(theme::text_soft()) |
| 197 | .child(icon(IconName::Users, COUNT_GLYPH, theme::text_soft())) |
| 198 | .child(count.to_string()) |
| 199 | } |
| 200 | |
| 201 | pub fn external_badge() -> Div { |
| 202 | div() |
| 203 | .debug_selector(|| EXTERNAL_BADGE.into()) |
| 204 | .flex_none() |
| 205 | .ml(px(6.)) |
| 206 | .px(px(6.)) |
| 207 | .rounded(px(4.)) |
| 208 | .bg(theme::row_hover()) |
| 209 | .text_size(px(11.)) |
| 210 | .line_height(px(18.)) |
| 211 | .text_color(theme::text_soft()) |
| 212 | .child("External") |
| 213 | } |
| 214 | |
| 215 | pub const EXTERNAL_BADGE: &str = "chat-header/external"; |
| 216 | |
| 217 | const TITLE_NAMES: usize = 3; |
| 218 | const NAME_DOT: f32 = 10.; |
| 219 | |
| 220 | pub fn group_title(directory: &Directory, faces: &[(Option<String>, String)]) -> Div { |
| 221 | let hidden = faces.len().saturating_sub(TITLE_NAMES); |
| 222 | h_flex() |
| 223 | .min_w_0() |
| 224 | .gap(px(6.)) |
| 225 | .items_center() |
| 226 | .children(faces.iter().take(TITLE_NAMES).map(|(user_id, name)| { |
| 227 | let first = name.split_whitespace().next().unwrap_or(name).to_owned(); |
| 228 | let dot = user_id |
| 229 | .as_deref() |
| 230 | .and_then(|id| status_glyph(directory.presence_of(id).kind())) |
| 231 | .map(|(glyph, color)| symbol(glyph, NAME_DOT, color)); |
| 232 | h_flex() |
| 233 | .flex_none() |
| 234 | .gap(px(3.)) |
| 235 | .items_center() |
| 236 | .child(first) |
| 237 | .children(dot) |
| 238 | })) |
| 239 | .when(hidden > 0, |row| row.child(format!("+{hidden}"))) |
| 240 | } |