| 1 | use calling::AcceptMode; |
| 2 | use gpui_kit::*; |
| 3 | use teams_core::{ForcedAvailability, ForcedKind}; |
| 4 | |
| 5 | use super::AppShell; |
| 6 | use crate::app_state::AppState; |
| 7 | use crate::sidebar_model::Step; |
| 8 | use crate::views::shortcuts::{ |
| 9 | AcceptAudioCall, AcceptCall, GoToComposeBox, NextUnreadConversation, |
| 10 | PreviousUnreadConversation, ReplyToLastMessage, SetPresenceAvailable, SetPresenceAway, |
| 11 | SetPresenceBeRightBack, SetPresenceBusy, SetPresenceDoNotDisturb, ToggleBackgroundBlur, |
| 12 | ToggleLiveCaptions, |
| 13 | }; |
| 14 | |
| 15 | fn 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 | |
| 23 | fn 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 | |
| 31 | impl 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.update(cx, |conversation, cx| { |
| 37 | conversation.focus_composer(window, cx) |
| 38 | }); |
| 39 | })) |
| 40 | .on_action(cx.listener(|this, _: &ReplyToLastMessage, window, cx| { |
| 41 | this.close_image_viewer(window, cx); |
| 42 | this.conversation.update(cx, |conversation, cx| { |
| 43 | conversation.reply_to_latest_from_others(window, cx) |
| 44 | }); |
| 45 | })) |
| 46 | .on_action( |
| 47 | cx.listener(|this, _: &PreviousUnreadConversation, window, cx| { |
| 48 | this.close_image_viewer(window, cx); |
| 49 | this.select_unread(Step::Previous, cx); |
| 50 | }), |
| 51 | ) |
| 52 | .on_action(cx.listener(|this, _: &NextUnreadConversation, window, cx| { |
| 53 | this.close_image_viewer(window, cx); |
| 54 | this.select_unread(Step::Next, cx); |
| 55 | })) |
| 56 | .on_action(presence_listener::<SetPresenceAvailable>( |
| 57 | &self.state, |
| 58 | ForcedKind::Available, |
| 59 | )) |
| 60 | .on_action(presence_listener::<SetPresenceBusy>( |
| 61 | &self.state, |
| 62 | ForcedKind::Busy, |
| 63 | )) |
| 64 | .on_action(presence_listener::<SetPresenceDoNotDisturb>( |
| 65 | &self.state, |
| 66 | ForcedKind::DoNotDisturb, |
| 67 | )) |
| 68 | .on_action(presence_listener::<SetPresenceBeRightBack>( |
| 69 | &self.state, |
| 70 | ForcedKind::BeRightBack, |
| 71 | )) |
| 72 | .on_action(presence_listener::<SetPresenceAway>( |
| 73 | &self.state, |
| 74 | ForcedKind::Away, |
| 75 | )) |
| 76 | .on_action(cx.listener(|this, _: &AcceptCall, _, cx| { |
| 77 | this.state.update(cx, |state, cx| { |
| 78 | state.accept_ringing_call(AcceptMode::Video, cx) |
| 79 | }); |
| 80 | })) |
| 81 | .on_action(cx.listener(|this, _: &AcceptAudioCall, _, cx| { |
| 82 | this.state.update(cx, |state, cx| { |
| 83 | state.accept_ringing_call(AcceptMode::Audio, cx) |
| 84 | }); |
| 85 | })) |
| 86 | .on_action(cx.listener(|this, _: &ToggleBackgroundBlur, _, cx| { |
| 87 | this.state |
| 88 | .update(cx, |state, cx| state.toggle_call_background_blur(cx)); |
| 89 | })) |
| 90 | .on_action(cx.listener(|this, _: &ToggleLiveCaptions, _, cx| { |
| 91 | this.state |
| 92 | .update(cx, |state, cx| state.toggle_call_captions(cx)); |
| 93 | })) |
| 94 | } |
| 95 | |
| 96 | fn select_unread(&mut self, step: Step, cx: &mut Context<Self>) { |
| 97 | let target = self.state.read(cx).adjacent_unread_chat_id(step); |
| 98 | if let Some(chat_id) = target { |
| 99 | self.sidebar |
| 100 | .update(cx, |sidebar, cx| sidebar.show_chats(cx)); |
| 101 | self.state.update(cx, |state, cx| { |
| 102 | state.select(crate::app_state::Selection::Chat(chat_id), cx) |
| 103 | }); |
| 104 | } |
| 105 | } |
| 106 | } |