BlueGit

ict rusty-teams

Files

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

source.rs

source.rs 4.0 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 LinkInfo {
94 pub url: String,
95 pub title: Option<String>,
96}
97
98#[derive(Debug, Clone, Default, PartialEq, Eq)]
99pub struct MessageExtras {
100 pub text: String,
101 pub images: Vec<ImageInfo>,
102 pub reactions: Vec<ReactionInfo>,
103 pub mentions: Vec<MentionInfo>,
104 pub files: Vec<FileInfo>,
105 pub quote: Option<QuoteInfo>,
106 pub cards: Vec<String>,
107 pub links: Vec<LinkInfo>,
108}
109
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct EncodedImage {
112 pub bytes: Vec<u8>,
113 pub mime_type: String,
114 pub kind: ImageKind,
115 pub alt: Option<String>,
116 pub width: u32,
117 pub height: u32,
118}
119
120pub trait TeamsSource: Send + Sync + 'static {
121 fn store(&self) -> Result<Arc<Store>, SourceError>;
122
123 fn me_id(&self) -> Option<String>;
124
125 fn message_extras(&self, message: &MessageRecord, my_user_id: Option<&str>) -> MessageExtras;
126
127 fn image<'a>(
128 &'a self,
129 message: &'a MessageRecord,
130 image_id: &'a str,
131 max_edge: u32,
132 ) -> SourceFuture<'a, EncodedImage>;
133
134 fn reaction_supported(&self, emoji: &str) -> bool;
135
136 fn image_dimensions(&self, bytes: &[u8]) -> Option<(u32, u32)>;
137
138 fn rendered_text(&self, markdown: &str) -> String;
139
140 /// Per name: the `@name` spans (in rendered text offsets) where a mention may sit.
141 fn plain_mention_spans(
142 &self,
143 markdown: &str,
144 names: &[String],
145 ignore_case: bool,
146 ) -> Vec<Vec<std::ops::Range<usize>>>;
147
148 fn refresh_recent(&self, conversation_ids: Vec<String>) -> SourceFuture<'_, ()>;
149
150 fn calendar(
151 &self,
152 _start: DateTime<Utc>,
153 _end: DateTime<Utc>,
154 ) -> SourceFuture<'_, Vec<Meeting>> {
155 Box::pin(async { Err(SourceError::Unsupported("calendar")) })
156 }
157
158 fn transcript<'a>(&'a self, _meeting_chat_id: &'a str) -> SourceFuture<'a, Transcript> {
159 Box::pin(async { Err(SourceError::Unsupported("transcript")) })
160 }
161}