BlueGit

ict rusty-teams

Files

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

calendar.rs

calendar.rs 3.3 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
14pub(crate) fn demo_anchor() -> DateTime<Utc> {
15 *DEMO_ANCHOR.get_or_init(Utc::now)
16}
17
18impl AppState {
19 pub fn apply_calendar(&mut self, events: Vec<CalendarEvent>, cx: &mut Context<Self>) {
20 // Agenda / reminders poll — must not replace calendar_week.events.
21 // That window is only ~today+7d; overwriting wiped earlier days in the
22 // visible week/month and made entries "vanish" after delete or poll.
23 self.calendar_events = events;
24 self.calls_list.invalidate();
25 cx.emit(AppEvent::CallHistory);
26 cx.notify();
27 }
28
29 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
30 if self.mode.demo {
31 let mut events = demo_events(demo_anchor());
32 events.extend(self.demo_meetings.iter().cloned());
33 events.sort_by_key(|event| (event.start, event.end));
34 self.apply_calendar(events, cx);
35 if self.calendar_week.start.is_some() {
36 self.load_calendar_week(cx);
37 }
38 return;
39 }
40 if let Some(nudge) = &self.calendar_nudge {
41 let _ = nudge.send(());
42 }
43 // Visible grid SoT is load_calendar_week (full span + Google merge).
44 if self.calendar_week.start.is_some() {
45 self.load_calendar_week(cx);
46 }
47 }
48
49 pub fn rebuild_calls_list(&mut self, cx: &mut Context<Self>) {
50 let now = Utc::now();
51 let offset = Local::now().offset().fix();
52 self.calls_list
53 .rebuild(&self.call_history, &self.sidebar.chats, now, offset);
54 cx.emit(AppEvent::CallHistory);
55 cx.notify();
56 }
57
58 pub fn set_call_history_filter(&mut self, filter: HistoryFilter, cx: &mut Context<Self>) {
59 self.calls_list.set_filter(filter);
60 self.rebuild_calls_list(cx);
61 }
62
63 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
64 self.join_calendar_meeting(row.join_url.as_deref(), &row.subject, cx);
65 }
66
67 pub fn join_calendar_meeting(
68 &mut self,
69 join_url: Option<&str>,
70 subject: &str,
71 cx: &mut Context<Self>,
72 ) {
73 if let Some(url) = join_url {
74 self.join_meeting_link(url, cx);
75 if let Some(pending) = self.prejoin.as_mut() {
76 pending.join.title = subject.to_owned();
77 }
78 }
79 }
80
81 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
82 self.open_meeting_chat(row.thread_id.as_deref(), cx);
83 }
84
85 pub fn open_meeting_chat(&mut self, thread_id: Option<&str>, cx: &mut Context<Self>) {
86 let Some(thread_id) = thread_id else {
87 return;
88 };
89 match selection_for(&self.sidebar, thread_id) {
90 Some(selection @ Selection::Chat(_)) => self.select(selection, cx),
91 _ => self.raise_notice(NO_MEETING_CHAT_NOTICE.to_owned(), None, cx),
92 }
93 }
94}