BlueGit

ict rusty-teams

Files

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

calendar.rs

db36f730 History
calendar.rs 2.4 KiB Download Raw
1use std::sync::OnceLock;
2
3use chatsvc::CalendarEvent;
4use chrono::{DateTime, Local, Offset, Utc};
5use gpui_kit::Context;
6
7use super::agenda::{AgendaRow, demo_events};
8use super::list::HistoryFilter;
9use crate::app_state::{AppEvent, AppState, Selection, selection_for};
10
11const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";
12static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();
13
14impl AppState {
15 pub fn apply_calendar(&mut self, events: Vec<CalendarEvent>, cx: &mut Context<Self>) {
16 self.calendar_events = events;
17 self.calls_list.invalidate();
18 cx.emit(AppEvent::CallHistory);
19 cx.notify();
20 }
21
22 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
23 if self.mode.demo {
24 let mut events = demo_events(*DEMO_ANCHOR.get_or_init(Utc::now));
25 events.extend(self.demo_meetings.iter().cloned());
26 events.sort_by_key(|event| (event.start, event.end));
27 self.apply_calendar(events, cx);
28 return;
29 }
30 if let Some(nudge) = &self.calendar_nudge {
31 let _ = nudge.send(());
32 }
33 }
34
35 pub fn rebuild_calls_list(&mut self, cx: &mut Context<Self>) {
36 let now = Utc::now();
37 let offset = Local::now().offset().fix();
38 self.calls_list.rebuild(
39 &self.call_history,
40 &self.sidebar.chats,
41 &self.calendar_events,
42 now,
43 offset,
44 );
45 cx.emit(AppEvent::CallHistory);
46 cx.notify();
47 }
48
49 pub fn set_call_history_filter(&mut self, filter: HistoryFilter, cx: &mut Context<Self>) {
50 self.calls_list.set_filter(filter);
51 self.rebuild_calls_list(cx);
52 }
53
54 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
55 if let Some(url) = &row.join_url {
56 self.join_meeting_link(url, cx);
57 if let Some(pending) = self.prejoin.as_mut() {
58 pending.join.title = row.subject.clone();
59 }
60 }
61 }
62
63 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
64 let Some(thread_id) = &row.thread_id else {
65 return;
66 };
67 match selection_for(&self.sidebar, thread_id) {
68 Some(selection @ Selection::Chat(_)) => self.select(selection, cx),
69 _ => self.raise_notice(NO_MEETING_CHAT_NOTICE.to_owned(), None, cx),
70 }
71 }
72}