BlueGit

ict rusty-teams

Files

rusty-teams / crates / mcp / src / source.rs

source.rs

source.rs 4.3 KiB Download Raw
1use std::future::Future;
2use std::pin::Pin;
3use std::sync::Arc;
4
5use chrono::{DateTime, Utc};
6use serde::Serialize;
7use store::{MessageRecord, Store};
8
9pub type SourceFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, SourceError>> + Send + 'a>>;
10
11#[derive(Debug, thiserror::Error)]
12pub enum SourceError {
13 #[error("rusty-teams is not connected to Teams")]
14 NotConnected,
15 #[error("{0} is not supported by this build")]
16 Unsupported(&'static str),
17 #[error("{0}")]
18 Failed(String),
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
22pub struct Meeting {
23 pub title: String,
24 pub start: DateTime<Utc>,
25 pub end: DateTime<Utc>,
26 pub all_day: bool,
27 pub organizer: Option<String>,
28 pub join_url: Option<String>,
29 pub meeting_chat_id: Option<String>,
30}
31
32#[derive(Debug, Clone, PartialEq, Serialize)]
33pub struct TranscriptTurn {
34 pub speaker: String,
35 pub start_seconds: f64,
36 pub end_seconds: f64,
37 pub text: String,
38}
39
40#[derive(Debug, Clone, PartialEq, Serialize)]
41pub struct Transcript {
42 pub recording_name: Option<String>,
43 pub created_at: Option<String>,
44 pub turns: Vec<TranscriptTurn>,
45}
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
48#[serde(rename_all = "lowercase")]
49pub enum ImageKind {
50 Inline,
51 Gif,
52 Sticker,
53}
54
55#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
56pub struct ImageInfo {
57 pub image_id: String,
58 pub kind: ImageKind,
59 #[serde(skip_serializing_if = "Option::is_none")]
60 pub alt: Option<String>,
61}
62
63#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
64pub struct ReactionInfo {
65 pub emoji: String,
66 pub count: usize,
67 pub mine: bool,
68}
69
70#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
71pub struct MentionInfo {
72 pub name: String,
73 pub user_id: Option<String>,
74}
75
76#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
77pub struct FileInfo {
78 pub name: String,
79 pub size: Option<u64>,
80 #[serde(rename = "type")]
81 pub file_type: Option<String>,
82 pub link: String,
83}
84
85#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
86pub struct QuoteInfo {
87 pub message_id: String,
88 pub sender: Option<String>,
89 pub text: String,
90}
91
92#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
93pub struct ForwardedInfo {
94 pub message_id: String,
95 pub conversation_id: Option<String>,
96 pub sender: Option<String>,
97 pub sender_id: Option<String>,
98 pub time: Option<String>,
99 pub text: String,
100}
101
102#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
103pub struct LinkInfo {
104 pub url: String,
105 pub title: Option<String>,
106}
107
108#[derive(Debug, Clone, Default, PartialEq, Eq)]
109pub struct MessageExtras {
110 pub text: String,
111 pub images: Vec<ImageInfo>,
112 pub reactions: Vec<ReactionInfo>,
113 pub mentions: Vec<MentionInfo>,
114 pub files: Vec<FileInfo>,
115 pub quote: Option<QuoteInfo>,
116 pub forwarded: Vec<ForwardedInfo>,
117 pub cards: Vec<String>,
118 pub links: Vec<LinkInfo>,
119}
120
121#[derive(Debug, Clone, PartialEq, Eq)]
122pub struct EncodedImage {
123 pub bytes: Vec<u8>,
124 pub mime_type: String,
125 pub kind: ImageKind,
126 pub alt: Option<String>,
127 pub width: u32,
128 pub height: u32,
129}
130
131pub trait TeamsSource: Send + Sync + 'static {
132 fn store(&self) -> Result<Arc<Store>, SourceError>;
133
134 fn me_id(&self) -> Option<String>;
135
136 fn message_extras(&self, message: &MessageRecord, my_user_id: Option<&str>) -> MessageExtras;
137
138 fn image<'a>(
139 &'a self,
140 message: &'a MessageRecord,
141 image_id: &'a str,
142 max_edge: u32,
143 ) -> SourceFuture<'a, EncodedImage>;
144
145 fn reaction_supported(&self, emoji: &str) -> bool;
146
147 fn image_dimensions(&self, bytes: &[u8]) -> Option<(u32, u32)>;
148
149 fn rendered_text(&self, markdown: &str) -> String;
150
151 /// Per name: the `@name` spans (in rendered text offsets) where a mention may sit.
152 fn plain_mention_spans(
153 &self,
154 markdown: &str,
155 names: &[String],
156 ignore_case: bool,
157 ) -> Vec<Vec<std::ops::Range<usize>>>;
158
159 fn refresh_recent(&self, conversation_ids: Vec<String>) -> SourceFuture<'_, ()>;
160
161 fn calendar(
162 &self,
163 _start: DateTime<Utc>,
164 _end: DateTime<Utc>,
165 ) -> SourceFuture<'_, Vec<Meeting>> {
166 Box::pin(async { Err(SourceError::Unsupported("calendar")) })
167 }
168
169 fn transcript<'a>(&'a self, _meeting_chat_id: &'a str) -> SourceFuture<'a, Transcript> {
170 Box::pin(async { Err(SourceError::Unsupported("transcript")) })
171 }
172}