BlueGit

ict rusty-teams

feat(parity): chat header like Teams

- video split button (Video call / Audio call) replaces the separate video and phone buttons
- divider between call actions and Copilot, search, details
- "..." menu with Schedule meeting and the chat row menu replaces the pop-out icon
- details pane "In this chat" (Pinned, Shared) for chats, shared with channel details
- chat menu moved into its own module so row and header share it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
3b37290b0824a1003946d8f2876d10a8fd64dafb
Parent
00c7763d
10 files changed +582 −431
crates/app/src/views/call_controls.rs +65 −27
@@ -2,10 +2,11 @@ use gpui_kit::assets::IconName;
2 2 use gpui_kit::component::{
3 3 button::{Button, ButtonVariants as _},
4 4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
5 6 };
6 7 use gpui_kit::*;
7 8
8 use super::widgets::icon;
9 use super::widgets::{icon, menu_icon};
9 10 use crate::app_state::{AppState, Selection};
10 11 use crate::call::{is_echo_chat, plan_for_chat};
11 12 use crate::theme;
@@ -13,6 +14,13 @@ use crate::theme;
13 14 const BUTTON_SIZE: f32 = 30.;
14 15 const GLYPH_SIZE: f32 = 16.;
15 16 const JOIN_HEIGHT: f32 = 30.;
17 const CHEVRON_WIDTH: f32 = 18.;
18 const CHEVRON_GLYPH: f32 = 12.;
19 pub const HEADER_VIDEO_CALL_TAG: &str = "header-video-call";
20 pub const HEADER_CALL_OPTIONS_TAG: &str = "header-call-options";
21 const VIDEO_CALL_LABEL: &str = "Video call";
22 const AUDIO_CALL_LABEL: &str = "Audio call";
23 const CALL_OPTIONS_LABEL: &str = "Call options";
16 24
17 25 pub fn header_call_controls(
18 26 app: &Entity<AppState>,
@@ -57,32 +65,62 @@ pub fn header_call_controls(
57 65 is_echo_chat(chat) || plan_for_chat(chat, state.directory.me.as_ref()).is_some()
58 66 }));
59 67 if callable {
60 for (id, tooltip, glyph, with_video) in [
61 ("header-video-call", "Video call", IconName::Video, true),
62 ("header-call", "Call", IconName::Phone, false),
63 ] {
64 let call_app = app.clone();
65 controls.push(
66 Button::new(id)
67 .ghost()
68 .p_0()
69 .size(px(BUTTON_SIZE))
70 .tooltip(tooltip)
71 .child(icon(glyph, GLYPH_SIZE, theme::text_soft()))
72 .on_click(move |_, _, cx| {
73 call_app.update(cx, |state, cx| {
74 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
75 if with_video {
76 state.start_chat_video_call(&chat_id, cx);
77 } else {
78 state.start_chat_call(&chat_id, cx);
79 }
80 }
81 });
82 })
83 .into_any_element(),
84 );
85 }
68 controls.push(video_split_button(app));
86 69 }
87 70 controls
88 71 }
72
73 fn start_call(app: &Entity<AppState>, with_video: bool, cx: &mut App) {
74 app.update(cx, |state, cx| {
75 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
76 if with_video {
77 state.start_chat_video_call(&chat_id, cx);
78 } else {
79 state.start_chat_call(&chat_id, cx);
80 }
81 }
82 });
83 }
84
85 fn video_split_button(app: &Entity<AppState>) -> AnyElement {
86 let video_app = app.clone();
87 let menu_app = app.clone();
88 h_flex()
89 .flex_none()
90 .items_center()
91 .child(
92 Button::new(HEADER_VIDEO_CALL_TAG)
93 .ghost()
94 .p_0()
95 .size(px(BUTTON_SIZE))
96 .tooltip(VIDEO_CALL_LABEL)
97 .debug_selector(|| HEADER_VIDEO_CALL_TAG.into())
98 .child(icon(IconName::Video, GLYPH_SIZE, theme::text_soft()))
99 .on_click(move |_, _, cx| start_call(&video_app, true, cx)),
100 )
101 .child(
102 Button::new(HEADER_CALL_OPTIONS_TAG)
103 .ghost()
104 .p_0()
105 .w(px(CHEVRON_WIDTH))
106 .h(px(BUTTON_SIZE))
107 .tooltip(CALL_OPTIONS_LABEL)
108 .debug_selector(|| HEADER_CALL_OPTIONS_TAG.into())
109 .child(icon(IconName::ChevronDown, CHEVRON_GLYPH, theme::text_soft()))
110 .dropdown_menu(move |popup, _, _| {
111 let (video, audio) = (menu_app.clone(), menu_app.clone());
112 popup
113 .item(
114 PopupMenuItem::new(VIDEO_CALL_LABEL)
115 .icon(menu_icon(IconName::Video))
116 .on_click(move |_, _, cx| start_call(&video, true, cx)),
117 )
118 .item(
119 PopupMenuItem::new(AUDIO_CALL_LABEL)
120 .icon(menu_icon(IconName::Phone))
121 .on_click(move |_, _, cx| start_call(&audio, false, cx)),
122 )
123 }),
124 )
125 .into_any_element()
126 }
@@ -2,10 +2,11 @@ use gpui_kit::assets::IconName;
2use gpui_kit::component::{
2use gpui_kit::component::{
3 button::{Button, ButtonVariants as _},
3 button::{Button, ButtonVariants as _},
4 h_flex,
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
5};
6};
6use gpui_kit::*;
7use gpui_kit::*;
7
8
8use super::widgets::icon;
9use super::widgets::{icon, menu_icon};
9use crate::app_state::{AppState, Selection};
10use crate::app_state::{AppState, Selection};
10use crate::call::{is_echo_chat, plan_for_chat};
11use crate::call::{is_echo_chat, plan_for_chat};
11use crate::theme;
12use crate::theme;
@@ -13,6 +14,13 @@ use crate::theme;
13const BUTTON_SIZE: f32 = 30.;
14const BUTTON_SIZE: f32 = 30.;
14const GLYPH_SIZE: f32 = 16.;
15const GLYPH_SIZE: f32 = 16.;
15const JOIN_HEIGHT: f32 = 30.;
16const JOIN_HEIGHT: f32 = 30.;
17const CHEVRON_WIDTH: f32 = 18.;
18const CHEVRON_GLYPH: f32 = 12.;
19pub const HEADER_VIDEO_CALL_TAG: &str = "header-video-call";
20pub const HEADER_CALL_OPTIONS_TAG: &str = "header-call-options";
21const VIDEO_CALL_LABEL: &str = "Video call";
22const AUDIO_CALL_LABEL: &str = "Audio call";
23const CALL_OPTIONS_LABEL: &str = "Call options";
16
24
17pub fn header_call_controls(
25pub fn header_call_controls(
18 app: &Entity<AppState>,
26 app: &Entity<AppState>,
@@ -57,32 +65,62 @@ pub fn header_call_controls(
57 is_echo_chat(chat) || plan_for_chat(chat, state.directory.me.as_ref()).is_some()
65 is_echo_chat(chat) || plan_for_chat(chat, state.directory.me.as_ref()).is_some()
58 }));
66 }));
59 if callable {
67 if callable {
60 for (id, tooltip, glyph, with_video) in [
68 controls.push(video_split_button(app));
61 ("header-video-call", "Video call", IconName::Video, true),
62 ("header-call", "Call", IconName::Phone, false),
63 ] {
64 let call_app = app.clone();
65 controls.push(
66 Button::new(id)
67 .ghost()
68 .p_0()
69 .size(px(BUTTON_SIZE))
70 .tooltip(tooltip)
71 .child(icon(glyph, GLYPH_SIZE, theme::text_soft()))
72 .on_click(move |_, _, cx| {
73 call_app.update(cx, |state, cx| {
74 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
75 if with_video {
76 state.start_chat_video_call(&chat_id, cx);
77 } else {
78 state.start_chat_call(&chat_id, cx);
79 }
80 }
81 });
82 })
83 .into_any_element(),
84 );
85 }
86 }
69 }
87 controls
70 controls
88}
71}
72
73fn start_call(app: &Entity<AppState>, with_video: bool, cx: &mut App) {
74 app.update(cx, |state, cx| {
75 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
76 if with_video {
77 state.start_chat_video_call(&chat_id, cx);
78 } else {
79 state.start_chat_call(&chat_id, cx);
80 }
81 }
82 });
83}
84
85fn video_split_button(app: &Entity<AppState>) -> AnyElement {
86 let video_app = app.clone();
87 let menu_app = app.clone();
88 h_flex()
89 .flex_none()
90 .items_center()
91 .child(
92 Button::new(HEADER_VIDEO_CALL_TAG)
93 .ghost()
94 .p_0()
95 .size(px(BUTTON_SIZE))
96 .tooltip(VIDEO_CALL_LABEL)
97 .debug_selector(|| HEADER_VIDEO_CALL_TAG.into())
98 .child(icon(IconName::Video, GLYPH_SIZE, theme::text_soft()))
99 .on_click(move |_, _, cx| start_call(&video_app, true, cx)),
100 )
101 .child(
102 Button::new(HEADER_CALL_OPTIONS_TAG)
103 .ghost()
104 .p_0()
105 .w(px(CHEVRON_WIDTH))
106 .h(px(BUTTON_SIZE))
107 .tooltip(CALL_OPTIONS_LABEL)
108 .debug_selector(|| HEADER_CALL_OPTIONS_TAG.into())
109 .child(icon(IconName::ChevronDown, CHEVRON_GLYPH, theme::text_soft()))
110 .dropdown_menu(move |popup, _, _| {
111 let (video, audio) = (menu_app.clone(), menu_app.clone());
112 popup
113 .item(
114 PopupMenuItem::new(VIDEO_CALL_LABEL)
115 .icon(menu_icon(IconName::Video))
116 .on_click(move |_, _, cx| start_call(&video, true, cx)),
117 )
118 .item(
119 PopupMenuItem::new(AUDIO_CALL_LABEL)
120 .icon(menu_icon(IconName::Phone))
121 .on_click(move |_, _, cx| start_call(&audio, false, cx)),
122 )
123 }),
124 )
125 .into_any_element()
126}
crates/app/src/views/chat_members.rs +1 −1
@@ -14,7 +14,7 @@ use gpui_kit::*;
14 14 use super::add_people_dialog::open_add_people;
15 15 use super::avatar::{person_avatar, with_presence};
16 16 use super::profile_card::opens_profile;
17 use super::sidebar::confirm_leave;
17 use super::chat_menu::confirm_leave;
18 18 use super::widgets::icon;
19 19 use crate::app_state::AppState;
20 20 use crate::chat_actions::TITLE_LIMIT;
@@ -14,7 +14,7 @@ use gpui_kit::*;
14use super::add_people_dialog::open_add_people;
14use super::add_people_dialog::open_add_people;
15use super::avatar::{person_avatar, with_presence};
15use super::avatar::{person_avatar, with_presence};
16use super::profile_card::opens_profile;
16use super::profile_card::opens_profile;
17use super::sidebar::confirm_leave;
17use super::chat_menu::confirm_leave;
18use super::widgets::icon;
18use super::widgets::icon;
19use crate::app_state::AppState;
19use crate::app_state::AppState;
20use crate::chat_actions::TITLE_LIMIT;
20use crate::chat_actions::TITLE_LIMIT;
crates/app/src/views/chat_menu.rs added +398 −0
@@ -0,0 +1,398 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::button::{Button, ButtonVariants as _};
3 use gpui_kit::component::dialog::DialogFooter;
4 use gpui_kit::component::menu::{PopupMenu, PopupMenuItem};
5 use gpui_kit::component::WindowExt as _;
6 use gpui_kit::*;
7 use teams_core::{ChatNotificationMode, DesktopNotifications, chat_link, is_notes_chat};
8
9 use super::chat_pop_out;
10 use super::widgets::menu_icon;
11 use crate::app_state::{AppState, chat_title};
12 use crate::chat_actions::TITLE_LIMIT;
13 use crate::notice::truncated;
14 use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
15 use crate::theme;
16
17 const GROUP_KIND: &str = "group";
18
19 #[derive(Clone)]
20 pub(crate) struct ChatMenuTarget {
21 pub id: String,
22 pub title: String,
23 pub folder_id: Option<String>,
24 pub unread: bool,
25 pub muted: bool,
26 pub is_group: bool,
27 pub member_count: usize,
28 }
29
30 impl ChatMenuTarget {
31 pub(crate) fn for_chat(state: &AppState, chat_id: &str) -> Option<Self> {
32 let chat = state.sidebar.chats.iter().find(|chat| chat.id == chat_id)?;
33 Some(ChatMenuTarget {
34 id: chat.id.clone(),
35 title: chat_title(chat),
36 folder_id: state
37 .directory
38 .folder_of(chat_id)
39 .map(|folder| folder.id.clone()),
40 unread: chat.unread,
41 muted: chat.muted,
42 is_group: chat.kind == GROUP_KIND,
43 member_count: chat.members.len(),
44 })
45 }
46 }
47
48 #[derive(Clone)]
49 pub(crate) struct MenuContext {
50 pub state: Entity<AppState>,
51 pub folders: Vec<(String, String)>,
52 }
53
54 impl MenuContext {
55 pub(crate) fn new(state: &Entity<AppState>, cx: &App) -> Self {
56 MenuContext {
57 state: state.clone(),
58 folders: state.read(cx).directory.move_targets(),
59 }
60 }
61 }
62
63 pub(crate) fn chat_menu(
64 popup: PopupMenu,
65 window: &mut Window,
66 cx: &mut Context<PopupMenu>,
67 context: &MenuContext,
68 target: &ChatMenuTarget,
69 ) -> PopupMenu {
70 let mut popup = popup;
71 let read_state = context.state.clone();
72 let read_id = target.id.clone();
73 let unread = target.unread;
74 let mute_state = context.state.clone();
75 let mute_id = target.id.clone();
76 let muted = target.muted;
77 let hide_state = context.state.clone();
78 let hide_id = target.id.clone();
79 let notes = is_notes_chat(&target.id);
80 popup = popup.item(
81 PopupMenuItem::new(if unread {
82 "Mark as read"
83 } else {
84 "Mark as unread"
85 })
86 .icon(menu_icon(if unread {
87 IconName::MailOpen
88 } else {
89 IconName::Mail
90 }))
91 .on_click(move |_, _, cx| {
92 read_state.update(cx, |state, cx| {
93 if unread {
94 state.mark_chat_read(&read_id, cx);
95 } else {
96 state.mark_chat_unread(&read_id, cx);
97 }
98 });
99 }),
100 );
101 let current = target.folder_id.clone();
102 let folders: Vec<(String, String)> = context
103 .folders
104 .iter()
105 .filter(|(folder_id, _)| current.as_ref() != Some(folder_id))
106 .cloned()
107 .collect();
108 if !folders.is_empty() {
109 let move_state = context.state.clone();
110 let move_id = target.id.clone();
111 popup = popup.submenu_with_icon(
112 Some(menu_icon(IconName::Folder)),
113 "Move to section",
114 window,
115 cx,
116 move |submenu, _, _| {
117 folders.iter().fold(submenu, |submenu, (folder_id, name)| {
118 let (state, chat_id, folder_id) =
119 (move_state.clone(), move_id.clone(), folder_id.clone());
120 submenu.item(PopupMenuItem::new(name.clone()).on_click(move |_, _, cx| {
121 state.update(cx, |state, cx| {
122 state.move_chat(&chat_id, Some(&folder_id), cx)
123 });
124 }))
125 })
126 },
127 );
128 }
129 if current.is_some() {
130 let remove_state = context.state.clone();
131 let remove_id = target.id.clone();
132 popup = popup.item(
133 PopupMenuItem::new("Remove from section")
134 .icon(menu_icon(IconName::FolderMinus))
135 .on_click(move |_, _, cx| {
136 remove_state.update(cx, |state, cx| state.move_chat(&remove_id, None, cx));
137 }),
138 );
139 }
140 let hide_item = PopupMenuItem::new("Hide")
141 .icon(menu_icon(IconName::EyeOff))
142 .on_click(move |_, _, cx| {
143 hide_state.update(cx, |state, cx| state.hide_chat(&hide_id, cx));
144 });
145 if notes {
146 return popup
147 .item(pop_out_item(context, target))
148 .separator()
149 .item(hide_item);
150 }
151 popup = popup.item(
152 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
153 .icon(menu_icon(if muted {
154 IconName::Bell
155 } else {
156 IconName::BellOff
157 }))
158 .on_click(move |_, _, cx| {
159 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
160 }),
161 );
162 popup = chat_notifications_submenu(popup, window, cx, context, target);
163 let partner = (!target.is_group)
164 .then(|| context.state.read(cx).one_on_one_partner(&target.id))
165 .flatten();
166 if let Some(partner) = partner {
167 let follow_state = context.state.clone();
168 let follow = !context.state.read(cx).is_presence_followed(&partner.user_id);
169 popup = popup.item(
170 PopupMenuItem::new(if follow {
171 NOTIFY_WHEN_AVAILABLE
172 } else {
173 TURN_OFF_NOTIFICATIONS
174 })
175 .icon(menu_icon(if follow {
176 IconName::BellRing
177 } else {
178 IconName::BellOff
179 }))
180 .on_click(move |_, _, cx| {
181 follow_state.update(cx, |state, cx| {
182 state.set_presence_followed(&partner.user_id, &partner.name, follow, cx)
183 });
184 }),
185 );
186 }
187 let (link_state, link_id) = (context.state.clone(), target.id.clone());
188 popup = popup
189 .item(
190 PopupMenuItem::new("Copy link")
191 .icon(menu_icon(IconName::Link))
192 .on_click(move |_, _, cx| {
193 cx.write_to_clipboard(ClipboardItem::new_string(chat_link(&link_id)));
194 link_state.update(cx, |state, cx| {
195 state.raise_notice("Link copied".to_owned(), None, cx)
196 });
197 }),
198 )
199 .item(pop_out_item(context, target))
200 .separator()
201 .item(hide_item);
202 if !target.is_group {
203 let remove_state = context.state.clone();
204 let remove_id = target.id.clone();
205 popup = popup.item(
206 PopupMenuItem::new(REMOVE_HISTORY_LABEL)
207 .icon(menu_icon(IconName::Trash))
208 .on_click(move |_, window, cx| {
209 confirm_remove_history(&remove_state, &remove_id, window, cx);
210 }),
211 );
212 }
213 if target.is_group {
214 let leave_state = context.state.clone();
215 let leave_id = target.id.clone();
216 let title = target.title.clone();
217 let member_count = target.member_count;
218 popup = popup.item(
219 PopupMenuItem::element(|_, _| {
220 div().text_color(theme::red_soft()).child("Leave chat...")
221 })
222 .icon(menu_icon(IconName::LogOut).text_color(theme::red_soft()))
223 .on_click(move |_, window, cx| {
224 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
225 }),
226 );
227 }
228 popup
229 }
230
231 fn pop_out_item(context: &MenuContext, target: &ChatMenuTarget) -> PopupMenuItem {
232 let (state, chat_id) = (context.state.clone(), target.id.clone());
233 PopupMenuItem::new(chat_pop_out::POP_OUT_CHAT_LABEL)
234 .icon(menu_icon(IconName::ExternalLink))
235 .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&state, &chat_id, cx))
236 }
237
238 const CHAT_NOTIFICATION_MODES: [(&str, ChatNotificationMode); 2] = [
239 ("All new messages", ChatNotificationMode::AllNewMessages),
240 ("Mute", ChatNotificationMode::Mute),
241 ];
242
243 const DESKTOP_NOTIFICATIONS: [(&str, DesktopNotifications); 2] = [
244 (
245 "Match settings used for all chats",
246 DesktopNotifications::MatchAllChats,
247 ),
248 ("Don't get desktop notifications", DesktopNotifications::Off),
249 ];
250
251 fn chat_notifications_submenu(
252 popup: PopupMenu,
253 window: &mut Window,
254 cx: &mut Context<PopupMenu>,
255 context: &MenuContext,
256 target: &ChatMenuTarget,
257 ) -> PopupMenu {
258 let state = context.state.clone();
259 let chat_id = target.id.clone();
260 let mode = if target.muted {
261 ChatNotificationMode::Mute
262 } else {
263 ChatNotificationMode::AllNewMessages
264 };
265 let desktop = state.read(cx).chat_desktop_notifications(&chat_id);
266 popup.submenu_with_icon(
267 Some(menu_icon(IconName::Bell)),
268 "Manage notifications",
269 window,
270 cx,
271 move |submenu, _, _| {
272 let choose = |chosen_mode: ChatNotificationMode,
273 chosen_desktop: DesktopNotifications| {
274 let (state, chat_id) = (state.clone(), chat_id.clone());
275 move |_: &ClickEvent, _: &mut Window, cx: &mut App| {
276 state.update(cx, |state, cx| {
277 state.set_chat_notifications(&chat_id, chosen_mode, chosen_desktop, cx)
278 });
279 }
280 };
281 let submenu = submenu.label("Chat notification mode");
282 let submenu =
283 CHAT_NOTIFICATION_MODES
284 .iter()
285 .fold(submenu, |submenu, (label, value)| {
286 submenu.item(
287 PopupMenuItem::new(*label)
288 .checked(*value == mode)
289 .on_click(choose(*value, desktop)),
290 )
291 });
292 let submenu = submenu
293 .separator()
294 .label("Set a desktop notification preference");
295 DESKTOP_NOTIFICATIONS
296 .iter()
297 .fold(submenu, |submenu, (label, value)| {
298 submenu.item(
299 PopupMenuItem::new(*label)
300 .checked(*value == desktop)
301 .on_click(choose(mode, *value)),
302 )
303 })
304 },
305 )
306 }
307
308 pub(crate) fn leave_description(member_count: usize) -> String {
309 let who = match member_count {
310 0 | 1 => "The other members".to_owned(),
311 2 => "The other member".to_owned(),
312 count => format!("The {} other members", count - 1),
313 };
314 let verb = if member_count == 2 { "sees" } else { "see" };
315 format!("{who} {verb} that you left. You can only come back if someone adds you.")
316 }
317
318 const REMOVE_HISTORY_LABEL: &str = "Remove chat history";
319 const REMOVE_HISTORY_TITLE: &str = "Remove chat history?";
320 const REMOVE_HISTORY_TEXT: &str =
321 "This will remove the chat from your list and search. It affects you only.";
322
323 fn confirm_remove_history(
324 state: &Entity<AppState>,
325 chat_id: &str,
326 window: &mut Window,
327 cx: &mut App,
328 ) {
329 let state = state.clone();
330 let chat_id = chat_id.to_owned();
331 window.open_alert_dialog(cx, move |alert, _, _| {
332 let state = state.clone();
333 let chat_id = chat_id.clone();
334 let cancel = Button::new("remove-history-cancel")
335 .label("Cancel")
336 .on_click(|_, window, cx| window.close_dialog(cx));
337 let remove = Button::new("remove-history-confirm")
338 .label("Remove")
339 .primary()
340 .on_click(move |_, window, cx| {
341 state.update(cx, |state, cx| state.remove_chat_history(&chat_id, cx));
342 window.close_dialog(cx);
343 });
344 alert
345 .title(REMOVE_HISTORY_TITLE)
346 .description(REMOVE_HISTORY_TEXT)
347 .footer(DialogFooter::new().child(cancel).child(remove))
348 .on_ok(|_, _, _| false)
349 });
350 }
351
352 pub(crate) fn confirm_leave(
353 state: &Entity<AppState>,
354 chat_id: &str,
355 title: &str,
356 member_count: usize,
357 window: &mut Window,
358 cx: &mut App,
359 ) {
360 let state = state.clone();
361 let chat_id = chat_id.to_owned();
362 let heading = format!("Leave \"{}\"?", truncated(title, TITLE_LIMIT));
363 let description = leave_description(member_count);
364 window.open_alert_dialog(cx, move |alert, _, _| {
365 let state = state.clone();
366 let chat_id = chat_id.clone();
367 let cancel = Button::new("leave-cancel")
368 .label("Cancel")
369 .on_click(|_, window, cx| window.close_dialog(cx));
370 let leave = Button::new("leave-confirm")
371 .label("Leave")
372 .danger()
373 .on_click(move |_, window, cx| {
374 state.update(cx, |state, cx| state.leave_chat(&chat_id, cx));
375 window.close_dialog(cx);
376 });
377 alert
378 .title(heading.clone())
379 .description(description.clone())
380 .footer(DialogFooter::new().child(cancel).child(leave))
381 .on_ok(|_, _, _| false)
382 });
383 }
384
385 #[cfg(test)]
386 mod tests {
387 use super::leave_description;
388
389 #[test]
390 fn leave_text_counts_the_other_members() {
391 assert_eq!(
392 leave_description(4),
393 "The 3 other members see that you left. You can only come back if someone adds you."
394 );
395 assert!(leave_description(2).starts_with("The other member sees"));
396 assert!(leave_description(0).starts_with("The other members see"));
397 }
398 }
@@ -0,0 +1,398 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::button::{Button, ButtonVariants as _};
3use gpui_kit::component::dialog::DialogFooter;
4use gpui_kit::component::menu::{PopupMenu, PopupMenuItem};
5use gpui_kit::component::WindowExt as _;
6use gpui_kit::*;
7use teams_core::{ChatNotificationMode, DesktopNotifications, chat_link, is_notes_chat};
8
9use super::chat_pop_out;
10use super::widgets::menu_icon;
11use crate::app_state::{AppState, chat_title};
12use crate::chat_actions::TITLE_LIMIT;
13use crate::notice::truncated;
14use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
15use crate::theme;
16
17const GROUP_KIND: &str = "group";
18
19#[derive(Clone)]
20pub(crate) struct ChatMenuTarget {
21 pub id: String,
22 pub title: String,
23 pub folder_id: Option<String>,
24 pub unread: bool,
25 pub muted: bool,
26 pub is_group: bool,
27 pub member_count: usize,
28}
29
30impl ChatMenuTarget {
31 pub(crate) fn for_chat(state: &AppState, chat_id: &str) -> Option<Self> {
32 let chat = state.sidebar.chats.iter().find(|chat| chat.id == chat_id)?;
33 Some(ChatMenuTarget {
34 id: chat.id.clone(),
35 title: chat_title(chat),
36 folder_id: state
37 .directory
38 .folder_of(chat_id)
39 .map(|folder| folder.id.clone()),
40 unread: chat.unread,
41 muted: chat.muted,
42 is_group: chat.kind == GROUP_KIND,
43 member_count: chat.members.len(),
44 })
45 }
46}
47
48#[derive(Clone)]
49pub(crate) struct MenuContext {
50 pub state: Entity<AppState>,
51 pub folders: Vec<(String, String)>,
52}
53
54impl MenuContext {
55 pub(crate) fn new(state: &Entity<AppState>, cx: &App) -> Self {
56 MenuContext {
57 state: state.clone(),
58 folders: state.read(cx).directory.move_targets(),
59 }
60 }
61}
62
63pub(crate) fn chat_menu(
64 popup: PopupMenu,
65 window: &mut Window,
66 cx: &mut Context<PopupMenu>,
67 context: &MenuContext,
68 target: &ChatMenuTarget,
69) -> PopupMenu {
70 let mut popup = popup;
71 let read_state = context.state.clone();
72 let read_id = target.id.clone();
73 let unread = target.unread;
74 let mute_state = context.state.clone();
75 let mute_id = target.id.clone();
76 let muted = target.muted;
77 let hide_state = context.state.clone();
78 let hide_id = target.id.clone();
79 let notes = is_notes_chat(&target.id);
80 popup = popup.item(
81 PopupMenuItem::new(if unread {
82 "Mark as read"
83 } else {
84 "Mark as unread"
85 })
86 .icon(menu_icon(if unread {
87 IconName::MailOpen
88 } else {
89 IconName::Mail
90 }))
91 .on_click(move |_, _, cx| {
92 read_state.update(cx, |state, cx| {
93 if unread {
94 state.mark_chat_read(&read_id, cx);
95 } else {
96 state.mark_chat_unread(&read_id, cx);
97 }
98 });
99 }),
100 );
101 let current = target.folder_id.clone();
102 let folders: Vec<(String, String)> = context
103 .folders
104 .iter()
105 .filter(|(folder_id, _)| current.as_ref() != Some(folder_id))
106 .cloned()
107 .collect();
108 if !folders.is_empty() {
109 let move_state = context.state.clone();
110 let move_id = target.id.clone();
111 popup = popup.submenu_with_icon(
112 Some(menu_icon(IconName::Folder)),
113 "Move to section",
114 window,
115 cx,
116 move |submenu, _, _| {
117 folders.iter().fold(submenu, |submenu, (folder_id, name)| {
118 let (state, chat_id, folder_id) =
119 (move_state.clone(), move_id.clone(), folder_id.clone());
120 submenu.item(PopupMenuItem::new(name.clone()).on_click(move |_, _, cx| {
121 state.update(cx, |state, cx| {
122 state.move_chat(&chat_id, Some(&folder_id), cx)
123 });
124 }))
125 })
126 },
127 );
128 }
129 if current.is_some() {
130 let remove_state = context.state.clone();
131 let remove_id = target.id.clone();
132 popup = popup.item(
133 PopupMenuItem::new("Remove from section")
134 .icon(menu_icon(IconName::FolderMinus))
135 .on_click(move |_, _, cx| {
136 remove_state.update(cx, |state, cx| state.move_chat(&remove_id, None, cx));
137 }),
138 );
139 }
140 let hide_item = PopupMenuItem::new("Hide")
141 .icon(menu_icon(IconName::EyeOff))
142 .on_click(move |_, _, cx| {
143 hide_state.update(cx, |state, cx| state.hide_chat(&hide_id, cx));
144 });
145 if notes {
146 return popup
147 .item(pop_out_item(context, target))
148 .separator()
149 .item(hide_item);
150 }
151 popup = popup.item(
152 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
153 .icon(menu_icon(if muted {
154 IconName::Bell
155 } else {
156 IconName::BellOff
157 }))
158 .on_click(move |_, _, cx| {
159 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
160 }),
161 );
162 popup = chat_notifications_submenu(popup, window, cx, context, target);
163 let partner = (!target.is_group)
164 .then(|| context.state.read(cx).one_on_one_partner(&target.id))
165 .flatten();
166 if let Some(partner) = partner {
167 let follow_state = context.state.clone();
168 let follow = !context.state.read(cx).is_presence_followed(&partner.user_id);
169 popup = popup.item(
170 PopupMenuItem::new(if follow {
171 NOTIFY_WHEN_AVAILABLE
172 } else {
173 TURN_OFF_NOTIFICATIONS
174 })
175 .icon(menu_icon(if follow {
176 IconName::BellRing
177 } else {
178 IconName::BellOff
179 }))
180 .on_click(move |_, _, cx| {
181 follow_state.update(cx, |state, cx| {
182 state.set_presence_followed(&partner.user_id, &partner.name, follow, cx)
183 });
184 }),
185 );
186 }
187 let (link_state, link_id) = (context.state.clone(), target.id.clone());
188 popup = popup
189 .item(
190 PopupMenuItem::new("Copy link")
191 .icon(menu_icon(IconName::Link))
192 .on_click(move |_, _, cx| {
193 cx.write_to_clipboard(ClipboardItem::new_string(chat_link(&link_id)));
194 link_state.update(cx, |state, cx| {
195 state.raise_notice("Link copied".to_owned(), None, cx)
196 });
197 }),
198 )
199 .item(pop_out_item(context, target))
200 .separator()
201 .item(hide_item);
202 if !target.is_group {
203 let remove_state = context.state.clone();
204 let remove_id = target.id.clone();
205 popup = popup.item(
206 PopupMenuItem::new(REMOVE_HISTORY_LABEL)
207 .icon(menu_icon(IconName::Trash))
208 .on_click(move |_, window, cx| {
209 confirm_remove_history(&remove_state, &remove_id, window, cx);
210 }),
211 );
212 }
213 if target.is_group {
214 let leave_state = context.state.clone();
215 let leave_id = target.id.clone();
216 let title = target.title.clone();
217 let member_count = target.member_count;
218 popup = popup.item(
219 PopupMenuItem::element(|_, _| {
220 div().text_color(theme::red_soft()).child("Leave chat...")
221 })
222 .icon(menu_icon(IconName::LogOut).text_color(theme::red_soft()))
223 .on_click(move |_, window, cx| {
224 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
225 }),
226 );
227 }
228 popup
229}
230
231fn pop_out_item(context: &MenuContext, target: &ChatMenuTarget) -> PopupMenuItem {
232 let (state, chat_id) = (context.state.clone(), target.id.clone());
233 PopupMenuItem::new(chat_pop_out::POP_OUT_CHAT_LABEL)
234 .icon(menu_icon(IconName::ExternalLink))
235 .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&state, &chat_id, cx))
236}
237
238const CHAT_NOTIFICATION_MODES: [(&str, ChatNotificationMode); 2] = [
239 ("All new messages", ChatNotificationMode::AllNewMessages),
240 ("Mute", ChatNotificationMode::Mute),
241];
242
243const DESKTOP_NOTIFICATIONS: [(&str, DesktopNotifications); 2] = [
244 (
245 "Match settings used for all chats",
246 DesktopNotifications::MatchAllChats,
247 ),
248 ("Don't get desktop notifications", DesktopNotifications::Off),
249];
250
251fn chat_notifications_submenu(
252 popup: PopupMenu,
253 window: &mut Window,
254 cx: &mut Context<PopupMenu>,
255 context: &MenuContext,
256 target: &ChatMenuTarget,
257) -> PopupMenu {
258 let state = context.state.clone();
259 let chat_id = target.id.clone();
260 let mode = if target.muted {
261 ChatNotificationMode::Mute
262 } else {
263 ChatNotificationMode::AllNewMessages
264 };
265 let desktop = state.read(cx).chat_desktop_notifications(&chat_id);
266 popup.submenu_with_icon(
267 Some(menu_icon(IconName::Bell)),
268 "Manage notifications",
269 window,
270 cx,
271 move |submenu, _, _| {
272 let choose = |chosen_mode: ChatNotificationMode,
273 chosen_desktop: DesktopNotifications| {
274 let (state, chat_id) = (state.clone(), chat_id.clone());
275 move |_: &ClickEvent, _: &mut Window, cx: &mut App| {
276 state.update(cx, |state, cx| {
277 state.set_chat_notifications(&chat_id, chosen_mode, chosen_desktop, cx)
278 });
279 }
280 };
281 let submenu = submenu.label("Chat notification mode");
282 let submenu =
283 CHAT_NOTIFICATION_MODES
284 .iter()
285 .fold(submenu, |submenu, (label, value)| {
286 submenu.item(
287 PopupMenuItem::new(*label)
288 .checked(*value == mode)
289 .on_click(choose(*value, desktop)),
290 )
291 });
292 let submenu = submenu
293 .separator()
294 .label("Set a desktop notification preference");
295 DESKTOP_NOTIFICATIONS
296 .iter()
297 .fold(submenu, |submenu, (label, value)| {
298 submenu.item(
299 PopupMenuItem::new(*label)
300 .checked(*value == desktop)
301 .on_click(choose(mode, *value)),
302 )
303 })
304 },
305 )
306}
307
308pub(crate) fn leave_description(member_count: usize) -> String {
309 let who = match member_count {
310 0 | 1 => "The other members".to_owned(),
311 2 => "The other member".to_owned(),
312 count => format!("The {} other members", count - 1),
313 };
314 let verb = if member_count == 2 { "sees" } else { "see" };
315 format!("{who} {verb} that you left. You can only come back if someone adds you.")
316}
317
318const REMOVE_HISTORY_LABEL: &str = "Remove chat history";
319const REMOVE_HISTORY_TITLE: &str = "Remove chat history?";
320const REMOVE_HISTORY_TEXT: &str =
321 "This will remove the chat from your list and search. It affects you only.";
322
323fn confirm_remove_history(
324 state: &Entity<AppState>,
325 chat_id: &str,
326 window: &mut Window,
327 cx: &mut App,
328) {
329 let state = state.clone();
330 let chat_id = chat_id.to_owned();
331 window.open_alert_dialog(cx, move |alert, _, _| {
332 let state = state.clone();
333 let chat_id = chat_id.clone();
334 let cancel = Button::new("remove-history-cancel")
335 .label("Cancel")
336 .on_click(|_, window, cx| window.close_dialog(cx));
337 let remove = Button::new("remove-history-confirm")
338 .label("Remove")
339 .primary()
340 .on_click(move |_, window, cx| {
341 state.update(cx, |state, cx| state.remove_chat_history(&chat_id, cx));
342 window.close_dialog(cx);
343 });
344 alert
345 .title(REMOVE_HISTORY_TITLE)
346 .description(REMOVE_HISTORY_TEXT)
347 .footer(DialogFooter::new().child(cancel).child(remove))
348 .on_ok(|_, _, _| false)
349 });
350}
351
352pub(crate) fn confirm_leave(
353 state: &Entity<AppState>,
354 chat_id: &str,
355 title: &str,
356 member_count: usize,
357 window: &mut Window,
358 cx: &mut App,
359) {
360 let state = state.clone();
361 let chat_id = chat_id.to_owned();
362 let heading = format!("Leave \"{}\"?", truncated(title, TITLE_LIMIT));
363 let description = leave_description(member_count);
364 window.open_alert_dialog(cx, move |alert, _, _| {
365 let state = state.clone();
366 let chat_id = chat_id.clone();
367 let cancel = Button::new("leave-cancel")
368 .label("Cancel")
369 .on_click(|_, window, cx| window.close_dialog(cx));
370 let leave = Button::new("leave-confirm")
371 .label("Leave")
372 .danger()
373 .on_click(move |_, window, cx| {
374 state.update(cx, |state, cx| state.leave_chat(&chat_id, cx));
375 window.close_dialog(cx);
376 });
377 alert
378 .title(heading.clone())
379 .description(description.clone())
380 .footer(DialogFooter::new().child(cancel).child(leave))
381 .on_ok(|_, _, _| false)
382 });
383}
384
385#[cfg(test)]
386mod tests {
387 use super::leave_description;
388
389 #[test]
390 fn leave_text_counts_the_other_members() {
391 assert_eq!(
392 leave_description(4),
393 "The 3 other members see that you left. You can only come back if someone adds you."
394 );
395 assert!(leave_description(2).starts_with("The other member sees"));
396 assert!(leave_description(0).starts_with("The other members see"));
397 }
398}
crates/app/src/views/composer/plus_menu.rs +23 −23
@@ -8,6 +8,7 @@ use gpui_kit::prelude::FluentBuilder as _;
8 8 use gpui_kit::*;
9 9
10 10 use super::{COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer};
11 use crate::app_state::AppState;
11 12 use crate::delivery_options::DELIVERY_BUTTON_TITLE;
12 13 use crate::theme::{self, ElevatedSurface as _};
13 14 use crate::views::new_chat::Pick;
@@ -171,34 +172,33 @@ impl Composer {
171 172 PlusAction::ScheduleMessage => self.open_schedule_picker(cx),
172 173 PlusAction::DeliveryOptions => self.delivery_menu = true,
173 174 PlusAction::ScheduleMeeting => {
174 let invitees = self.meeting_invitees(cx);
175 let invitees = self
176 .conversation_id
177 .as_deref()
178 .map(|chat_id| chat_invitees(self.app.read(cx), chat_id))
179 .unwrap_or_default();
175 180 open_new_meeting_with(self.app.clone(), invitees, window, cx);
176 181 }
177 182 }
178 183 cx.notify();
179 184 }
185 }
180 186
181 fn meeting_invitees(&self, cx: &App) -> Vec<Pick> {
182 let state = self.app.read(cx);
183 let me = state.directory.me.as_ref().map(|me| me.user_id.as_str());
184 let Some(chat) = self
185 .conversation_id
186 .as_deref()
187 .and_then(|id| state.sidebar.chats.iter().find(|chat| chat.id == id))
188 else {
189 return Vec::new();
190 };
191 chat.members
192 .iter()
193 .filter(|member| !member.is_bot())
194 .filter_map(|member| {
195 let user_id = member.user_id.clone()?;
196 (Some(user_id.as_str()) != me).then(|| Pick {
197 user_id,
198 name: member.display_name.clone(),
199 mail: None,
200 })
187 pub(crate) fn chat_invitees(state: &AppState, chat_id: &str) -> Vec<Pick> {
188 let me = state.directory.me.as_ref().map(|me| me.user_id.as_str());
189 let Some(chat) = state.sidebar.chats.iter().find(|chat| chat.id == chat_id) else {
190 return Vec::new();
191 };
192 chat.members
193 .iter()
194 .filter(|member| !member.is_bot())
195 .filter_map(|member| {
196 let user_id = member.user_id.clone()?;
197 (Some(user_id.as_str()) != me).then(|| Pick {
198 user_id,
199 name: member.display_name.clone(),
200 mail: None,
201 201 })
202 .collect()
203 }
202 })
203 .collect()
204 204 }
@@ -8,6 +8,7 @@ use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
8use gpui_kit::*;
9
9
10use super::{COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer};
10use super::{COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer};
11use crate::app_state::AppState;
11use crate::delivery_options::DELIVERY_BUTTON_TITLE;
12use crate::delivery_options::DELIVERY_BUTTON_TITLE;
12use crate::theme::{self, ElevatedSurface as _};
13use crate::theme::{self, ElevatedSurface as _};
13use crate::views::new_chat::Pick;
14use crate::views::new_chat::Pick;
@@ -171,34 +172,33 @@ impl Composer {
171 PlusAction::ScheduleMessage => self.open_schedule_picker(cx),
172 PlusAction::ScheduleMessage => self.open_schedule_picker(cx),
172 PlusAction::DeliveryOptions => self.delivery_menu = true,
173 PlusAction::DeliveryOptions => self.delivery_menu = true,
173 PlusAction::ScheduleMeeting => {
174 PlusAction::ScheduleMeeting => {
174 let invitees = self.meeting_invitees(cx);
175 let invitees = self
176 .conversation_id
177 .as_deref()
178 .map(|chat_id| chat_invitees(self.app.read(cx), chat_id))
179 .unwrap_or_default();
175 open_new_meeting_with(self.app.clone(), invitees, window, cx);
180 open_new_meeting_with(self.app.clone(), invitees, window, cx);
176 }
181 }
177 }
182 }
178 cx.notify();
183 cx.notify();
179 }
184 }
185}
180
186
181 fn meeting_invitees(&self, cx: &App) -> Vec<Pick> {
187pub(crate) fn chat_invitees(state: &AppState, chat_id: &str) -> Vec<Pick> {
182 let state = self.app.read(cx);
188 let me = state.directory.me.as_ref().map(|me| me.user_id.as_str());
183 let me = state.directory.me.as_ref().map(|me| me.user_id.as_str());
189 let Some(chat) = state.sidebar.chats.iter().find(|chat| chat.id == chat_id) else {
184 let Some(chat) = self
190 return Vec::new();
185 .conversation_id
191 };
186 .as_deref()
192 chat.members
187 .and_then(|id| state.sidebar.chats.iter().find(|chat| chat.id == id))
193 .iter()
188 else {
194 .filter(|member| !member.is_bot())
189 return Vec::new();
195 .filter_map(|member| {
190 };
196 let user_id = member.user_id.clone()?;
191 chat.members
197 (Some(user_id.as_str()) != me).then(|| Pick {
192 .iter()
198 user_id,
193 .filter(|member| !member.is_bot())
199 name: member.display_name.clone(),
194 .filter_map(|member| {
200 mail: None,
195 let user_id = member.user_id.clone()?;
196 (Some(user_id.as_str()) != me).then(|| Pick {
197 user_id,
198 name: member.display_name.clone(),
199 mail: None,
200 })
201 })
201 })
202 .collect()
202 })
203 }
203 .collect()
204}
204}
crates/app/src/views/composer/slash.rs +1 −1
@@ -11,7 +11,7 @@ use super::Composer;
11 11 use crate::theme::{self, ElevatedSurface as _};
12 12 use crate::views::actions::OpenSwitcher;
13 13 use crate::views::shortcuts::{OpenSettings, ShowShortcuts};
14 use crate::views::sidebar::confirm_leave;
14 use crate::views::chat_menu::confirm_leave;
15 15
16 16 const GROUP_KIND: &str = "group";
17 17 const WIDTH: f32 = 380.;
@@ -11,7 +11,7 @@ use super::Composer;
11use crate::theme::{self, ElevatedSurface as _};
11use crate::theme::{self, ElevatedSurface as _};
12use crate::views::actions::OpenSwitcher;
12use crate::views::actions::OpenSwitcher;
13use crate::views::shortcuts::{OpenSettings, ShowShortcuts};
13use crate::views::shortcuts::{OpenSettings, ShowShortcuts};
14use crate::views::sidebar::confirm_leave;
14use crate::views::chat_menu::confirm_leave;
15
15
16const GROUP_KIND: &str = "group";
16const GROUP_KIND: &str = "group";
17const WIDTH: f32 = 380.;
17const WIDTH: f32 = 380.;
crates/app/src/views/conversation.rs +14 −1
@@ -3757,6 +3757,8 @@ impl ConversationView {
3757 3757 .to_owned();
3758 3758 }
3759 3759 let inline_tabs = tabs.map(|tabs| h_flex().h_full().flex_1().child(tabs));
3760 let divided = matches!(current.selection, Selection::Chat(_))
3761 && (!call_controls.is_empty() || stack.is_some());
3760 3762 header
3761 3763 .relative()
3762 3764 .child(record_width(&self.header_width))
@@ -3803,11 +3805,12 @@ impl ConversationView {
3803 3805 .children(inline_tabs)
3804 3806 .children(call_controls)
3805 3807 .children(stack)
3808 .when(divided, |header| header.child(header_divider()))
3806 3809 .children(self.copilot_button(cx))
3807 3810 .children(self.chat_find_button(cx))
3808 3811 .children(self.channel_find_button(cx))
3809 3812 .children(self.channel_details_button(cx))
3810 .children(self.pop_out_button())
3813 .children(self.chat_more_button(cx))
3811 3814 .children(self.pop_in_button(current))
3812 3815 }
3813 3816
@@ -3835,6 +3838,16 @@ impl ConversationView {
3835 3838 }
3836 3839
3837 3840 const GROUP_KIND: &str = "group";
3841 const HEADER_DIVIDER_HEIGHT: f32 = 20.;
3842
3843 fn header_divider() -> Div {
3844 div()
3845 .w(px(1.))
3846 .h(px(HEADER_DIVIDER_HEIGHT))
3847 .mx(px(4.))
3848 .flex_none()
3849 .bg(theme::border())
3850 }
3838 3851
3839 3852 impl Render for ConversationView {
3840 3853 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3757,6 +3757,8 @@ impl ConversationView {
3757 .to_owned();
3757 .to_owned();
3758 }
3758 }
3759 let inline_tabs = tabs.map(|tabs| h_flex().h_full().flex_1().child(tabs));
3759 let inline_tabs = tabs.map(|tabs| h_flex().h_full().flex_1().child(tabs));
3760 let divided = matches!(current.selection, Selection::Chat(_))
3761 && (!call_controls.is_empty() || stack.is_some());
3760 header
3762 header
3761 .relative()
3763 .relative()
3762 .child(record_width(&self.header_width))
3764 .child(record_width(&self.header_width))
@@ -3803,11 +3805,12 @@ impl ConversationView {
3803 .children(inline_tabs)
3805 .children(inline_tabs)
3804 .children(call_controls)
3806 .children(call_controls)
3805 .children(stack)
3807 .children(stack)
3808 .when(divided, |header| header.child(header_divider()))
3806 .children(self.copilot_button(cx))
3809 .children(self.copilot_button(cx))
3807 .children(self.chat_find_button(cx))
3810 .children(self.chat_find_button(cx))
3808 .children(self.channel_find_button(cx))
3811 .children(self.channel_find_button(cx))
3809 .children(self.channel_details_button(cx))
3812 .children(self.channel_details_button(cx))
3810 .children(self.pop_out_button())
3813 .children(self.chat_more_button(cx))
3811 .children(self.pop_in_button(current))
3814 .children(self.pop_in_button(current))
3812 }
3815 }
3813
3816
@@ -3835,6 +3838,16 @@ impl ConversationView {
3835}
3838}
3836
3839
3837const GROUP_KIND: &str = "group";
3840const GROUP_KIND: &str = "group";
3841const HEADER_DIVIDER_HEIGHT: f32 = 20.;
3842
3843fn header_divider() -> Div {
3844 div()
3845 .w(px(1.))
3846 .h(px(HEADER_DIVIDER_HEIGHT))
3847 .mx(px(4.))
3848 .flex_none()
3849 .bg(theme::border())
3850}
3838
3851
3839impl Render for ConversationView {
3852impl Render for ConversationView {
3840 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
3853 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
crates/app/src/views/conversation/channel_details.rs +36 −9
@@ -26,6 +26,9 @@ pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details
26 26 const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";
27 27 const OPEN_LABEL: &str = "Open channel details";
28 28 const CLOSE_LABEL: &str = "Close channel details";
29 const OPEN_CHAT_LABEL: &str = "Open chat details";
30 const CLOSE_CHAT_LABEL: &str = "Close chat details";
31 const CHAT_DETAILS_TITLE: &str = "In this chat";
29 32 const PINNED_TITLE: &str = "Pinned";
30 33 const SHARED_TITLE: &str = "Shared";
31 34 const SEE_ALL_SHARED_ARIA: &str = "See all shared files";
@@ -129,6 +132,24 @@ impl ConversationView {
129 132 }
130 133 }
131 134
135 fn details_conversation_id(&self) -> Option<String> {
136 match &self.current.as_ref()?.selection {
137 Selection::Channel(channel_id) => Some(channel_id.clone()),
138 Selection::Chat(chat_id) if !self.draft_active && !self.pinned => {
139 Some(chat_id.clone())
140 }
141 Selection::Chat(_) => None,
142 }
143 }
144
145 fn details_labels(&self) -> (&'static str, &'static str) {
146 if self.details_channel_id().is_some() {
147 (OPEN_LABEL, CLOSE_LABEL)
148 } else {
149 (OPEN_CHAT_LABEL, CLOSE_CHAT_LABEL)
150 }
151 }
152
132 153 pub(super) fn channel_find_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
133 154 self.details_channel_id()?;
134 155 Some(
@@ -144,8 +165,9 @@ impl ConversationView {
144 165 }
145 166
146 167 pub(super) fn channel_details_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
147 self.details_channel_id()?;
168 self.details_conversation_id()?;
148 169 let open = self.channel_details_open;
170 let (open_label, close_label) = self.details_labels();
149 171 Some(
150 172 Button::new("channel-details-toggle")
151 173 .debug_selector(|| CHANNEL_DETAILS_BUTTON.into())
@@ -157,7 +179,7 @@ impl ConversationView {
157 179 .ghost()
158 180 .size(px(BUTTON_SIZE))
159 181 .rounded(px(8.))
160 .tooltip(if open { CLOSE_LABEL } else { OPEN_LABEL })
182 .tooltip(if open { close_label } else { open_label })
161 183 .on_click(cx.listener(|this, _, _, cx| {
162 184 this.channel_details_open = !this.channel_details_open;
163 185 this.pinned_posts_expanded = false;
@@ -176,7 +198,9 @@ impl ConversationView {
176 198 if !self.channel_details_open {
177 199 return None;
178 200 }
179 let channel_id = self.details_channel_id()?;
201 let channel_id = self.details_conversation_id()?;
202 let (_, close_label) = self.details_labels();
203 let is_chat = self.details_channel_id().is_none();
180 204 let state = self.app.read(cx);
181 205 let ids: Vec<String> = state
182 206 .pinned_messages(&channel_id)
@@ -194,11 +218,14 @@ impl ConversationView {
194 218 let expanded = self.pinned_posts_expanded;
195 219 let shown = shown_pin_count(items.len(), expanded);
196 220 let has_more = items.len() > shown;
197 let title = self
198 .current
199 .as_ref()
200 .map(|current| current.title.clone())
201 .unwrap_or_default();
221 let title = if is_chat {
222 CHAT_DETAILS_TITLE.to_owned()
223 } else {
224 self.current
225 .as_ref()
226 .map(|current| current.title.clone())
227 .unwrap_or_default()
228 };
202 229 let directory = &state.directory;
203 230 let mut body = v_flex()
204 231 .w_full()
@@ -297,7 +324,7 @@ impl ConversationView {
297 324 .ghost()
298 325 .size(px(BUTTON_SIZE))
299 326 .rounded(px(8.))
300 .tooltip(CLOSE_LABEL)
327 .tooltip(close_label)
301 328 .on_click(cx.listener(|this, _, _, cx| {
302 329 this.channel_details_open = false;
303 330 this.pinned_posts_expanded = false;
@@ -26,6 +26,9 @@ pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details
26const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";
26const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";
27const OPEN_LABEL: &str = "Open channel details";
27const OPEN_LABEL: &str = "Open channel details";
28const CLOSE_LABEL: &str = "Close channel details";
28const CLOSE_LABEL: &str = "Close channel details";
29const OPEN_CHAT_LABEL: &str = "Open chat details";
30const CLOSE_CHAT_LABEL: &str = "Close chat details";
31const CHAT_DETAILS_TITLE: &str = "In this chat";
29const PINNED_TITLE: &str = "Pinned";
32const PINNED_TITLE: &str = "Pinned";
30const SHARED_TITLE: &str = "Shared";
33const SHARED_TITLE: &str = "Shared";
31const SEE_ALL_SHARED_ARIA: &str = "See all shared files";
34const SEE_ALL_SHARED_ARIA: &str = "See all shared files";
@@ -129,6 +132,24 @@ impl ConversationView {
129 }
132 }
130 }
133 }
131
134
135 fn details_conversation_id(&self) -> Option<String> {
136 match &self.current.as_ref()?.selection {
137 Selection::Channel(channel_id) => Some(channel_id.clone()),
138 Selection::Chat(chat_id) if !self.draft_active && !self.pinned => {
139 Some(chat_id.clone())
140 }
141 Selection::Chat(_) => None,
142 }
143 }
144
145 fn details_labels(&self) -> (&'static str, &'static str) {
146 if self.details_channel_id().is_some() {
147 (OPEN_LABEL, CLOSE_LABEL)
148 } else {
149 (OPEN_CHAT_LABEL, CLOSE_CHAT_LABEL)
150 }
151 }
152
132 pub(super) fn channel_find_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
153 pub(super) fn channel_find_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
133 self.details_channel_id()?;
154 self.details_channel_id()?;
134 Some(
155 Some(
@@ -144,8 +165,9 @@ impl ConversationView {
144 }
165 }
145
166
146 pub(super) fn channel_details_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
167 pub(super) fn channel_details_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
147 self.details_channel_id()?;
168 self.details_conversation_id()?;
148 let open = self.channel_details_open;
169 let open = self.channel_details_open;
170 let (open_label, close_label) = self.details_labels();
149 Some(
171 Some(
150 Button::new("channel-details-toggle")
172 Button::new("channel-details-toggle")
151 .debug_selector(|| CHANNEL_DETAILS_BUTTON.into())
173 .debug_selector(|| CHANNEL_DETAILS_BUTTON.into())
@@ -157,7 +179,7 @@ impl ConversationView {
157 .ghost()
179 .ghost()
158 .size(px(BUTTON_SIZE))
180 .size(px(BUTTON_SIZE))
159 .rounded(px(8.))
181 .rounded(px(8.))
160 .tooltip(if open { CLOSE_LABEL } else { OPEN_LABEL })
182 .tooltip(if open { close_label } else { open_label })
161 .on_click(cx.listener(|this, _, _, cx| {
183 .on_click(cx.listener(|this, _, _, cx| {
162 this.channel_details_open = !this.channel_details_open;
184 this.channel_details_open = !this.channel_details_open;
163 this.pinned_posts_expanded = false;
185 this.pinned_posts_expanded = false;
@@ -176,7 +198,9 @@ impl ConversationView {
176 if !self.channel_details_open {
198 if !self.channel_details_open {
177 return None;
199 return None;
178 }
200 }
179 let channel_id = self.details_channel_id()?;
201 let channel_id = self.details_conversation_id()?;
202 let (_, close_label) = self.details_labels();
203 let is_chat = self.details_channel_id().is_none();
180 let state = self.app.read(cx);
204 let state = self.app.read(cx);
181 let ids: Vec<String> = state
205 let ids: Vec<String> = state
182 .pinned_messages(&channel_id)
206 .pinned_messages(&channel_id)
@@ -194,11 +218,14 @@ impl ConversationView {
194 let expanded = self.pinned_posts_expanded;
218 let expanded = self.pinned_posts_expanded;
195 let shown = shown_pin_count(items.len(), expanded);
219 let shown = shown_pin_count(items.len(), expanded);
196 let has_more = items.len() > shown;
220 let has_more = items.len() > shown;
197 let title = self
221 let title = if is_chat {
198 .current
222 CHAT_DETAILS_TITLE.to_owned()
199 .as_ref()
223 } else {
200 .map(|current| current.title.clone())
224 self.current
201 .unwrap_or_default();
225 .as_ref()
226 .map(|current| current.title.clone())
227 .unwrap_or_default()
228 };
202 let directory = &state.directory;
229 let directory = &state.directory;
203 let mut body = v_flex()
230 let mut body = v_flex()
204 .w_full()
231 .w_full()
@@ -297,7 +324,7 @@ impl ConversationView {
297 .ghost()
324 .ghost()
298 .size(px(BUTTON_SIZE))
325 .size(px(BUTTON_SIZE))
299 .rounded(px(8.))
326 .rounded(px(8.))
300 .tooltip(CLOSE_LABEL)
327 .tooltip(close_label)
301 .on_click(cx.listener(|this, _, _, cx| {
328 .on_click(cx.listener(|this, _, _, cx| {
302 this.channel_details_open = false;
329 this.channel_details_open = false;
303 this.pinned_posts_expanded = false;
330 this.pinned_posts_expanded = false;
crates/app/src/views/conversation/chat_header_actions.rs +39 −10
@@ -1,18 +1,25 @@
1 1 use gpui_kit::assets::IconName;
2 2 use gpui_kit::component::button::{Button, ButtonVariants as _};
3 3 use gpui_kit::component::h_flex;
4 use gpui_kit::component::menu::{DropdownMenu as _, PopupMenu, PopupMenuItem};
4 5 use gpui_kit::prelude::FluentBuilder as _;
5 6 use gpui_kit::*;
6 7
8 use teams_core::is_notes_chat;
9
7 10 use super::ConversationView;
8 11 use crate::app_state::Selection;
9 12 use crate::data::Directory;
10 13 use crate::find_in_chat::FIND_IN_CHAT;
11 14 use crate::theme;
12 use crate::views::chat_pop_out::{self, POP_OUT_CHAT_LABEL};
15 use crate::views::chat_menu::{ChatMenuTarget, MenuContext, chat_menu};
16 use crate::views::composer::plus_menu::chat_invitees;
17 use crate::views::new_meeting_dialog::open_new_meeting_with;
13 18 use crate::views::avatar::status_glyph;
14 use crate::views::widgets::{icon, symbol};
19 use crate::views::widgets::{icon, menu_icon, symbol};
15 20
21 pub const CHAT_HEADER_MORE_TAG: &str = "chat-header-more";
22 const SCHEDULE_MEETING_LABEL: &str = "Schedule meeting";
16 23 const BUTTON_SIZE: f32 = 32.;
17 24 const COUNT_GLYPH: f32 = 16.;
18 25
@@ -38,25 +45,47 @@ impl ConversationView {
38 45 )
39 46 }
40 47
41 pub(super) fn pop_out_button(&self) -> Option<AnyElement> {
48 pub(super) fn chat_more_button(&self, cx: &App) -> Option<AnyElement> {
42 49 let chat_id = self
43 50 .header_chat_id()
44 .filter(|_| !self.popped_out && !self.pinned)?
45 .to_owned();
46 let app = self.app.clone();
51 .filter(|_| !self.popped_out && !self.pinned)?;
52 let target = ChatMenuTarget::for_chat(self.app.read(cx), chat_id)?;
53 let context = MenuContext::new(&self.app, cx);
47 54 Some(
48 Button::new("chat-pop-out")
49 .icon(IconName::ExternalLink)
55 Button::new(CHAT_HEADER_MORE_TAG)
56 .icon(IconName::Ellipsis)
50 57 .ghost()
51 58 .size(px(BUTTON_SIZE))
52 59 .rounded(px(8.))
53 .tooltip(POP_OUT_CHAT_LABEL)
54 .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&app, &chat_id, cx))
60 .tooltip("More chat options")
61 .debug_selector(|| CHAT_HEADER_MORE_TAG.into())
62 .dropdown_menu(move |popup, window, cx| {
63 let popup = if is_notes_chat(&target.id) {
64 popup
65 } else {
66 schedule_meeting_item(popup, &context, &target.id)
67 };
68 chat_menu(popup, window, cx, &context, &target)
69 })
55 70 .into_any_element(),
56 71 )
57 72 }
58 73 }
59 74
75 fn schedule_meeting_item(popup: PopupMenu, context: &MenuContext, chat_id: &str) -> PopupMenu {
76 let (state, chat_id) = (context.state.clone(), chat_id.to_owned());
77 popup
78 .item(
79 PopupMenuItem::new(SCHEDULE_MEETING_LABEL)
80 .icon(menu_icon(IconName::Calendar))
81 .on_click(move |_, window, cx| {
82 let invitees = chat_invitees(state.read(cx), &chat_id);
83 open_new_meeting_with(state.clone(), invitees, window, cx);
84 }),
85 )
86 .separator()
87 }
88
60 89 pub fn member_count(count: usize) -> Div {
61 90 h_flex()
62 91 .gap(px(4.))
@@ -1,18 +1,25 @@
1use gpui_kit::assets::IconName;
1use gpui_kit::assets::IconName;
2use gpui_kit::component::button::{Button, ButtonVariants as _};
2use gpui_kit::component::button::{Button, ButtonVariants as _};
3use gpui_kit::component::h_flex;
3use gpui_kit::component::h_flex;
4use gpui_kit::component::menu::{DropdownMenu as _, PopupMenu, PopupMenuItem};
4use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::*;
6use gpui_kit::*;
6
7
8use teams_core::is_notes_chat;
9
7use super::ConversationView;
10use super::ConversationView;
8use crate::app_state::Selection;
11use crate::app_state::Selection;
9use crate::data::Directory;
12use crate::data::Directory;
10use crate::find_in_chat::FIND_IN_CHAT;
13use crate::find_in_chat::FIND_IN_CHAT;
11use crate::theme;
14use crate::theme;
12use crate::views::chat_pop_out::{self, POP_OUT_CHAT_LABEL};
15use crate::views::chat_menu::{ChatMenuTarget, MenuContext, chat_menu};
16use crate::views::composer::plus_menu::chat_invitees;
17use crate::views::new_meeting_dialog::open_new_meeting_with;
13use crate::views::avatar::status_glyph;
18use crate::views::avatar::status_glyph;
14use crate::views::widgets::{icon, symbol};
19use crate::views::widgets::{icon, menu_icon, symbol};
15
20
21pub const CHAT_HEADER_MORE_TAG: &str = "chat-header-more";
22const SCHEDULE_MEETING_LABEL: &str = "Schedule meeting";
16const BUTTON_SIZE: f32 = 32.;
23const BUTTON_SIZE: f32 = 32.;
17const COUNT_GLYPH: f32 = 16.;
24const COUNT_GLYPH: f32 = 16.;
18
25
@@ -38,25 +45,47 @@ impl ConversationView {
38 )
45 )
39 }
46 }
40
47
41 pub(super) fn pop_out_button(&self) -> Option<AnyElement> {
48 pub(super) fn chat_more_button(&self, cx: &App) -> Option<AnyElement> {
42 let chat_id = self
49 let chat_id = self
43 .header_chat_id()
50 .header_chat_id()
44 .filter(|_| !self.popped_out && !self.pinned)?
51 .filter(|_| !self.popped_out && !self.pinned)?;
45 .to_owned();
52 let target = ChatMenuTarget::for_chat(self.app.read(cx), chat_id)?;
46 let app = self.app.clone();
53 let context = MenuContext::new(&self.app, cx);
47 Some(
54 Some(
48 Button::new("chat-pop-out")
55 Button::new(CHAT_HEADER_MORE_TAG)
49 .icon(IconName::ExternalLink)
56 .icon(IconName::Ellipsis)
50 .ghost()
57 .ghost()
51 .size(px(BUTTON_SIZE))
58 .size(px(BUTTON_SIZE))
52 .rounded(px(8.))
59 .rounded(px(8.))
53 .tooltip(POP_OUT_CHAT_LABEL)
60 .tooltip("More chat options")
54 .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&app, &chat_id, cx))
61 .debug_selector(|| CHAT_HEADER_MORE_TAG.into())
62 .dropdown_menu(move |popup, window, cx| {
63 let popup = if is_notes_chat(&target.id) {
64 popup
65 } else {
66 schedule_meeting_item(popup, &context, &target.id)
67 };
68 chat_menu(popup, window, cx, &context, &target)
69 })
55 .into_any_element(),
70 .into_any_element(),
56 )
71 )
57 }
72 }
58}
73}
59
74
75fn schedule_meeting_item(popup: PopupMenu, context: &MenuContext, chat_id: &str) -> PopupMenu {
76 let (state, chat_id) = (context.state.clone(), chat_id.to_owned());
77 popup
78 .item(
79 PopupMenuItem::new(SCHEDULE_MEETING_LABEL)
80 .icon(menu_icon(IconName::Calendar))
81 .on_click(move |_, window, cx| {
82 let invitees = chat_invitees(state.read(cx), &chat_id);
83 open_new_meeting_with(state.clone(), invitees, window, cx);
84 }),
85 )
86 .separator()
87}
88
60pub fn member_count(count: usize) -> Div {
89pub fn member_count(count: usize) -> Div {
61 h_flex()
90 h_flex()
62 .gap(px(4.))
91 .gap(px(4.))
crates/app/src/views/mod.rs +1 −0
@@ -81,6 +81,7 @@ pub mod skin_tone_choices;
81 81 pub mod shell;
82 82 pub mod shortcuts;
83 83 pub mod shortcuts_dialog;
84 mod chat_menu;
84 85 mod last_views;
85 86 pub mod sidebar;
86 87 pub mod status_menu;
@@ -81,6 +81,7 @@ pub mod skin_tone_choices;
81pub mod shell;
81pub mod shell;
82pub mod shortcuts;
82pub mod shortcuts;
83pub mod shortcuts_dialog;
83pub mod shortcuts_dialog;
84mod chat_menu;
84mod last_views;
85mod last_views;
85pub mod sidebar;
86pub mod sidebar;
86pub mod status_menu;
87pub mod status_menu;
crates/app/src/views/sidebar.rs +4 −359
@@ -15,14 +15,12 @@ use store::{
15 15 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
16 16 Store,
17 17 };
18 use teams_core::{
19 ChatNotificationMode, DesktopNotifications, chat_link, is_notes_chat, team_avatar_key,
20 };
18 use teams_core::team_avatar_key;
21 19
22 20 use super::activity_panel::ActivityPanel;
23 21 use super::avatar::{spec_avatar, team_avatar, with_presence};
24 22 use super::calls_tab::calls_body;
25 use super::chat_pop_out;
23 use super::chat_menu::{ChatMenuTarget, MenuContext, chat_menu};
26 24 use super::saved_panel::SavedPanel;
27 25 use super::scroll_edge::{scroll_offset, with_top_edge};
28 26 use super::channel_admin_dialogs::{confirm_delete_channel, open_edit_channel_dialog};
@@ -32,7 +30,6 @@ use super::widgets::{count_badge, icon, menu_icon, page_header, symbol, unread_m
32 30 use crate::agents::AgentsPanel;
33 31 use super::last_views::LastViews;
34 32 use crate::app_state::{AppEvent, AppState, Selection};
35 use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
36 33 use crate::channel_menu::{
37 34 ChannelMenuItem, MenuEntry, TeamMenuItem, TeamMenuState, channel_menu_entries,
38 35 team_menu_entries,
@@ -147,268 +144,6 @@ impl Render for DragGhost {
147 144 }
148 145 }
149 146
150 #[derive(Clone)]
151 struct ChatMenuTarget {
152 id: String,
153 title: String,
154 folder_id: Option<String>,
155 unread: bool,
156 muted: bool,
157 is_group: bool,
158 member_count: usize,
159 }
160
161 #[derive(Clone)]
162 struct MenuContext {
163 state: Entity<AppState>,
164 folders: Vec<(String, String)>,
165 }
166
167 fn chat_menu(
168 popup: PopupMenu,
169 window: &mut Window,
170 cx: &mut Context<PopupMenu>,
171 context: &MenuContext,
172 target: &ChatMenuTarget,
173 ) -> PopupMenu {
174 let mut popup = popup;
175 let read_state = context.state.clone();
176 let read_id = target.id.clone();
177 let unread = target.unread;
178 let mute_state = context.state.clone();
179 let mute_id = target.id.clone();
180 let muted = target.muted;
181 let hide_state = context.state.clone();
182 let hide_id = target.id.clone();
183 let notes = is_notes_chat(&target.id);
184 popup = popup.item(
185 PopupMenuItem::new(if unread {
186 "Mark as read"
187 } else {
188 "Mark as unread"
189 })
190 .icon(menu_icon(if unread {
191 IconName::MailOpen
192 } else {
193 IconName::Mail
194 }))
195 .on_click(move |_, _, cx| {
196 read_state.update(cx, |state, cx| {
197 if unread {
198 state.mark_chat_read(&read_id, cx);
199 } else {
200 state.mark_chat_unread(&read_id, cx);
201 }
202 });
203 }),
204 );
205 let current = target.folder_id.clone();
206 let folders: Vec<(String, String)> = context
207 .folders
208 .iter()
209 .filter(|(folder_id, _)| current.as_ref() != Some(folder_id))
210 .cloned()
211 .collect();
212 if !folders.is_empty() {
213 let move_state = context.state.clone();
214 let move_id = target.id.clone();
215 popup = popup.submenu_with_icon(
216 Some(menu_icon(IconName::Folder)),
217 "Move to section",
218 window,
219 cx,
220 move |submenu, _, _| {
221 folders.iter().fold(submenu, |submenu, (folder_id, name)| {
222 let (state, chat_id, folder_id) =
223 (move_state.clone(), move_id.clone(), folder_id.clone());
224 submenu.item(PopupMenuItem::new(name.clone()).on_click(move |_, _, cx| {
225 state.update(cx, |state, cx| {
226 state.move_chat(&chat_id, Some(&folder_id), cx)
227 });
228 }))
229 })
230 },
231 );
232 }
233 if current.is_some() {
234 let remove_state = context.state.clone();
235 let remove_id = target.id.clone();
236 popup = popup.item(
237 PopupMenuItem::new("Remove from section")
238 .icon(menu_icon(IconName::FolderMinus))
239 .on_click(move |_, _, cx| {
240 remove_state.update(cx, |state, cx| state.move_chat(&remove_id, None, cx));
241 }),
242 );
243 }
244 let hide_item = PopupMenuItem::new("Hide")
245 .icon(menu_icon(IconName::EyeOff))
246 .on_click(move |_, _, cx| {
247 hide_state.update(cx, |state, cx| state.hide_chat(&hide_id, cx));
248 });
249 if notes {
250 return popup
251 .item(pop_out_item(context, target))
252 .separator()
253 .item(hide_item);
254 }
255 popup = popup.item(
256 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
257 .icon(menu_icon(if muted {
258 IconName::Bell
259 } else {
260 IconName::BellOff
261 }))
262 .on_click(move |_, _, cx| {
263 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
264 }),
265 );
266 popup = chat_notifications_submenu(popup, window, cx, context, target);
267 let partner = (!target.is_group)
268 .then(|| context.state.read(cx).one_on_one_partner(&target.id))
269 .flatten();
270 if let Some(partner) = partner {
271 let follow_state = context.state.clone();
272 let follow = !context.state.read(cx).is_presence_followed(&partner.user_id);
273 popup = popup.item(
274 PopupMenuItem::new(if follow {
275 NOTIFY_WHEN_AVAILABLE
276 } else {
277 TURN_OFF_NOTIFICATIONS
278 })
279 .icon(menu_icon(if follow {
280 IconName::BellRing
281 } else {
282 IconName::BellOff
283 }))
284 .on_click(move |_, _, cx| {
285 follow_state.update(cx, |state, cx| {
286 state.set_presence_followed(&partner.user_id, &partner.name, follow, cx)
287 });
288 }),
289 );
290 }
291 let (link_state, link_id) = (context.state.clone(), target.id.clone());
292 popup = popup
293 .item(
294 PopupMenuItem::new("Copy link")
295 .icon(menu_icon(IconName::Link))
296 .on_click(move |_, _, cx| {
297 cx.write_to_clipboard(ClipboardItem::new_string(chat_link(&link_id)));
298 link_state.update(cx, |state, cx| {
299 state.raise_notice("Link copied".to_owned(), None, cx)
300 });
301 }),
302 )
303 .item(pop_out_item(context, target))
304 .separator()
305 .item(hide_item);
306 if !target.is_group {
307 let remove_state = context.state.clone();
308 let remove_id = target.id.clone();
309 popup = popup.item(
310 PopupMenuItem::new(REMOVE_HISTORY_LABEL)
311 .icon(menu_icon(IconName::Trash))
312 .on_click(move |_, window, cx| {
313 confirm_remove_history(&remove_state, &remove_id, window, cx);
314 }),
315 );
316 }
317 if target.is_group {
318 let leave_state = context.state.clone();
319 let leave_id = target.id.clone();
320 let title = target.title.clone();
321 let member_count = target.member_count;
322 popup = popup.item(
323 PopupMenuItem::element(|_, _| {
324 div().text_color(theme::red_soft()).child("Leave chat...")
325 })
326 .icon(menu_icon(IconName::LogOut).text_color(theme::red_soft()))
327 .on_click(move |_, window, cx| {
328 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
329 }),
330 );
331 }
332 popup
333 }
334
335 fn pop_out_item(context: &MenuContext, target: &ChatMenuTarget) -> PopupMenuItem {
336 let (state, chat_id) = (context.state.clone(), target.id.clone());
337 PopupMenuItem::new(chat_pop_out::POP_OUT_CHAT_LABEL)
338 .icon(menu_icon(IconName::ExternalLink))
339 .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&state, &chat_id, cx))
340 }
341
342 const CHAT_NOTIFICATION_MODES: [(&str, ChatNotificationMode); 2] = [
343 ("All new messages", ChatNotificationMode::AllNewMessages),
344 ("Mute", ChatNotificationMode::Mute),
345 ];
346
347 const DESKTOP_NOTIFICATIONS: [(&str, DesktopNotifications); 2] = [
348 (
349 "Match settings used for all chats",
350 DesktopNotifications::MatchAllChats,
351 ),
352 ("Don't get desktop notifications", DesktopNotifications::Off),
353 ];
354
355 fn chat_notifications_submenu(
356 popup: PopupMenu,
357 window: &mut Window,
358 cx: &mut Context<PopupMenu>,
359 context: &MenuContext,
360 target: &ChatMenuTarget,
361 ) -> PopupMenu {
362 let state = context.state.clone();
363 let chat_id = target.id.clone();
364 let mode = if target.muted {
365 ChatNotificationMode::Mute
366 } else {
367 ChatNotificationMode::AllNewMessages
368 };
369 let desktop = state.read(cx).chat_desktop_notifications(&chat_id);
370 popup.submenu_with_icon(
371 Some(menu_icon(IconName::Bell)),
372 "Manage notifications",
373 window,
374 cx,
375 move |submenu, _, _| {
376 let choose = |chosen_mode: ChatNotificationMode,
377 chosen_desktop: DesktopNotifications| {
378 let (state, chat_id) = (state.clone(), chat_id.clone());
379 move |_: &ClickEvent, _: &mut Window, cx: &mut App| {
380 state.update(cx, |state, cx| {
381 state.set_chat_notifications(&chat_id, chosen_mode, chosen_desktop, cx)
382 });
383 }
384 };
385 let submenu = submenu.label("Chat notification mode");
386 let submenu =
387 CHAT_NOTIFICATION_MODES
388 .iter()
389 .fold(submenu, |submenu, (label, value)| {
390 submenu.item(
391 PopupMenuItem::new(*label)
392 .checked(*value == mode)
393 .on_click(choose(*value, desktop)),
394 )
395 });
396 let submenu = submenu
397 .separator()
398 .label("Set a desktop notification preference");
399 DESKTOP_NOTIFICATIONS
400 .iter()
401 .fold(submenu, |submenu, (label, value)| {
402 submenu.item(
403 PopupMenuItem::new(*label)
404 .checked(*value == desktop)
405 .on_click(choose(mode, *value)),
406 )
407 })
408 },
409 )
410 }
411
412 147 #[derive(Clone)]
413 148 struct SectionMenuTarget {
414 149 id: String,
@@ -592,83 +327,6 @@ fn confirm_delete_section(
592 327 });
593 328 }
594 329
595 fn leave_description(member_count: usize) -> String {
596 let who = match member_count {
597 0 | 1 => "The other members".to_owned(),
598 2 => "The other member".to_owned(),
599 count => format!("The {} other members", count - 1),
600 };
601 let verb = if member_count == 2 { "sees" } else { "see" };
602 format!("{who} {verb} that you left. You can only come back if someone adds you.")
603 }
604
605 const REMOVE_HISTORY_LABEL: &str = "Remove chat history";
606 const REMOVE_HISTORY_TITLE: &str = "Remove chat history?";
607 const REMOVE_HISTORY_TEXT: &str =
608 "This will remove the chat from your list and search. It affects you only.";
609
610 fn confirm_remove_history(
611 state: &Entity<AppState>,
612 chat_id: &str,
613 window: &mut Window,
614 cx: &mut App,
615 ) {
616 let state = state.clone();
617 let chat_id = chat_id.to_owned();
618 window.open_alert_dialog(cx, move |alert, _, _| {
619 let state = state.clone();
620 let chat_id = chat_id.clone();
621 let cancel = Button::new("remove-history-cancel")
622 .label("Cancel")
623 .on_click(|_, window, cx| window.close_dialog(cx));
624 let remove = Button::new("remove-history-confirm")
625 .label("Remove")
626 .primary()
627 .on_click(move |_, window, cx| {
628 state.update(cx, |state, cx| state.remove_chat_history(&chat_id, cx));
629 window.close_dialog(cx);
630 });
631 alert
632 .title(REMOVE_HISTORY_TITLE)
633 .description(REMOVE_HISTORY_TEXT)
634 .footer(DialogFooter::new().child(cancel).child(remove))
635 .on_ok(|_, _, _| false)
636 });
637 }
638
639 pub(crate) fn confirm_leave(
640 state: &Entity<AppState>,
641 chat_id: &str,
642 title: &str,
643 member_count: usize,
644 window: &mut Window,
645 cx: &mut App,
646 ) {
647 let state = state.clone();
648 let chat_id = chat_id.to_owned();
649 let heading = format!("Leave \"{}\"?", truncated(title, TITLE_LIMIT));
650 let description = leave_description(member_count);
651 window.open_alert_dialog(cx, move |alert, _, _| {
652 let state = state.clone();
653 let chat_id = chat_id.clone();
654 let cancel = Button::new("leave-cancel")
655 .label("Cancel")
656 .on_click(|_, window, cx| window.close_dialog(cx));
657 let leave = Button::new("leave-confirm")
658 .label("Leave")
659 .danger()
660 .on_click(move |_, window, cx| {
661 state.update(cx, |state, cx| state.leave_chat(&chat_id, cx));
662 window.close_dialog(cx);
663 });
664 alert
665 .title(heading.clone())
666 .description(description.clone())
667 .footer(DialogFooter::new().child(cancel).child(leave))
668 .on_ok(|_, _, _| false)
669 });
670 }
671
672 330 pub enum SidebarEvent {
673 331 RestoreFocus,
674 332 TabChanged,
@@ -1433,10 +1091,7 @@ impl SidebarView {
1433 1091 } else {
1434 1092 build_sections(&input)
1435 1093 };
1436 let menu = MenuContext {
1437 state: self.state.clone(),
1438 folders: state.directory.move_targets(),
1439 };
1094 let menu = MenuContext::new(&self.state, cx);
1440 1095 let section_menus =
1441 1096 section_menu_targets(&sections, &state.directory, state.mode.read_only);
1442 1097 *self.section_ids.borrow_mut() =
@@ -2390,7 +2045,7 @@ mod tests {
2390 2045 use std::collections::HashSet;
2391 2046
2392 2047 use super::{
2393 drop_target, leave_description, parse_collapsed_teams, serialize_collapsed_teams,
2048 drop_target, parse_collapsed_teams, serialize_collapsed_teams,
2394 2049 team_expanded,
2395 2050 };
2396 2051 use crate::data::PENDING_FOLDER_PREFIX;
@@ -2445,14 +2100,4 @@ mod tests {
2445 2100 assert_eq!(parse_collapsed_teams(&json), collapsed);
2446 2101 assert!(parse_collapsed_teams("garbage").is_empty());
2447 2102 }
2448
2449 #[test]
2450 fn leave_text_counts_the_other_members() {
2451 assert_eq!(
2452 leave_description(4),
2453 "The 3 other members see that you left. You can only come back if someone adds you."
2454 );
2455 assert!(leave_description(2).starts_with("The other member sees"));
2456 assert!(leave_description(0).starts_with("The other members see"));
2457 }
2458 2103 }
@@ -15,14 +15,12 @@ use store::{
15 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
15 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
16 Store,
16 Store,
17};
17};
18use teams_core::{
18use teams_core::team_avatar_key;
19 ChatNotificationMode, DesktopNotifications, chat_link, is_notes_chat, team_avatar_key,
20};
21
19
22use super::activity_panel::ActivityPanel;
20use super::activity_panel::ActivityPanel;
23use super::avatar::{spec_avatar, team_avatar, with_presence};
21use super::avatar::{spec_avatar, team_avatar, with_presence};
24use super::calls_tab::calls_body;
22use super::calls_tab::calls_body;
25use super::chat_pop_out;
23use super::chat_menu::{ChatMenuTarget, MenuContext, chat_menu};
26use super::saved_panel::SavedPanel;
24use super::saved_panel::SavedPanel;
27use super::scroll_edge::{scroll_offset, with_top_edge};
25use super::scroll_edge::{scroll_offset, with_top_edge};
28use super::channel_admin_dialogs::{confirm_delete_channel, open_edit_channel_dialog};
26use super::channel_admin_dialogs::{confirm_delete_channel, open_edit_channel_dialog};
@@ -32,7 +30,6 @@ use super::widgets::{count_badge, icon, menu_icon, page_header, symbol, unread_m
32use crate::agents::AgentsPanel;
30use crate::agents::AgentsPanel;
33use super::last_views::LastViews;
31use super::last_views::LastViews;
34use crate::app_state::{AppEvent, AppState, Selection};
32use crate::app_state::{AppEvent, AppState, Selection};
35use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
36use crate::channel_menu::{
33use crate::channel_menu::{
37 ChannelMenuItem, MenuEntry, TeamMenuItem, TeamMenuState, channel_menu_entries,
34 ChannelMenuItem, MenuEntry, TeamMenuItem, TeamMenuState, channel_menu_entries,
38 team_menu_entries,
35 team_menu_entries,
@@ -147,268 +144,6 @@ impl Render for DragGhost {
147 }
144 }
148}
145}
149
146
150#[derive(Clone)]
151struct ChatMenuTarget {
152 id: String,
153 title: String,
154 folder_id: Option<String>,
155 unread: bool,
156 muted: bool,
157 is_group: bool,
158 member_count: usize,
159}
160
161#[derive(Clone)]
162struct MenuContext {
163 state: Entity<AppState>,
164 folders: Vec<(String, String)>,
165}
166
167fn chat_menu(
168 popup: PopupMenu,
169 window: &mut Window,
170 cx: &mut Context<PopupMenu>,
171 context: &MenuContext,
172 target: &ChatMenuTarget,
173) -> PopupMenu {
174 let mut popup = popup;
175 let read_state = context.state.clone();
176 let read_id = target.id.clone();
177 let unread = target.unread;
178 let mute_state = context.state.clone();
179 let mute_id = target.id.clone();
180 let muted = target.muted;
181 let hide_state = context.state.clone();
182 let hide_id = target.id.clone();
183 let notes = is_notes_chat(&target.id);
184 popup = popup.item(
185 PopupMenuItem::new(if unread {
186 "Mark as read"
187 } else {
188 "Mark as unread"
189 })
190 .icon(menu_icon(if unread {
191 IconName::MailOpen
192 } else {
193 IconName::Mail
194 }))
195 .on_click(move |_, _, cx| {
196 read_state.update(cx, |state, cx| {
197 if unread {
198 state.mark_chat_read(&read_id, cx);
199 } else {
200 state.mark_chat_unread(&read_id, cx);
201 }
202 });
203 }),
204 );
205 let current = target.folder_id.clone();
206 let folders: Vec<(String, String)> = context
207 .folders
208 .iter()
209 .filter(|(folder_id, _)| current.as_ref() != Some(folder_id))
210 .cloned()
211 .collect();
212 if !folders.is_empty() {
213 let move_state = context.state.clone();
214 let move_id = target.id.clone();
215 popup = popup.submenu_with_icon(
216 Some(menu_icon(IconName::Folder)),
217 "Move to section",
218 window,
219 cx,
220 move |submenu, _, _| {
221 folders.iter().fold(submenu, |submenu, (folder_id, name)| {
222 let (state, chat_id, folder_id) =
223 (move_state.clone(), move_id.clone(), folder_id.clone());
224 submenu.item(PopupMenuItem::new(name.clone()).on_click(move |_, _, cx| {
225 state.update(cx, |state, cx| {
226 state.move_chat(&chat_id, Some(&folder_id), cx)
227 });
228 }))
229 })
230 },
231 );
232 }
233 if current.is_some() {
234 let remove_state = context.state.clone();
235 let remove_id = target.id.clone();
236 popup = popup.item(
237 PopupMenuItem::new("Remove from section")
238 .icon(menu_icon(IconName::FolderMinus))
239 .on_click(move |_, _, cx| {
240 remove_state.update(cx, |state, cx| state.move_chat(&remove_id, None, cx));
241 }),
242 );
243 }
244 let hide_item = PopupMenuItem::new("Hide")
245 .icon(menu_icon(IconName::EyeOff))
246 .on_click(move |_, _, cx| {
247 hide_state.update(cx, |state, cx| state.hide_chat(&hide_id, cx));
248 });
249 if notes {
250 return popup
251 .item(pop_out_item(context, target))
252 .separator()
253 .item(hide_item);
254 }
255 popup = popup.item(
256 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
257 .icon(menu_icon(if muted {
258 IconName::Bell
259 } else {
260 IconName::BellOff
261 }))
262 .on_click(move |_, _, cx| {
263 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
264 }),
265 );
266 popup = chat_notifications_submenu(popup, window, cx, context, target);
267 let partner = (!target.is_group)
268 .then(|| context.state.read(cx).one_on_one_partner(&target.id))
269 .flatten();
270 if let Some(partner) = partner {
271 let follow_state = context.state.clone();
272 let follow = !context.state.read(cx).is_presence_followed(&partner.user_id);
273 popup = popup.item(
274 PopupMenuItem::new(if follow {
275 NOTIFY_WHEN_AVAILABLE
276 } else {
277 TURN_OFF_NOTIFICATIONS
278 })
279 .icon(menu_icon(if follow {
280 IconName::BellRing
281 } else {
282 IconName::BellOff
283 }))
284 .on_click(move |_, _, cx| {
285 follow_state.update(cx, |state, cx| {
286 state.set_presence_followed(&partner.user_id, &partner.name, follow, cx)
287 });
288 }),
289 );
290 }
291 let (link_state, link_id) = (context.state.clone(), target.id.clone());
292 popup = popup
293 .item(
294 PopupMenuItem::new("Copy link")
295 .icon(menu_icon(IconName::Link))
296 .on_click(move |_, _, cx| {
297 cx.write_to_clipboard(ClipboardItem::new_string(chat_link(&link_id)));
298 link_state.update(cx, |state, cx| {
299 state.raise_notice("Link copied".to_owned(), None, cx)
300 });
301 }),
302 )
303 .item(pop_out_item(context, target))
304 .separator()
305 .item(hide_item);
306 if !target.is_group {
307 let remove_state = context.state.clone();
308 let remove_id = target.id.clone();
309 popup = popup.item(
310 PopupMenuItem::new(REMOVE_HISTORY_LABEL)
311 .icon(menu_icon(IconName::Trash))
312 .on_click(move |_, window, cx| {
313 confirm_remove_history(&remove_state, &remove_id, window, cx);
314 }),
315 );
316 }
317 if target.is_group {
318 let leave_state = context.state.clone();
319 let leave_id = target.id.clone();
320 let title = target.title.clone();
321 let member_count = target.member_count;
322 popup = popup.item(
323 PopupMenuItem::element(|_, _| {
324 div().text_color(theme::red_soft()).child("Leave chat...")
325 })
326 .icon(menu_icon(IconName::LogOut).text_color(theme::red_soft()))
327 .on_click(move |_, window, cx| {
328 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
329 }),
330 );
331 }
332 popup
333}
334
335fn pop_out_item(context: &MenuContext, target: &ChatMenuTarget) -> PopupMenuItem {
336 let (state, chat_id) = (context.state.clone(), target.id.clone());
337 PopupMenuItem::new(chat_pop_out::POP_OUT_CHAT_LABEL)
338 .icon(menu_icon(IconName::ExternalLink))
339 .on_click(move |_, _, cx| chat_pop_out::pop_out_chat(&state, &chat_id, cx))
340}
341
342const CHAT_NOTIFICATION_MODES: [(&str, ChatNotificationMode); 2] = [
343 ("All new messages", ChatNotificationMode::AllNewMessages),
344 ("Mute", ChatNotificationMode::Mute),
345];
346
347const DESKTOP_NOTIFICATIONS: [(&str, DesktopNotifications); 2] = [
348 (
349 "Match settings used for all chats",
350 DesktopNotifications::MatchAllChats,
351 ),
352 ("Don't get desktop notifications", DesktopNotifications::Off),
353];
354
355fn chat_notifications_submenu(
356 popup: PopupMenu,
357 window: &mut Window,
358 cx: &mut Context<PopupMenu>,
359 context: &MenuContext,
360 target: &ChatMenuTarget,
361) -> PopupMenu {
362 let state = context.state.clone();
363 let chat_id = target.id.clone();
364 let mode = if target.muted {
365 ChatNotificationMode::Mute
366 } else {
367 ChatNotificationMode::AllNewMessages
368 };
369 let desktop = state.read(cx).chat_desktop_notifications(&chat_id);
370 popup.submenu_with_icon(
371 Some(menu_icon(IconName::Bell)),
372 "Manage notifications",
373 window,
374 cx,
375 move |submenu, _, _| {
376 let choose = |chosen_mode: ChatNotificationMode,
377 chosen_desktop: DesktopNotifications| {
378 let (state, chat_id) = (state.clone(), chat_id.clone());
379 move |_: &ClickEvent, _: &mut Window, cx: &mut App| {
380 state.update(cx, |state, cx| {
381 state.set_chat_notifications(&chat_id, chosen_mode, chosen_desktop, cx)
382 });
383 }
384 };
385 let submenu = submenu.label("Chat notification mode");
386 let submenu =
387 CHAT_NOTIFICATION_MODES
388 .iter()
389 .fold(submenu, |submenu, (label, value)| {
390 submenu.item(
391 PopupMenuItem::new(*label)
392 .checked(*value == mode)
393 .on_click(choose(*value, desktop)),
394 )
395 });
396 let submenu = submenu
397 .separator()
398 .label("Set a desktop notification preference");
399 DESKTOP_NOTIFICATIONS
400 .iter()
401 .fold(submenu, |submenu, (label, value)| {
402 submenu.item(
403 PopupMenuItem::new(*label)
404 .checked(*value == desktop)
405 .on_click(choose(mode, *value)),
406 )
407 })
408 },
409 )
410}
411
412#[derive(Clone)]
147#[derive(Clone)]
413struct SectionMenuTarget {
148struct SectionMenuTarget {
414 id: String,
149 id: String,
@@ -592,83 +327,6 @@ fn confirm_delete_section(
592 });
327 });
593}
328}
594
329
595fn leave_description(member_count: usize) -> String {
596 let who = match member_count {
597 0 | 1 => "The other members".to_owned(),
598 2 => "The other member".to_owned(),
599 count => format!("The {} other members", count - 1),
600 };
601 let verb = if member_count == 2 { "sees" } else { "see" };
602 format!("{who} {verb} that you left. You can only come back if someone adds you.")
603}
604
605const REMOVE_HISTORY_LABEL: &str = "Remove chat history";
606const REMOVE_HISTORY_TITLE: &str = "Remove chat history?";
607const REMOVE_HISTORY_TEXT: &str =
608 "This will remove the chat from your list and search. It affects you only.";
609
610fn confirm_remove_history(
611 state: &Entity<AppState>,
612 chat_id: &str,
613 window: &mut Window,
614 cx: &mut App,
615) {
616 let state = state.clone();
617 let chat_id = chat_id.to_owned();
618 window.open_alert_dialog(cx, move |alert, _, _| {
619 let state = state.clone();
620 let chat_id = chat_id.clone();
621 let cancel = Button::new("remove-history-cancel")
622 .label("Cancel")
623 .on_click(|_, window, cx| window.close_dialog(cx));
624 let remove = Button::new("remove-history-confirm")
625 .label("Remove")
626 .primary()
627 .on_click(move |_, window, cx| {
628 state.update(cx, |state, cx| state.remove_chat_history(&chat_id, cx));
629 window.close_dialog(cx);
630 });
631 alert
632 .title(REMOVE_HISTORY_TITLE)
633 .description(REMOVE_HISTORY_TEXT)
634 .footer(DialogFooter::new().child(cancel).child(remove))
635 .on_ok(|_, _, _| false)
636 });
637}
638
639pub(crate) fn confirm_leave(
640 state: &Entity<AppState>,
641 chat_id: &str,
642 title: &str,
643 member_count: usize,
644 window: &mut Window,
645 cx: &mut App,
646) {
647 let state = state.clone();
648 let chat_id = chat_id.to_owned();
649 let heading = format!("Leave \"{}\"?", truncated(title, TITLE_LIMIT));
650 let description = leave_description(member_count);
651 window.open_alert_dialog(cx, move |alert, _, _| {
652 let state = state.clone();
653 let chat_id = chat_id.clone();
654 let cancel = Button::new("leave-cancel")
655 .label("Cancel")
656 .on_click(|_, window, cx| window.close_dialog(cx));
657 let leave = Button::new("leave-confirm")
658 .label("Leave")
659 .danger()
660 .on_click(move |_, window, cx| {
661 state.update(cx, |state, cx| state.leave_chat(&chat_id, cx));
662 window.close_dialog(cx);
663 });
664 alert
665 .title(heading.clone())
666 .description(description.clone())
667 .footer(DialogFooter::new().child(cancel).child(leave))
668 .on_ok(|_, _, _| false)
669 });
670}
671
672pub enum SidebarEvent {
330pub enum SidebarEvent {
673 RestoreFocus,
331 RestoreFocus,
674 TabChanged,
332 TabChanged,
@@ -1433,10 +1091,7 @@ impl SidebarView {
1433 } else {
1091 } else {
1434 build_sections(&input)
1092 build_sections(&input)
1435 };
1093 };
1436 let menu = MenuContext {
1094 let menu = MenuContext::new(&self.state, cx);
1437 state: self.state.clone(),
1438 folders: state.directory.move_targets(),
1439 };
1440 let section_menus =
1095 let section_menus =
1441 section_menu_targets(&sections, &state.directory, state.mode.read_only);
1096 section_menu_targets(&sections, &state.directory, state.mode.read_only);
1442 *self.section_ids.borrow_mut() =
1097 *self.section_ids.borrow_mut() =
@@ -2390,7 +2045,7 @@ mod tests {
2390 use std::collections::HashSet;
2045 use std::collections::HashSet;
2391
2046
2392 use super::{
2047 use super::{
2393 drop_target, leave_description, parse_collapsed_teams, serialize_collapsed_teams,
2048 drop_target, parse_collapsed_teams, serialize_collapsed_teams,
2394 team_expanded,
2049 team_expanded,
2395 };
2050 };
2396 use crate::data::PENDING_FOLDER_PREFIX;
2051 use crate::data::PENDING_FOLDER_PREFIX;
@@ -2445,14 +2100,4 @@ mod tests {
2445 assert_eq!(parse_collapsed_teams(&json), collapsed);
2100 assert_eq!(parse_collapsed_teams(&json), collapsed);
2446 assert!(parse_collapsed_teams("garbage").is_empty());
2101 assert!(parse_collapsed_teams("garbage").is_empty());
2447 }
2102 }
2448
2449 #[test]
2450 fn leave_text_counts_the_other_members() {
2451 assert_eq!(
2452 leave_description(4),
2453 "The 3 other members see that you left. You can only come back if someone adds you."
2454 );
2455 assert!(leave_description(2).starts_with("The other member sees"));
2456 assert!(leave_description(0).starts_with("The other members see"));
2457 }
2458}
2103}