| 1 | use std::future::Future; |
| 2 | use std::pin::Pin; |
| 3 | use std::sync::Arc; |
| 4 | |
| 5 | use chrono::{DateTime, Utc}; |
| 6 | use serde::Serialize; |
| 7 | use store::{MessageRecord, Store}; |
| 8 | |
| 9 | pub type SourceFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, SourceError>> + Send + 'a>>; |
| 10 | |
| 11 | #[derive(Debug, thiserror::Error)] |
| 12 | pub 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)] |
| 22 | pub 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, Eq, Serialize)] |
| 33 | pub struct BusySlot { |
| 34 | pub start: DateTime<Utc>, |
| 35 | pub end: DateTime<Utc>, |
| 36 | pub status: String, |
| 37 | } |
| 38 | |
| 39 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 40 | pub struct PersonAvailability { |
| 41 | pub email: String, |
| 42 | pub busy: Vec<BusySlot>, |
| 43 | #[serde(skip_serializing_if = "Option::is_none")] |
| 44 | pub error: Option<String>, |
| 45 | } |
| 46 | |
| 47 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 48 | pub struct MeetingDraft { |
| 49 | pub subject: String, |
| 50 | pub start: DateTime<Utc>, |
| 51 | pub end: DateTime<Utc>, |
| 52 | pub attendees: Vec<String>, |
| 53 | pub description: String, |
| 54 | } |
| 55 | |
| 56 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 57 | pub struct CreatedMeeting { |
| 58 | pub join_url: Option<String>, |
| 59 | } |
| 60 | |
| 61 | #[derive(Debug, Clone, PartialEq, Serialize)] |
| 62 | pub struct TranscriptTurn { |
| 63 | pub speaker: String, |
| 64 | pub start_seconds: f64, |
| 65 | pub end_seconds: f64, |
| 66 | pub text: String, |
| 67 | } |
| 68 | |
| 69 | #[derive(Debug, Clone, PartialEq, Serialize)] |
| 70 | pub struct Transcript { |
| 71 | pub recording_name: Option<String>, |
| 72 | pub created_at: Option<String>, |
| 73 | pub turns: Vec<TranscriptTurn>, |
| 74 | } |
| 75 | |
| 76 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] |
| 77 | #[serde(rename_all = "lowercase")] |
| 78 | pub enum ImageKind { |
| 79 | Inline, |
| 80 | Gif, |
| 81 | Sticker, |
| 82 | } |
| 83 | |
| 84 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 85 | pub struct ImageInfo { |
| 86 | pub image_id: String, |
| 87 | pub kind: ImageKind, |
| 88 | #[serde(skip_serializing_if = "Option::is_none")] |
| 89 | pub alt: Option<String>, |
| 90 | } |
| 91 | |
| 92 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 93 | pub struct ReactionInfo { |
| 94 | pub emoji: String, |
| 95 | pub count: usize, |
| 96 | pub mine: bool, |
| 97 | } |
| 98 | |
| 99 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 100 | pub struct MentionInfo { |
| 101 | pub name: String, |
| 102 | pub user_id: Option<String>, |
| 103 | } |
| 104 | |
| 105 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 106 | pub struct FileInfo { |
| 107 | pub name: String, |
| 108 | pub size: Option<u64>, |
| 109 | #[serde(rename = "type")] |
| 110 | pub file_type: Option<String>, |
| 111 | pub link: String, |
| 112 | } |
| 113 | |
| 114 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 115 | pub struct QuoteInfo { |
| 116 | pub message_id: String, |
| 117 | pub sender: Option<String>, |
| 118 | pub text: String, |
| 119 | } |
| 120 | |
| 121 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 122 | pub struct ForwardedInfo { |
| 123 | pub message_id: String, |
| 124 | pub conversation_id: Option<String>, |
| 125 | pub sender: Option<String>, |
| 126 | pub sender_id: Option<String>, |
| 127 | pub time: Option<String>, |
| 128 | pub text: String, |
| 129 | } |
| 130 | |
| 131 | #[derive(Debug, Clone, PartialEq, Eq, Serialize)] |
| 132 | pub struct LinkInfo { |
| 133 | pub url: String, |
| 134 | pub title: Option<String>, |
| 135 | } |
| 136 | |
| 137 | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 138 | pub struct MessageExtras { |
| 139 | pub text: String, |
| 140 | pub images: Vec<ImageInfo>, |
| 141 | pub reactions: Vec<ReactionInfo>, |
| 142 | pub mentions: Vec<MentionInfo>, |
| 143 | pub files: Vec<FileInfo>, |
| 144 | pub quote: Option<QuoteInfo>, |
| 145 | pub forwarded: Vec<ForwardedInfo>, |
| 146 | pub cards: Vec<String>, |
| 147 | pub links: Vec<LinkInfo>, |
| 148 | } |
| 149 | |
| 150 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 151 | pub struct EncodedImage { |
| 152 | pub bytes: Vec<u8>, |
| 153 | pub mime_type: String, |
| 154 | pub kind: ImageKind, |
| 155 | pub alt: Option<String>, |
| 156 | pub width: u32, |
| 157 | pub height: u32, |
| 158 | } |
| 159 | |
| 160 | pub trait TeamsSource: Send + Sync + 'static { |
| 161 | fn store(&self) -> Result<Arc<Store>, SourceError>; |
| 162 | |
| 163 | fn me_id(&self) -> Option<String>; |
| 164 | |
| 165 | fn message_extras(&self, message: &MessageRecord, my_user_id: Option<&str>) -> MessageExtras; |
| 166 | |
| 167 | fn image<'a>( |
| 168 | &'a self, |
| 169 | message: &'a MessageRecord, |
| 170 | image_id: &'a str, |
| 171 | max_edge: u32, |
| 172 | ) -> SourceFuture<'a, EncodedImage>; |
| 173 | |
| 174 | fn reaction_supported(&self, emoji: &str) -> bool; |
| 175 | |
| 176 | fn image_dimensions(&self, bytes: &[u8]) -> Option<(u32, u32)>; |
| 177 | |
| 178 | fn rendered_text(&self, markdown: &str) -> String; |
| 179 | |
| 180 | /// Per name: the `@name` spans (in rendered text offsets) where a mention may sit. |
| 181 | fn plain_mention_spans( |
| 182 | &self, |
| 183 | markdown: &str, |
| 184 | names: &[String], |
| 185 | ignore_case: bool, |
| 186 | ) -> Vec<Vec<std::ops::Range<usize>>>; |
| 187 | |
| 188 | fn refresh_recent(&self, conversation_ids: Vec<String>) -> SourceFuture<'_, ()>; |
| 189 | |
| 190 | fn calendar( |
| 191 | &self, |
| 192 | _start: DateTime<Utc>, |
| 193 | _end: DateTime<Utc>, |
| 194 | ) -> SourceFuture<'_, Vec<Meeting>> { |
| 195 | Box::pin(async { Err(SourceError::Unsupported("calendar")) }) |
| 196 | } |
| 197 | |
| 198 | fn transcript<'a>(&'a self, _meeting_chat_id: &'a str) -> SourceFuture<'a, Transcript> { |
| 199 | Box::pin(async { Err(SourceError::Unsupported("transcript")) }) |
| 200 | } |
| 201 | |
| 202 | fn availability( |
| 203 | &self, |
| 204 | _emails: Vec<String>, |
| 205 | _start: DateTime<Utc>, |
| 206 | _end: DateTime<Utc>, |
| 207 | ) -> SourceFuture<'_, Vec<PersonAvailability>> { |
| 208 | Box::pin(async { Err(SourceError::Unsupported("availability")) }) |
| 209 | } |
| 210 | |
| 211 | fn create_meeting(&self, _draft: MeetingDraft) -> SourceFuture<'_, CreatedMeeting> { |
| 212 | Box::pin(async { Err(SourceError::Unsupported("create_meeting")) }) |
| 213 | } |
| 214 | } |