BlueGit

ict rusty-teams

Files

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

calendar.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 3 weeks ago
a6592765 History
calendar.rs 2.7 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 self.calendar_events = events;
21 self.calls_list.invalidate();
22 cx.emit(AppEvent::CallHistory);
23 cx.notify();
24 }
25
26 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
27 if self.mode.demo {
28 let mut events = demo_events(demo_anchor());
29 events.extend(self.demo_meetings.iter().cloned());
30 events.sort_by_key(|event| (event.start, event.end));
31 self.apply_calendar(events, cx);
32 return;
33 }
34 if let Some(nudge) = &self.calendar_nudge {
35 let _ = nudge.send(());
36 }
37 }
38
39 pub fn rebuild_calls_list(&mut self, cx: &mut Context<Self>) {
40 let now = Utc::now();
41 let offset = Local::now().offset().fix();
42 self.calls_list
43 .rebuild(&self.call_history, &self.sidebar.chats, now, offset);
44 cx.emit(AppEvent::CallHistory);
45 cx.notify();
46 }
47
48 pub fn set_call_history_filter(&mut self, filter: HistoryFilter, cx: &mut Context<Self>) {
49 self.calls_list.set_filter(filter);
50 self.rebuild_calls_list(cx);
51 }
52
53 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
54 self.join_calendar_meeting(row.join_url.as_deref(), &row.subject, cx);
55 }
56
57 pub fn join_calendar_meeting(
58 &mut self,
59 join_url: Option<&str>,
60 subject: &str,
61 cx: &mut Context<Self>,
62 ) {
63 if let Some(url) = join_url {
64 self.join_meeting_link(url, cx);
65 if let Some(pending) = self.prejoin.as_mut() {
66 pending.join.title = subject.to_owned();
67 }
68 }
69 }
70
71 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
72 self.open_meeting_chat(row.thread_id.as_deref(), cx);
73 }
74
75 pub fn open_meeting_chat(&mut self, thread_id: Option<&str>, cx: &mut Context<Self>) {
76 let Some(thread_id) = thread_id else {
77 return;
78 };
79 match selection_for(&self.sidebar, thread_id) {
80 Some(selection @ Selection::Chat(_)) => self.select(selection, cx),
81 _ => self.raise_notice(NO_MEETING_CHAT_NOTICE.to_owned(), None, cx),
82 }
83 }
84}