| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::{ |
| 3 | button::{Button, ButtonVariants as _}, |
| 4 | h_flex, |
| 5 | menu::{DropdownMenu as _, PopupMenuItem}, |
| 6 | }; |
| 7 | use gpui_kit::prelude::FluentBuilder as _; |
| 8 | use gpui_kit::*; |
| 9 | |
| 10 | use super::shortcuts::{StartAudioCall, StartVideoCall}; |
| 11 | use super::widgets::{icon, menu_icon}; |
| 12 | use crate::app_state::{AppState, Selection}; |
| 13 | use crate::call::{is_echo_chat, plan_for_chat}; |
| 14 | use crate::theme; |
| 15 | |
| 16 | const BUTTON_SIZE: f32 = 30.; |
| 17 | const GLYPH_SIZE: f32 = 16.; |
| 18 | const JOIN_HEIGHT: f32 = 30.; |
| 19 | const CHEVRON_WIDTH: f32 = 18.; |
| 20 | const CHEVRON_GLYPH: f32 = 12.; |
| 21 | pub const HEADER_VIDEO_CALL_TAG: &str = "header-video-call"; |
| 22 | pub const HEADER_CALL_OPTIONS_TAG: &str = "header-call-options"; |
| 23 | const VIDEO_CALL_LABEL: &str = "Video call"; |
| 24 | const AUDIO_CALL_LABEL: &str = "Audio call"; |
| 25 | const CALL_OPTIONS_LABEL: &str = "Call options"; |
| 26 | const MEET_NOW_LABEL: &str = "Meet now"; |
| 27 | const GROUP_KIND: &str = "group"; |
| 28 | |
| 29 | pub 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 | |
| 77 | fn 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 | |
| 89 | fn 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 | } |