BlueGit

ict rusty-teams

Files

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

call_people.rs

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