forge
Explore
Log in

Don't you dare go Hollow

yumush

Clone
★ 0

0 watching0 forksRustAGPL-3.07.2 MiB4b67e80Tahinli1 hour ago400 commits

dock.rs103 lines, 3.7 KiBHistoryRawDownload
1use std::rc::Rc;
2
3use common::share::Kind;
4use gpui_kit::{App, Entity, IntoElement};
5
6use super::{
7 Palette, Yumush,
8 call_bar::{self, CallActions, CallBar},
9 chat::VoiceState,
10 entity_action,
11 parts::Voice,
12 style::Tokens,
13 voice_stats::{self, Quality},
14};
15
16impl Yumush {
17 pub(super) fn dock(
18 &self,
19 entity: &Entity<Self>,
20 palette: Palette,
21 cx: &App,
22 ) -> Option<impl IntoElement> {
23 let community = self.chat.voice_room()?;
24 let VoiceState::In { .. } = &self.chat.voice_state else {
25 return None;
26 };
27 let (muted, deafened) = self.chat.voice_flags()?;
28 let user = self.user.as_ref()?;
29 let me = user.id;
30 let t = Tokens::of(cx);
31 let frayed = voice_stats::quality(&self.chat.stats.voice) == Some(Quality::Poor);
32 let voice = if frayed {
33 Voice::Frayed
34 } else if !muted && self.chat.waves.speaking.contains(&me) {
35 Voice::Live(t.person(me))
36 } else {
37 Voice::Quiet
38 };
39 let bar = CallBar {
40 place: super::community_name(community).to_string().into(),
41 bands: self.chat.waves.voice(me).cloned(),
42 voice,
43 quality: super::voice_stats::quality(&self.chat.stats.voice),
44 pings: self
45 .chat
46 .stats
47 .voice
48 .iter()
49 .map(|sample| sample.ping_ms)
50 .collect(),
51 muted,
52 deafened,
53 camera: self.network.share_source(Kind::Camera).is_some(),
54 screen: self.network.share_source(Kind::Screen).is_some(),
55 ghost: self.chat.ghost,
56 share: self
57 .network
58 .share_source(Kind::Screen)
59 .map(|_| (self.chat.waves.share(me).cloned(), t.person(me))),
60 stats: self.chat.stats_at == Some(super::chat::StatsAt::Dock),
61 };
62 let go_id = community.id;
63 let actions = CallActions {
64 go: Rc::new(entity_action(entity, move |yumush, window, cx| {
65 yumush.select_community(go_id, window, cx);
66 })),
67 mute: Rc::new(entity_action(entity, |yumush, window, cx| {
68 yumush.toggle_mute(window, cx)
69 })),
70 deafen: Rc::new(entity_action(entity, |yumush, _, cx| {
71 yumush.toggle_deafen(cx)
72 })),
73 camera: Rc::new(entity_action(entity, |yumush, window, cx| {
74 yumush.toggle_camera(window, cx)
75 })),
76 screen: Rc::new(entity_action(entity, |yumush, window, cx| {
77 yumush.toggle_share(window, cx)
78 })),
79 leave: Rc::new(entity_action(entity, |yumush, _, cx| {
80 yumush.end_voice(cx);
81 cx.notify();
82 })),
83 stats: Rc::new(entity_action(entity, move |yumush, window, cx| {
84 yumush.select_community(go_id, window, cx);
85 yumush.toggle_stats(super::chat::StatsAt::Dock);
86 cx.notify();
87 })),
88 mic_more: self
89 .audio_button(entity, palette, super::voice_settings::Side::Input, cx)
90 .into_any_element(),
91 speaker_more: self
92 .audio_button(entity, palette, super::voice_settings::Side::Output, cx)
93 .into_any_element(),
94 camera_more: self
95 .share_settings_button(entity, palette, Kind::Camera, cx)
96 .into_any_element(),
97 screen_more: self
98 .share_settings_button(entity, palette, Kind::Screen, cx)
99 .into_any_element(),
100 };
101 Some(call_bar::view(bar, actions, t))
102 }
103}