BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_controls.rs

call_controls.rs

call_controls.rs 5.7 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{
3 button::{Button, ButtonVariants as _},
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
6};
7use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9
10use super::shortcuts::{StartAudioCall, StartVideoCall};
11use super::widgets::{icon, menu_icon};
12use crate::app_state::{AppState, Selection};
13use crate::call::{is_echo_chat, plan_for_chat};
14use crate::theme;
15
16const BUTTON_SIZE: f32 = 30.;
17const GLYPH_SIZE: f32 = 16.;
18const JOIN_HEIGHT: f32 = 30.;
19const CHEVRON_WIDTH: f32 = 18.;
20const CHEVRON_GLYPH: f32 = 12.;
21pub const HEADER_VIDEO_CALL_TAG: &str = "header-video-call";
22pub const HEADER_CALL_OPTIONS_TAG: &str = "header-call-options";
23const VIDEO_CALL_LABEL: &str = "Video call";
24const AUDIO_CALL_LABEL: &str = "Audio call";
25const CALL_OPTIONS_LABEL: &str = "Call options";
26const MEET_NOW_LABEL: &str = "Meet now";
27const GROUP_KIND: &str = "group";
28
29pub fn header_call_controls(
30 app: &Entity<AppState>,
31 state: &AppState,
32 selection: &Selection,
33 compact: bool,
34) -> Vec<AnyElement> {
35 let conversation_id = selection.conversation_id().to_owned();
36 let mut controls = Vec::new();
37 if state.running_meeting(&conversation_id).is_some() {
38 let join_app = app.clone();
39 let join_id = conversation_id.clone();
40 controls.push(
41 h_flex()
42 .id("header-join")
43 .h(px(JOIN_HEIGHT))
44 .px(px(14.))
45 .gap(px(6.))
46 .flex_none()
47 .items_center()
48 .rounded_full()
49 .bg(theme::green())
50 .text_color(theme::white())
51 .text_size(px(13.))
52 .font_weight(FontWeight::SEMIBOLD)
53 .cursor_pointer()
54 .hover(|button| button.opacity(0.85))
55 .child(icon(IconName::Phone, 14., theme::white()))
56 .child("Join")
57 .on_click(move |_, _, cx| {
58 join_app.update(cx, |state, cx| state.join_meeting_call(&join_id, cx));
59 })
60 .into_any_element(),
61 );
62 }
63 let chat = match selection {
64 Selection::Chat(chat_id) => state.sidebar.chats.iter().find(|chat| &chat.id == chat_id),
65 Selection::Channel(_) => None,
66 };
67 let callable = chat.is_some_and(|chat| {
68 is_echo_chat(chat) || plan_for_chat(chat, state.directory.me.as_ref()).is_some()
69 });
70 if let Some(chat) = chat.filter(|_| callable) {
71 let meet_now = chat.kind == GROUP_KIND && !is_echo_chat(chat);
72 controls.push(video_split_button(app, meet_now, compact));
73 }
74 controls
75}
76
77fn start_call(app: &Entity<AppState>, with_video: bool, cx: &mut App) {
78 app.update(cx, |state, cx| {
79 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
80 if with_video {
81 state.start_chat_video_call(&chat_id, cx);
82 } else {
83 state.start_chat_call(&chat_id, cx);
84 }
85 }
86 });
87}
88
89fn video_split_button(app: &Entity<AppState>, meet_now: bool, compact: bool) -> AnyElement {
90 let video_app = app.clone();
91 let menu_app = app.clone();
92 let labelled = meet_now && !compact;
93 h_flex()
94 .flex_none()
95 .items_center()
96 .child(
97 Button::new(HEADER_VIDEO_CALL_TAG)
98 .ghost()
99 .h(px(BUTTON_SIZE))
100 .map(|button| if labelled { button.px(px(8.)) } else { button.p_0().w(px(BUTTON_SIZE)) })
101 .tooltip(if meet_now { MEET_NOW_LABEL } else { VIDEO_CALL_LABEL })
102 .debug_selector(|| HEADER_VIDEO_CALL_TAG.into())
103 .child(
104 h_flex()
105 .gap(px(6.))
106 .items_center()
107 .child(icon(IconName::Video, GLYPH_SIZE, theme::text_soft()))
108 .when(labelled, |row| {
109 row.child(
110 div()
111 .text_size(px(14.))
112 .font_weight(FontWeight::SEMIBOLD)
113 .text_color(theme::text())
114 .child(MEET_NOW_LABEL),
115 )
116 }),
117 )
118 .on_click(move |_, _, cx| start_call(&video_app, true, cx)),
119 )
120 .child(
121 Button::new(HEADER_CALL_OPTIONS_TAG)
122 .ghost()
123 .p_0()
124 .w(px(CHEVRON_WIDTH))
125 .h(px(BUTTON_SIZE))
126 .tooltip(CALL_OPTIONS_LABEL)
127 .debug_selector(|| HEADER_CALL_OPTIONS_TAG.into())
128 .child(icon(IconName::ChevronDown, CHEVRON_GLYPH, theme::text_soft()))
129 .dropdown_menu(move |popup, _, _| {
130 let (video, audio) = (menu_app.clone(), menu_app.clone());
131 let popup = if meet_now {
132 popup
133 } else {
134 popup.item(
135 PopupMenuItem::new(VIDEO_CALL_LABEL)
136 .icon(menu_icon(IconName::Video))
137 .action(Box::new(StartVideoCall))
138 .on_click(move |_, _, cx| start_call(&video, true, cx)),
139 )
140 };
141 popup.item(
142 PopupMenuItem::new(AUDIO_CALL_LABEL)
143 .icon(menu_icon(IconName::Phone))
144 .action(Box::new(StartAudioCall))
145 .on_click(move |_, _, cx| start_call(&audio, false, cx)),
146 )
147 }),
148 )
149 .into_any_element()
150}