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>
@@ -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;2
use gpui_kit::component::{2
use 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
};6
use gpui_kit::*;7
use gpui_kit::*;7
8
8
use super::widgets::icon;9
use super::widgets::{icon, menu_icon};9
use crate::app_state::{AppState, Selection};10
use crate::app_state::{AppState, Selection};10
use crate::call::{is_echo_chat, plan_for_chat};11
use crate::call::{is_echo_chat, plan_for_chat};11
use crate::theme;12
use crate::theme;@@ -13,6 +14,13 @@ use crate::theme;13
const BUTTON_SIZE: f32 = 30.;14
const BUTTON_SIZE: f32 = 30.;14
const GLYPH_SIZE: f32 = 16.;15
const GLYPH_SIZE: f32 = 16.;15
const JOIN_HEIGHT: f32 = 30.;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
pub fn header_call_controls(25
pub 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
controls70
controls88
}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
popup113
.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
}@@ -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::*;14
use super::add_people_dialog::open_add_people;14
use super::add_people_dialog::open_add_people;15
use super::avatar::{person_avatar, with_presence};15
use super::avatar::{person_avatar, with_presence};16
use super::profile_card::opens_profile;16
use super::profile_card::opens_profile;17
use super::sidebar::confirm_leave;17
use super::chat_menu::confirm_leave;18
use super::widgets::icon;18
use super::widgets::icon;19
use crate::app_state::AppState;19
use crate::app_state::AppState;20
use crate::chat_actions::TITLE_LIMIT;20
use crate::chat_actions::TITLE_LIMIT;@@ -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;11
use crate::theme::{self, ElevatedSurface as _};11
use crate::theme::{self, ElevatedSurface as _};12
use crate::views::actions::OpenSwitcher;12
use crate::views::actions::OpenSwitcher;13
use crate::views::shortcuts::{OpenSettings, ShowShortcuts};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
const GROUP_KIND: &str = "group";16
const GROUP_KIND: &str = "group";17
const WIDTH: f32 = 380.;17
const WIDTH: f32 = 380.;@@ -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
header3762
header3761
.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
3837
const GROUP_KIND: &str = "group";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
impl Render for ConversationView {3852
impl 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 {@@ -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-details26
const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";26
const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";27
const OPEN_LABEL: &str = "Open channel details";27
const OPEN_LABEL: &str = "Open channel details";28
const CLOSE_LABEL: &str = "Close channel details";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
const PINNED_TITLE: &str = "Pinned";32
const PINNED_TITLE: &str = "Pinned";30
const SHARED_TITLE: &str = "Shared";33
const SHARED_TITLE: &str = "Shared";31
const SEE_ALL_SHARED_ARIA: &str = "See all shared files";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
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> = state205
let ids: Vec<String> = state182
.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 = self221
let title = if is_chat {198
.current222
CHAT_DETAILS_TITLE.to_owned()199
.as_ref()223
} else {200
.map(|current| current.title.clone())224
self.current201
.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;@@ -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 @@1
use gpui_kit::assets::IconName;1
use gpui_kit::assets::IconName;2
use gpui_kit::component::button::{Button, ButtonVariants as _};2
use gpui_kit::component::button::{Button, ButtonVariants as _};3
use gpui_kit::component::h_flex;3
use gpui_kit::component::h_flex;4
use gpui_kit::component::menu::{DropdownMenu as _, PopupMenu, PopupMenuItem};4
use gpui_kit::prelude::FluentBuilder as _;5
use gpui_kit::prelude::FluentBuilder as _;5
use gpui_kit::*;6
use gpui_kit::*;6
7
8
use teams_core::is_notes_chat;9
7
use super::ConversationView;10
use super::ConversationView;8
use crate::app_state::Selection;11
use crate::app_state::Selection;9
use crate::data::Directory;12
use crate::data::Directory;10
use crate::find_in_chat::FIND_IN_CHAT;13
use crate::find_in_chat::FIND_IN_CHAT;11
use crate::theme;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
use crate::views::avatar::status_glyph;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
const BUTTON_SIZE: f32 = 32.;23
const BUTTON_SIZE: f32 = 32.;17
const COUNT_GLYPH: f32 = 16.;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
let chat_id = self49
let chat_id = self43
.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
popup65
} 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
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
popup78
.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
pub fn member_count(count: usize) -> Div {89
pub fn member_count(count: usize) -> Div {61
h_flex()90
h_flex()62
.gap(px(4.))91
.gap(px(4.))@@ -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;81
pub mod shell;81
pub mod shell;82
pub mod shortcuts;82
pub mod shortcuts;83
pub mod shortcuts_dialog;83
pub mod shortcuts_dialog;84
mod chat_menu;84
mod last_views;85
mod last_views;85
pub mod sidebar;86
pub mod sidebar;86
pub mod status_menu;87
pub mod status_menu;@@ -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(§ions, &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
};18
use teams_core::{18
use teams_core::team_avatar_key;19
ChatNotificationMode, DesktopNotifications, chat_link, is_notes_chat, team_avatar_key,20
};21
19
22
use super::activity_panel::ActivityPanel;20
use super::activity_panel::ActivityPanel;23
use super::avatar::{spec_avatar, team_avatar, with_presence};21
use super::avatar::{spec_avatar, team_avatar, with_presence};24
use super::calls_tab::calls_body;22
use super::calls_tab::calls_body;25
use super::chat_pop_out;23
use super::chat_menu::{ChatMenuTarget, MenuContext, chat_menu};26
use super::saved_panel::SavedPanel;24
use super::saved_panel::SavedPanel;27
use super::scroll_edge::{scroll_offset, with_top_edge};25
use super::scroll_edge::{scroll_offset, with_top_edge};28
use super::channel_admin_dialogs::{confirm_delete_channel, open_edit_channel_dialog};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_m32
use crate::agents::AgentsPanel;30
use crate::agents::AgentsPanel;33
use super::last_views::LastViews;31
use super::last_views::LastViews;34
use crate::app_state::{AppEvent, AppState, Selection};32
use crate::app_state::{AppEvent, AppState, Selection};35
use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};36
use crate::channel_menu::{33
use 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)]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::MailOpen192
} else {193
IconName::Mail194
}))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)> = context207
.folders208
.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 popup251
.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::Bell259
} else {260
IconName::BellOff261
}))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_AVAILABLE276
} else {277
TURN_OFF_NOTIFICATIONS278
})279
.icon(menu_icon(if follow {280
IconName::BellRing281
} else {282
IconName::BellOff283
}))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 = popup293
.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
popup333
}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::Mute366
} else {367
ChatNotificationMode::AllNewMessages368
};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_MODES388
.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 = submenu397
.separator()398
.label("Set a desktop notification preference");399
DESKTOP_NOTIFICATIONS400
.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)]413
struct SectionMenuTarget {148
struct SectionMenuTarget {414
id: String,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
alert632
.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
alert665
.title(heading.clone())666
.description(description.clone())667
.footer(DialogFooter::new().child(cancel).child(leave))668
.on_ok(|_, _, _| false)669
});670
}671
672
pub enum SidebarEvent {330
pub 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(§ions, &state.directory, state.mode.read_only);1096
section_menu_targets(§ions, &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
}