use std::future::Future; use std::pin::Pin; use std::sync::Arc; use chrono::{DateTime, Utc}; use serde::Serialize; use store::{MessageRecord, Store}; pub type SourceFuture<'a, T> = Pin> + Send + 'a>>; #[derive(Debug, thiserror::Error)] pub enum SourceError { #[error("rusty-teams is not connected to Teams")] NotConnected, #[error("{0} is not supported by this build")] Unsupported(&'static str), #[error("{0}")] Failed(String), } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct Meeting { pub title: String, pub start: DateTime, pub end: DateTime, pub all_day: bool, pub organizer: Option, pub join_url: Option, pub meeting_chat_id: Option, } #[derive(Debug, Clone, PartialEq, Serialize)] pub struct TranscriptTurn { pub speaker: String, pub start_seconds: f64, pub end_seconds: f64, pub text: String, } #[derive(Debug, Clone, PartialEq, Serialize)] pub struct Transcript { pub recording_name: Option, pub created_at: Option, pub turns: Vec, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "lowercase")] pub enum ImageKind { Inline, Gif, Sticker, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct ImageInfo { pub image_id: String, pub kind: ImageKind, #[serde(skip_serializing_if = "Option::is_none")] pub alt: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct ReactionInfo { pub emoji: String, pub count: usize, pub mine: bool, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct MentionInfo { pub name: String, pub user_id: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct FileInfo { pub name: String, pub size: Option, #[serde(rename = "type")] pub file_type: Option, pub link: String, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct QuoteInfo { pub message_id: String, pub sender: Option, pub text: String, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct LinkInfo { pub url: String, pub title: Option, } #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct MessageExtras { pub text: String, pub images: Vec, pub reactions: Vec, pub mentions: Vec, pub files: Vec, pub quote: Option, pub cards: Vec, pub links: Vec, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct EncodedImage { pub bytes: Vec, pub mime_type: String, pub kind: ImageKind, pub alt: Option, pub width: u32, pub height: u32, } pub trait TeamsSource: Send + Sync + 'static { fn store(&self) -> Result, SourceError>; fn me_id(&self) -> Option; fn message_extras(&self, message: &MessageRecord, my_user_id: Option<&str>) -> MessageExtras; fn image<'a>( &'a self, _message: &'a MessageRecord, _image_id: &'a str, _max_edge: u32, ) -> SourceFuture<'a, EncodedImage> { Box::pin(async { Err(SourceError::Unsupported("images")) }) } fn refresh_recent(&self, _conversation_ids: Vec) -> SourceFuture<'_, ()> { Box::pin(async { Ok(()) }) } fn calendar( &self, _start: DateTime, _end: DateTime, ) -> SourceFuture<'_, Vec> { Box::pin(async { Err(SourceError::Unsupported("calendar")) }) } fn transcript<'a>(&'a self, _meeting_chat_id: &'a str) -> SourceFuture<'a, Transcript> { Box::pin(async { Err(SourceError::Unsupported("transcript")) }) } }