BlueGit

ict rusty-teams

Files

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

calendar.rs

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