BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / shell / team_keys.rs

team_keys.rs

e7ea3d7f History
team_keys.rs 3.8 KiB Download Raw
1use calling::AcceptMode;
2use gpui_kit::*;
3use teams_core::{ForcedAvailability, ForcedKind};
4
5use super::AppShell;
6use crate::app_state::AppState;
7use crate::sidebar_model::Step;
8use crate::views::shortcuts::{
9 AcceptAudioCall, AcceptCall, GoToComposeBox, NextUnreadConversation,
10 PreviousUnreadConversation, ReplyToLastMessage, SetPresenceAvailable, SetPresenceAway,
11 SetPresenceBeRightBack, SetPresenceBusy, SetPresenceDoNotDisturb, ToggleBackgroundBlur,
12 ToggleLiveCaptions,
13};
14
15fn force_presence(state: &Entity<AppState>, kind: ForcedKind, cx: &mut App) {
16 let forced = ForcedAvailability {
17 kind,
18 expires_at: None,
19 };
20 state.update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
21}
22
23fn presence_listener<A: Action>(
24 state: &Entity<AppState>,
25 kind: ForcedKind,
26) -> impl Fn(&A, &mut Window, &mut App) + 'static {
27 let state = state.clone();
28 move |_, _, cx| force_presence(&state, kind, cx)
29}
30
31impl AppShell {
32 pub(super) fn team_keys(&self, shell: Stateful<Div>, cx: &mut Context<Self>) -> Stateful<Div> {
33 shell
34 .on_action(cx.listener(|this, _: &GoToComposeBox, window, cx| {
35 this.close_image_viewer(window, cx);
36 this.conversation
37 .update(cx, |conversation, cx| conversation.focus_composer(window, cx));
38 }))
39 .on_action(cx.listener(|this, _: &ReplyToLastMessage, window, cx| {
40 this.close_image_viewer(window, cx);
41 this.conversation.update(cx, |conversation, cx| {
42 conversation.reply_to_latest_from_others(window, cx)
43 });
44 }))
45 .on_action(cx.listener(|this, _: &PreviousUnreadConversation, window, cx| {
46 this.close_image_viewer(window, cx);
47 this.select_unread(Step::Previous, cx);
48 }))
49 .on_action(cx.listener(|this, _: &NextUnreadConversation, window, cx| {
50 this.close_image_viewer(window, cx);
51 this.select_unread(Step::Next, cx);
52 }))
53 .on_action(presence_listener::<SetPresenceAvailable>(&self.state, ForcedKind::Available))
54 .on_action(presence_listener::<SetPresenceBusy>(&self.state, ForcedKind::Busy))
55 .on_action(presence_listener::<SetPresenceDoNotDisturb>(
56 &self.state,
57 ForcedKind::DoNotDisturb,
58 ))
59 .on_action(presence_listener::<SetPresenceBeRightBack>(
60 &self.state,
61 ForcedKind::BeRightBack,
62 ))
63 .on_action(presence_listener::<SetPresenceAway>(&self.state, ForcedKind::Away))
64 .on_action(cx.listener(|this, _: &AcceptCall, _, cx| {
65 this.state
66 .update(cx, |state, cx| state.accept_ringing_call(AcceptMode::Video, cx));
67 }))
68 .on_action(cx.listener(|this, _: &AcceptAudioCall, _, cx| {
69 this.state
70 .update(cx, |state, cx| state.accept_ringing_call(AcceptMode::Audio, cx));
71 }))
72 .on_action(cx.listener(|this, _: &ToggleBackgroundBlur, _, cx| {
73 this.state
74 .update(cx, |state, cx| state.toggle_call_background_blur(cx));
75 }))
76 .on_action(cx.listener(|this, _: &ToggleLiveCaptions, _, cx| {
77 this.state
78 .update(cx, |state, cx| state.toggle_call_captions(cx));
79 }))
80 }
81
82 fn select_unread(&mut self, step: Step, cx: &mut Context<Self>) {
83 let target = self.state.read(cx).adjacent_unread_chat_id(step);
84 if let Some(chat_id) = target {
85 self.sidebar.update(cx, |sidebar, cx| sidebar.show_chats(cx));
86 self.state.update(cx, |state, cx| {
87 state.select(crate::app_state::Selection::Chat(chat_id), cx)
88 });
89 }
90 }
91}