collab_ui.rs

  1pub mod channel_view;
  2pub mod chat_panel;
  3pub mod collab_panel;
  4mod collab_titlebar_item;
  5mod face_pile;
  6pub mod notification_panel;
  7pub mod notifications;
  8mod panel_settings;
  9
 10use std::{rc::Rc, sync::Arc};
 11
 12use call::{report_call_event_for_room, ActiveCall, Room};
 13pub use collab_panel::CollabPanel;
 14pub use collab_titlebar_item::CollabTitlebarItem;
 15use feature_flags::{ChannelsAlpha, FeatureFlagAppExt};
 16use gpui::{
 17    actions, point, AppContext, GlobalPixels, Pixels, PlatformDisplay, Size, Task, WindowBounds,
 18    WindowKind, WindowOptions,
 19};
 20pub use panel_settings::{
 21    ChatPanelSettings, CollaborationPanelSettings, NotificationPanelSettings,
 22};
 23use settings::Settings;
 24use util::ResultExt;
 25use workspace::AppState;
 26
 27actions!(
 28    collab,
 29    [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
 30);
 31
 32pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
 33    CollaborationPanelSettings::register(cx);
 34    ChatPanelSettings::register(cx);
 35    NotificationPanelSettings::register(cx);
 36
 37    // vcs_menu::init(cx);
 38    collab_titlebar_item::init(cx);
 39    collab_panel::init(cx);
 40    channel_view::init(cx);
 41    chat_panel::init(cx);
 42    notifications::init(&app_state, cx);
 43
 44    // cx.add_global_action(toggle_screen_sharing);
 45    // cx.add_global_action(toggle_mute);
 46    // cx.add_global_action(toggle_deafen);
 47}
 48
 49pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
 50    let call = ActiveCall::global(cx).read(cx);
 51    if let Some(room) = call.room().cloned() {
 52        let client = call.client();
 53        let toggle_screen_sharing = room.update(cx, |room, cx| {
 54            if room.is_screen_sharing() {
 55                report_call_event_for_room(
 56                    "disable screen share",
 57                    room.id(),
 58                    room.channel_id(),
 59                    &client,
 60                    cx,
 61                );
 62                Task::ready(room.unshare_screen(cx))
 63            } else {
 64                report_call_event_for_room(
 65                    "enable screen share",
 66                    room.id(),
 67                    room.channel_id(),
 68                    &client,
 69                    cx,
 70                );
 71                room.share_screen(cx)
 72            }
 73        });
 74        toggle_screen_sharing.detach_and_log_err(cx);
 75    }
 76}
 77
 78pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
 79    let call = ActiveCall::global(cx).read(cx);
 80    if let Some(room) = call.room().cloned() {
 81        let client = call.client();
 82        room.update(cx, |room, cx| {
 83            let operation = if room.is_muted(cx) {
 84                "enable microphone"
 85            } else {
 86                "disable microphone"
 87            };
 88            report_call_event_for_room(operation, room.id(), room.channel_id(), &client, cx);
 89
 90            room.toggle_mute(cx)
 91        })
 92        .map(|task| task.detach_and_log_err(cx))
 93        .log_err();
 94    }
 95}
 96
 97pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
 98    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
 99        room.update(cx, Room::toggle_deafen)
100            .map(|task| task.detach_and_log_err(cx))
101            .log_err();
102    }
103}
104
105fn notification_window_options(
106    screen: Rc<dyn PlatformDisplay>,
107    window_size: Size<Pixels>,
108) -> WindowOptions {
109    let notification_margin_width = GlobalPixels::from(16.);
110    let notification_margin_height = GlobalPixels::from(-0.) - GlobalPixels::from(48.);
111
112    let screen_bounds = screen.bounds();
113    let size: Size<GlobalPixels> = window_size.into();
114
115    // todo!() use content bounds instead of screen.bounds and get rid of magics in point's 2nd argument.
116    let bounds = gpui::Bounds::<GlobalPixels> {
117        origin: screen_bounds.upper_right()
118            - point(
119                size.width + notification_margin_width,
120                notification_margin_height,
121            ),
122        size: window_size.into(),
123    };
124    WindowOptions {
125        bounds: WindowBounds::Fixed(bounds),
126        titlebar: None,
127        center: false,
128        focus: false,
129        show: true,
130        kind: WindowKind::PopUp,
131        is_movable: false,
132        display_id: Some(screen.id()),
133    }
134}
135
136// fn render_avatar<T: 'static>(
137//     avatar: Option<Arc<ImageData>>,
138//     avatar_style: &AvatarStyle,
139//     container: ContainerStyle,
140// ) -> AnyElement<T> {
141//     avatar
142//         .map(|avatar| {
143//             Image::from_data(avatar)
144//                 .with_style(avatar_style.image)
145//                 .aligned()
146//                 .contained()
147//                 .with_corner_radius(avatar_style.outer_corner_radius)
148//                 .constrained()
149//                 .with_width(avatar_style.outer_width)
150//                 .with_height(avatar_style.outer_width)
151//                 .into_any()
152//         })
153//         .unwrap_or_else(|| {
154//             Empty::new()
155//                 .constrained()
156//                 .with_width(avatar_style.outer_width)
157//                 .into_any()
158//         })
159//         .contained()
160//         .with_style(container)
161//         .into_any()
162// }
163
164fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
165    cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
166}