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};
 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 workspace::AppState;
 25
 26actions!(
 27    collab,
 28    [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
 29);
 30
 31pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
 32    CollaborationPanelSettings::register(cx);
 33    ChatPanelSettings::register(cx);
 34    NotificationPanelSettings::register(cx);
 35
 36    vcs_menu::init(cx);
 37    collab_titlebar_item::init(cx);
 38    collab_panel::init(cx);
 39    channel_view::init(cx);
 40    chat_panel::init(cx);
 41    notification_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                );
 61                Task::ready(room.unshare_screen(cx))
 62            } else {
 63                report_call_event_for_room(
 64                    "enable screen share",
 65                    room.id(),
 66                    room.channel_id(),
 67                    &client,
 68                );
 69                room.share_screen(cx)
 70            }
 71        });
 72        toggle_screen_sharing.detach_and_log_err(cx);
 73    }
 74}
 75
 76pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
 77    let call = ActiveCall::global(cx).read(cx);
 78    if let Some(room) = call.room().cloned() {
 79        let client = call.client();
 80        room.update(cx, |room, cx| {
 81            let operation = if room.is_muted() {
 82                "enable microphone"
 83            } else {
 84                "disable microphone"
 85            };
 86            report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
 87
 88            room.toggle_mute(cx)
 89        });
 90    }
 91}
 92
 93pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
 94    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
 95        room.update(cx, |room, cx| room.toggle_deafen(cx));
 96    }
 97}
 98
 99fn notification_window_options(
100    screen: Rc<dyn PlatformDisplay>,
101    window_size: Size<Pixels>,
102) -> WindowOptions {
103    let notification_margin_width = GlobalPixels::from(16.);
104    let notification_margin_height = GlobalPixels::from(-0.) - GlobalPixels::from(48.);
105
106    let screen_bounds = screen.bounds();
107    let size: Size<GlobalPixels> = window_size.into();
108
109    let bounds = gpui::Bounds::<GlobalPixels> {
110        origin: screen_bounds.upper_right()
111            - point(
112                size.width + notification_margin_width,
113                notification_margin_height,
114            ),
115        size: window_size.into(),
116    };
117    WindowOptions {
118        bounds: WindowBounds::Fixed(bounds),
119        titlebar: None,
120        center: false,
121        focus: false,
122        show: true,
123        kind: WindowKind::PopUp,
124        is_movable: false,
125        display_id: Some(screen.id()),
126    }
127}
128
129// fn render_avatar<T: 'static>(
130//     avatar: Option<Arc<ImageData>>,
131//     avatar_style: &AvatarStyle,
132//     container: ContainerStyle,
133// ) -> AnyElement<T> {
134//     avatar
135//         .map(|avatar| {
136//             Image::from_data(avatar)
137//                 .with_style(avatar_style.image)
138//                 .aligned()
139//                 .contained()
140//                 .with_corner_radius(avatar_style.outer_corner_radius)
141//                 .constrained()
142//                 .with_width(avatar_style.outer_width)
143//                 .with_height(avatar_style.outer_width)
144//                 .into_any()
145//         })
146//         .unwrap_or_else(|| {
147//             Empty::new()
148//                 .constrained()
149//                 .with_width(avatar_style.outer_width)
150//                 .into_any()
151//         })
152//         .contained()
153//         .with_style(container)
154//         .into_any()
155// }
156
157fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
158    cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
159}