BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / call / calendar.rs

calendar.rs

calendar.rs 1.8 KiB Download Raw
1use chatsvc::CalendarEvent;
2use chrono::{Local, Offset, Utc};
3use gpui_kit::Context;
4
5use super::agenda::{AgendaRow, demo_events};
6use crate::app_state::{AppEvent, AppState, Selection};
7use crate::notify::selection_for;
8
9const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";
10
11impl AppState {
12 pub fn apply_calendar(&mut self, events: Vec<CalendarEvent>, cx: &mut Context<Self>) {
13 self.calendar_events = events;
14 self.calls_list.invalidate();
15 cx.emit(AppEvent::CallHistory);
16 cx.notify();
17 }
18
19 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
20 if self.mode.demo {
21 self.apply_calendar(demo_events(Utc::now()), cx);
22 return;
23 }
24 if let Some(nudge) = &self.calendar_nudge {
25 let _ = nudge.send(());
26 }
27 }
28
29 pub fn rebuild_calls_list(&mut self, cx: &mut Context<Self>) {
30 let now = Utc::now();
31 let offset = Local::now().offset().fix();
32 self.calls_list.rebuild(
33 &self.call_history,
34 &self.sidebar.chats,
35 &self.calendar_events,
36 now,
37 offset,
38 );
39 cx.emit(AppEvent::CallHistory);
40 cx.notify();
41 }
42
43 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
44 if let Some(url) = &row.join_url {
45 self.join_meeting_link(url, cx);
46 }
47 }
48
49 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
50 let Some(thread_id) = &row.thread_id else {
51 return;
52 };
53 match selection_for(&self.sidebar, thread_id) {
54 Some(selection @ Selection::Chat(_)) => self.select(selection, cx),
55 _ => self.raise_notice(NO_MEETING_CHAT_NOTICE.to_owned(), None, cx),
56 }
57 }
58}