BlueGit

ict rusty-teams

Files

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

call_people.rs

call_people.rs 24.1 KiB Download Raw
1use gpui_kit::component::scroll::ScrollableElement as _;
2use gpui_kit::assets::IconName;
3use gpui_kit::component::{
4 Sizable as _,
5 button::{Button, ButtonVariants as _},
6 h_flex,
7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
8 switch::Switch,
9 tooltip::Tooltip,
10 v_flex,
11};
12use gpui_kit::prelude::FluentBuilder as _;
13use gpui_kit::*;
14
15use super::avatar::person_avatar;
16use super::call_extras::open_invite_picker;
17use super::call_organizer::{pill, tile_menu};
18use super::call_view::{BANNER_HEIGHT, CHAT_PANEL_WIDTH, MENU_WIDTH, round_control};
19use super::widgets::{Corner, corner_badge, count_badge, icon};
20use super::scroll_edge::with_top_edge;
21use crate::app_state::AppState;
22use crate::call::{
23 ActiveCall, CallModel, OptionsDialog, PeopleSections, PersonRow, people_sections,
24};
25use crate::notice::truncated;
26use crate::theme::{self, ElevatedSurface as _};
27use calling::MeetingOptions;
28
29const HEADER_HEIGHT: f32 = 48.;
30const PEOPLE_SCROLL_DIVIDER: &str = "shell/islands/main/call-people/divider-scroll";
31const ROW_HEIGHT: f32 = 44.;
32const AVATAR_SIZE: f32 = 28.;
33const MORE_SIZE: f32 = 24.;
34const SECTION_HEIGHT: f32 = 32.;
35const NAME_LIMIT: usize = 26;
36const STATE_ICON: f32 = 15.;
37const DIALOG_WIDTH: f32 = 460.;
38const DIALOG_BACKDROP: f32 = 0.55;
39const FIELD_HEIGHT: f32 = 36.;
40const DROPDOWN_WIDTH: f32 = 210.;
41
42fn dark_text() -> Hsla {
43 hsla(0., 0., 0.08, 1.)
44}
45
46pub fn people_button(app: &Entity<AppState>, open: bool, raised_hands: usize) -> Stateful<Div> {
47 let app = app.clone();
48 let (background, foreground) = if open {
49 (theme::accent(), theme::on_accent())
50 } else {
51 (theme::surface_raised(), theme::text())
52 };
53 round_control("call-people", IconName::Users, background, foreground)
54 .relative()
55 .tooltip(move |window, cx| {
56 Tooltip::new(if open { "Close the people list" } else { "Show people" }).build(window, cx)
57 })
58 .when(raised_hands > 0, |button| {
59 button.child(
60 corner_badge(Corner::TopRight, 4.).child(count_badge(raised_hands as u32, false)),
61 )
62 })
63 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_people(cx)))
64}
65
66pub fn lock_chip(model: &CallModel) -> Option<AnyElement> {
67 model.capability.locked.then(|| {
68 h_flex()
69 .id("call-lock-chip")
70 .h(px(24.))
71 .px(px(8.))
72 .gap(px(4.))
73 .flex_none()
74 .items_center()
75 .rounded_full()
76 .bg(theme::amber())
77 .text_color(dark_text())
78 .text_size(px(12.))
79 .font_weight(FontWeight::SEMIBOLD)
80 .child(icon(IconName::Lock, 13., dark_text()))
81 .child("Locked")
82 .into_any_element()
83 })
84}
85
86pub fn lock_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
87 if !model.capability.locked || !model.organizes_meeting() {
88 return None;
89 }
90 let app = app.clone();
91 Some(
92 h_flex()
93 .id("call-lock-banner")
94 .w_full()
95 .h(px(BANNER_HEIGHT))
96 .flex_none()
97 .px(px(20.))
98 .gap(px(12.))
99 .items_center()
100 .justify_center()
101 .bg(theme::surface_raised())
102 .text_color(theme::text())
103 .text_size(px(13.))
104 .font_weight(FontWeight::SEMIBOLD)
105 .child("The meeting is locked. Nobody new can join.")
106 .child(
107 pill("call-lock-unlock", "Unlock", false)
108 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_lock(false, cx))),
109 )
110 .into_any_element(),
111 )
112}
113
114fn people_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
115 let popup = popup.min_w(px(MENU_WIDTH));
116 if !model.organizes_meeting() {
117 return popup;
118 }
119 let capability = model.capability;
120 let (mute_app, lock_app, mic_app, camera_app, options_app) =
121 (app.clone(), app.clone(), app.clone(), app.clone(), app.clone());
122 popup
123 .item(
124 PopupMenuItem::new("Mute all")
125 .icon(IconName::MicOff)
126 .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))),
127 )
128 .item(
129 PopupMenuItem::new(if capability.locked { "Unlock meeting" } else { "Lock meeting" })
130 .icon(if capability.locked { IconName::LockOpen } else { IconName::Lock })
131 .on_click(move |_, _, cx| {
132 lock_app.update(cx, |state, cx| state.set_call_lock(!capability.locked, cx))
133 }),
134 )
135 .item(
136 PopupMenuItem::new(if capability.attendee_mic_off {
137 "Allow mic for attendees"
138 } else {
139 "Disable mic for attendees"
140 })
141 .icon(IconName::MicOff)
142 .on_click(move |_, _, cx| {
143 mic_app.update(cx, |state, cx| {
144 state.set_call_attendee_restrictions(
145 !capability.attendee_mic_off,
146 capability.attendee_camera_off,
147 cx,
148 )
149 })
150 }),
151 )
152 .item(
153 PopupMenuItem::new(if capability.attendee_camera_off {
154 "Allow camera for attendees"
155 } else {
156 "Disable camera for attendees"
157 })
158 .icon(IconName::VideoOff)
159 .on_click(move |_, _, cx| {
160 camera_app.update(cx, |state, cx| {
161 state.set_call_attendee_restrictions(
162 capability.attendee_mic_off,
163 !capability.attendee_camera_off,
164 cx,
165 )
166 })
167 }),
168 )
169 .separator()
170 .item(
171 PopupMenuItem::new("Meeting options...")
172 .icon(IconName::Settings)
173 .on_click(move |_, _, cx| {
174 options_app.update(cx, |state, cx| state.open_meeting_options(cx))
175 }),
176 )
177}
178
179fn has_people_menu(model: &CallModel) -> bool {
180 model.organizes_meeting()
181}
182
183fn panel_header(app: &Entity<AppState>, model: &CallModel, count: usize) -> Div {
184 let (invite_app, menu_app, close_app) = (app.clone(), app.clone(), app.clone());
185 let menu_model = model.clone();
186 h_flex()
187 .w_full()
188 .h(px(HEADER_HEIGHT))
189 .flex_none()
190 .pl(px(20.))
191 .pr(px(12.))
192 .gap(px(8.))
193 .items_center()
194 .child(
195 div()
196 .flex_1()
197 .min_w_0()
198 .truncate()
199 .text_size(px(15.))
200 .font_weight(FontWeight::SEMIBOLD)
201 .child(format!("People ({count})")),
202 )
203 .when(model.can_invite(), |header| {
204 header.child(
205 Button::new("call-people-invite")
206 .label("Invite")
207 .icon(IconName::UserPlus)
208 .xsmall()
209 .on_click(move |_, window, cx| open_invite_picker(&invite_app, window, cx)),
210 )
211 })
212 .when(has_people_menu(model), |header| {
213 header.child(
214 Button::new("call-people-more")
215 .icon(IconName::Ellipsis)
216 .ghost()
217 .xsmall()
218 .tooltip("More")
219 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
220 people_menu(popup, &menu_app, &menu_model)
221 }),
222 )
223 })
224 .child(
225 div()
226 .id("call-people-close")
227 .size(px(28.))
228 .flex()
229 .flex_none()
230 .items_center()
231 .justify_center()
232 .rounded(px(7.))
233 .cursor_pointer()
234 .hover(|button| button.bg(theme::row_hover()))
235 .tooltip(|window, cx| Tooltip::new("Close the people list").build(window, cx))
236 .child(icon(IconName::Close, 14., theme::text_muted()))
237 .on_click(move |_, _, cx| close_app.update(cx, |state, cx| state.toggle_call_people(cx))),
238 )
239}
240
241fn section_header(title: String, action: Option<AnyElement>) -> Div {
242 h_flex()
243 .w_full()
244 .h(px(SECTION_HEIGHT))
245 .flex_none()
246 .px(px(20.))
247 .items_center()
248 .justify_between()
249 .text_size(px(12.))
250 .font_weight(FontWeight::SEMIBOLD)
251 .text_color(theme::text_muted())
252 .child(title)
253 .children(action)
254}
255
256fn hand_badge(position: usize) -> Div {
257 h_flex()
258 .h(px(20.))
259 .px(px(6.))
260 .gap(px(3.))
261 .flex_none()
262 .items_center()
263 .rounded_full()
264 .bg(theme::amber())
265 .text_color(dark_text())
266 .text_size(px(11.))
267 .font_weight(FontWeight::SEMIBOLD)
268 .child(icon(IconName::Hand, 11., dark_text()))
269 .child(position.to_string())
270}
271
272fn mic_icon(row: &PersonRow) -> impl IntoElement {
273 if row.mic_blocked {
274 icon(IconName::MicOff, STATE_ICON, theme::red())
275 } else if row.muted {
276 icon(IconName::MicOff, STATE_ICON, theme::text_muted())
277 } else {
278 icon(IconName::Mic, STATE_ICON, theme::text())
279 }
280}
281
282fn camera_icon(row: &PersonRow) -> impl IntoElement {
283 if row.camera_blocked {
284 icon(IconName::VideoOff, STATE_ICON, theme::red())
285 } else if row.camera_on {
286 icon(IconName::Video, STATE_ICON, theme::text())
287 } else {
288 icon(IconName::VideoOff, STATE_ICON, theme::text_muted())
289 }
290}
291
292fn person_row(
293 app: &Entity<AppState>,
294 state: &AppState,
295 model: &CallModel,
296 section: &'static str,
297 row: &PersonRow,
298) -> AnyElement {
299 let group = SharedString::from(format!("call-people-{section}-{}", row.mri));
300 let user_id = row
301 .user_id
302 .clone()
303 .or_else(|| {
304 row.own
305 .then(|| state.directory.me.as_ref().map(|me| me.user_id.clone()))
306 .flatten()
307 });
308 let subtitle = if row.ringing { Some("Ringing") } else { row.label };
309 let (more_app, more_model, more_mri, more_name) =
310 (app.clone(), model.clone(), row.mri.clone(), row.name.clone());
311 h_flex()
312 .id(SharedString::from(format!("call-people-row-{section}-{}", row.mri)))
313 .group(group.clone())
314 .w_full()
315 .h(px(ROW_HEIGHT))
316 .flex_none()
317 .px(px(20.))
318 .gap(px(8.))
319 .items_center()
320 .hover(|row| row.bg(theme::row_hover()))
321 .child(person_avatar(&state.directory, user_id.as_deref(), &row.name, AVATAR_SIZE))
322 .child(
323 v_flex()
324 .flex_1()
325 .min_w_0()
326 .child(
327 div()
328 .truncate()
329 .text_size(px(13.))
330 .font_weight(FontWeight::SEMIBOLD)
331 .child(truncated(&row.name, NAME_LIMIT)),
332 )
333 .children(subtitle.map(|text| {
334 div()
335 .truncate()
336 .text_size(px(11.))
337 .text_color(theme::text_muted())
338 .child(text)
339 })),
340 )
341 .children(row.hand.map(hand_badge))
342 .child(mic_icon(row))
343 .child(camera_icon(row))
344 .child(
345 div()
346 .size(px(MORE_SIZE))
347 .flex_none()
348 .when(!row.own, |slot| {
349 slot.opacity(0.)
350 .group_hover(group, |slot| slot.opacity(1.))
351 .child(
352 Button::new(SharedString::from(format!(
353 "call-people-more-{section}-{}",
354 row.mri
355 )))
356 .icon(IconName::Ellipsis)
357 .ghost()
358 .xsmall()
359 .size(px(MORE_SIZE))
360 .tooltip("More")
361 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
362 tile_menu(popup, &more_app, &more_model, &more_mri, &more_name, false)
363 }),
364 )
365 }),
366 )
367 .into_any_element()
368}
369
370fn lobby_section(app: &Entity<AppState>, state: &AppState, sections: &PeopleSections) -> Option<Div> {
371 if sections.lobby.is_empty() {
372 return None;
373 }
374 let admit_all_app = app.clone();
375 let action = Button::new("call-people-admit-all")
376 .label("Admit all")
377 .ghost()
378 .xsmall()
379 .on_click(move |_, _, cx| admit_all_app.update(cx, |state, cx| state.admit_all_call_guests(cx)))
380 .into_any_element();
381 Some(
382 v_flex()
383 .w_full()
384 .child(section_header(format!("Waiting in lobby ({})", sections.lobby.len()), Some(action)))
385 .children(sections.lobby.iter().map(|guest| {
386 let (admit_app, deny_app) = (app.clone(), app.clone());
387 let (admit_mri, deny_mri) = (guest.mri.clone(), guest.mri.clone());
388 h_flex()
389 .id(SharedString::from(format!("call-people-lobby-{}", guest.mri)))
390 .w_full()
391 .h(px(ROW_HEIGHT))
392 .flex_none()
393 .px(px(20.))
394 .gap(px(8.))
395 .items_center()
396 .child(person_avatar(&state.directory, guest.user_id.as_deref(), &guest.name, AVATAR_SIZE))
397 .child(
398 div()
399 .flex_1()
400 .min_w_0()
401 .truncate()
402 .text_size(px(13.))
403 .font_weight(FontWeight::SEMIBOLD)
404 .child(truncated(&guest.name, NAME_LIMIT)),
405 )
406 .child(
407 Button::new(SharedString::from(format!("call-people-admit-{}", guest.mri)))
408 .label("Admit")
409 .xsmall()
410 .on_click(move |_, _, cx| {
411 admit_app.update(cx, |state, cx| state.admit_call_guest(admit_mri.clone(), cx))
412 }),
413 )
414 .child(
415 Button::new(SharedString::from(format!("call-people-deny-{}", guest.mri)))
416 .label("Deny")
417 .ghost()
418 .xsmall()
419 .on_click(move |_, _, cx| {
420 deny_app.update(cx, |state, cx| state.deny_call_guest(deny_mri.clone(), cx))
421 }),
422 )
423 })),
424 )
425}
426
427pub fn people_panel(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> {
428 call.people_open.then_some(())?;
429 let model = &call.model;
430 let sections = people_sections(model);
431 let lower_all = model.can_lower_hands().then(|| {
432 let app = app.clone();
433 Button::new("call-people-lower-all")
434 .label("Lower all")
435 .ghost()
436 .xsmall()
437 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.lower_all_call_hands(cx)))
438 .into_any_element()
439 });
440 let body = v_flex()
441 .id("call-people-list")
442 .flex_1()
443 .min_h_0()
444 .w_full()
445 .overflow_y_scrollbar()
446 .track_scroll(&call.people_scroll)
447 .pb(px(12.))
448 .children(model.can_admit().then(|| lobby_section(app, state, &sections)).flatten())
449 .when(!sections.hands.is_empty(), |list| {
450 list.child(section_header(format!("Raised hands ({})", sections.hands.len()), lower_all))
451 .children(
452 sections
453 .hands
454 .iter()
455 .map(|row| person_row(app, state, model, "hands", row)),
456 )
457 })
458 .children(sections.groups.iter().map(|group| {
459 v_flex()
460 .w_full()
461 .child(section_header(format!("{} ({})", group.title, group.rows.len()), None))
462 .children(group.rows.iter().map(|row| person_row(app, state, model, "group", row)))
463 }));
464 Some(
465 v_flex()
466 .id("call-people-panel")
467 .debug_selector(|| "shell/islands/main/call-people".into())
468 .w(px(CHAT_PANEL_WIDTH))
469 .h_full()
470 .flex_shrink(1.)
471 .min_w_0()
472 .rounded(px(10.))
473 .overflow_hidden()
474 .bg(theme::surface())
475 .child(panel_header(app, model, sections.count))
476 .child(with_top_edge(body, &call.people_scroll, PEOPLE_SCROLL_DIVIDER))
477 .into_any_element(),
478 )
479}
480
481fn choice_label(choices: &[(&str, &str)], value: &str) -> String {
482 choices
483 .iter()
484 .find(|(wire, _)| *wire == value)
485 .map_or_else(|| value.to_owned(), |(_, label)| (*label).to_owned())
486}
487
488fn choice_dropdown(
489 id: &'static str,
490 app: &Entity<AppState>,
491 choices: &'static [(&'static str, &'static str)],
492 current: &str,
493 edit: fn(&mut MeetingOptions, &str),
494) -> AnyElement {
495 let app = app.clone();
496 let current = current.to_owned();
497 Button::new(id)
498 .label(choice_label(choices, &current))
499 .icon(IconName::ChevronDown)
500 .ghost()
501 .h(px(FIELD_HEIGHT))
502 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
503 let mut popup = popup.min_w(px(DROPDOWN_WIDTH));
504 if !choices.iter().any(|(wire, _)| *wire == current) {
505 popup = popup.item(PopupMenuItem::new(current.clone()).checked(true));
506 }
507 for (wire, label) in choices {
508 let app = app.clone();
509 popup = popup.item(PopupMenuItem::new(*label).checked(*wire == current).on_click(
510 move |_, _, cx| {
511 app.update(cx, |state, cx| {
512 state.edit_meeting_options(|options| edit(options, wire), cx)
513 })
514 },
515 ));
516 }
517 popup
518 })
519 .into_any_element()
520}
521
522fn switch_field(
523 id: &'static str,
524 app: &Entity<AppState>,
525 on: bool,
526 edit: fn(&mut MeetingOptions, bool),
527) -> AnyElement {
528 let app = app.clone();
529 Switch::new(id)
530 .checked(on)
531 .on_click(move |checked, _, cx| {
532 let checked = *checked;
533 app.update(cx, |state, cx| {
534 state.edit_meeting_options(|options| edit(options, checked), cx)
535 })
536 })
537 .into_any_element()
538}
539
540fn option_row(label: &'static str, control: AnyElement) -> Div {
541 h_flex()
542 .w_full()
543 .min_h(px(FIELD_HEIGHT))
544 .gap(px(12.))
545 .items_center()
546 .justify_between()
547 .child(div().flex_1().min_w_0().text_size(px(14.)).child(label))
548 .child(control)
549}
550
551fn options_fields(app: &Entity<AppState>, options: &MeetingOptions) -> Div {
552 use calling::meeting_options::{BYPASS_CHOICES, CHAT_CHOICES, PRESENTER_CHOICES};
553 v_flex()
554 .w_full()
555 .gap(px(6.))
556 .child(option_row(
557 "Who can bypass the lobby",
558 choice_dropdown("options-bypass", app, &BYPASS_CHOICES, &options.bypass_lobby, |options, value| {
559 options.bypass_lobby = value.to_owned()
560 }),
561 ))
562 .child(option_row(
563 "Who can present",
564 choice_dropdown("options-present", app, &PRESENTER_CHOICES, &options.presenters, |options, value| {
565 options.presenters = value.to_owned()
566 }),
567 ))
568 .child(option_row(
569 "Allow mic for attendees",
570 switch_field("options-mic", app, options.attendee_mic, |options, on| options.attendee_mic = on),
571 ))
572 .child(option_row(
573 "Allow camera for attendees",
574 switch_field("options-camera", app, options.attendee_camera, |options, on| {
575 options.attendee_camera = on
576 }),
577 ))
578 .child(option_row(
579 "Meeting chat",
580 choice_dropdown("options-chat", app, &CHAT_CHOICES, &options.meeting_chat, |options, value| {
581 options.meeting_chat = value.to_owned()
582 }),
583 ))
584 .child(option_row(
585 "Allow reactions",
586 switch_field("options-reactions", app, options.reactions, |options, on| options.reactions = on),
587 ))
588 .child(option_row(
589 "Record automatically",
590 switch_field("options-record", app, options.record_automatically, |options, on| {
591 options.record_automatically = on
592 }),
593 ))
594}
595
596fn dialog_body(app: &Entity<AppState>, dialog: &OptionsDialog) -> Div {
597 let body = v_flex().w_full().gap(px(12.));
598 let body = match &dialog.draft {
599 Some(draft) => body.child(options_fields(app, draft)),
600 None if dialog.is_loading() => body.child(
601 div()
602 .text_size(px(13.))
603 .text_color(theme::text_muted())
604 .child("Loading the meeting options..."),
605 ),
606 None => body,
607 };
608 body.children(dialog.error.as_ref().map(|error| {
609 div()
610 .id("options-error")
611 .w_full()
612 .text_size(px(13.))
613 .text_color(theme::red())
614 .child(error.clone())
615 }))
616}
617
618pub fn options_dialog(app: &Entity<AppState>, call: &ActiveCall) -> Option<AnyElement> {
619 let dialog = call.options_dialog.as_ref()?;
620 let (close_app, cancel_app, save_app) = (app.clone(), app.clone(), app.clone());
621 let can_save = dialog.can_save();
622 let save = Button::new("options-save")
623 .label(if dialog.saving { "Saving..." } else { "Save" })
624 .when(!can_save, |button| button.opacity(0.4))
625 .on_click(move |_, _, cx| {
626 if can_save {
627 save_app.update(cx, |state, cx| state.save_meeting_options(cx))
628 }
629 });
630 Some(
631 div()
632 .id("options-layer")
633 .absolute()
634 .top_0()
635 .left_0()
636 .size_full()
637 .flex()
638 .items_center()
639 .justify_center()
640 .child(
641 div()
642 .id("options-backdrop")
643 .absolute()
644 .top_0()
645 .left_0()
646 .size_full()
647 .bg(black().opacity(DIALOG_BACKDROP))
648 .occlude()
649 .on_click(move |_, _, cx| close_app.update(cx, |state, cx| state.close_meeting_options(cx))),
650 )
651 .child(
652 v_flex()
653 .id("options-card")
654 .w(px(DIALOG_WIDTH))
655 .max_w(relative(1.))
656 .p(px(16.))
657 .gap(px(12.))
658 .rounded(px(12.))
659 .dialog_surface()
660 .text_color(theme::text())
661 .occlude()
662 .child(
663 div()
664 .text_size(px(15.))
665 .font_weight(FontWeight::SEMIBOLD)
666 .child("Meeting options"),
667 )
668 .child(dialog_body(app, dialog))
669 .child(
670 h_flex()
671 .w_full()
672 .justify_end()
673 .gap(px(8.))
674 .child(
675 Button::new("options-cancel")
676 .label("Cancel")
677 .ghost()
678 .on_click(move |_, _, cx| {
679 cancel_app.update(cx, |state, cx| state.close_meeting_options(cx))
680 }),
681 )
682 .child(save),
683 ),
684 )
685 .into_any_element(),
686 )
687}