BlueGit

ict rusty-teams

Files

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

call_people.rs

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