BlueGit

ict rusty-teams

Files

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

call_people.rs

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