BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / activity / actions.rs

actions.rs

actions.rs 1.3 KiB Download Raw
1use std::sync::Arc;
2
3use gpui_kit::*;
4
5use crate::app_state::{AppEvent, AppState};
6use crate::backend::Engine;
7
8impl AppState {
9 pub fn mark_activity_read(&mut self, message_ids: Vec<String>, cx: &mut Context<Self>) {
10 let Some(engine) = self.activity_engine() else {
11 return;
12 };
13 let receiver = crate::runtime::spawn(async move {
14 for message_id in &message_ids {
15 engine.mark_activity_read(message_id).await?;
16 }
17 Ok::<(), teams_core::Error>(())
18 });
19 cx.spawn(async move |this, cx| {
20 if !matches!(receiver.await, Ok(Ok(()))) {
21 this.update(cx, |_, cx| cx.emit(AppEvent::Activity)).ok();
22 }
23 })
24 .detach();
25 }
26
27 pub fn mark_all_activity_read(&mut self, cx: &mut Context<Self>) {
28 let Some(Some(engine)) = self.chat_action_engine(cx) else {
29 return;
30 };
31 self.run_chat_action(
32 "Mark all as read",
33 async move { engine.mark_all_activity_read().await },
34 |_, cx| cx.emit(AppEvent::Activity),
35 |_, _| {},
36 cx,
37 );
38 }
39
40 fn activity_engine(&self) -> Option<Arc<Engine>> {
41 self.engine.clone().filter(|_| !self.mode.read_only)
42 }
43}