| 1 | use std::collections::HashMap; |
| 2 | |
| 3 | use chatsvc::compose_copilot::{ComposeCopilot, ComposeRewrite}; |
| 4 | use chatsvc::copilot::{Copilot, CopilotAsk}; |
| 5 | use chatsvc::sound_settings::{SoundSettings, SoundSettingsClient}; |
| 6 | use chatsvc::substrate_search::{ |
| 7 | QueryRequest, QueryResults, SearchIdentity, SearchSession, SubstrateSearch, Suggestions, |
| 8 | }; |
| 9 | use chatsvc::{ |
| 10 | ActivityFeed, ActivitySnapshot, AppConsumptionHorizon, ChatNotificationMode, |
| 11 | ChatNotificationWrite, ChatSettingChange, ChatSettingsClient, ChatSettingsDocument, |
| 12 | DesktopNotifications, UserSettings, parse_app_consumption_horizon, |
| 13 | }; |
| 14 | use chatsvc::{ |
| 15 | BotProfile, BotProfiles, CallLogEntry, CardActions, ChatApp, ConversationRef, |
| 16 | ConversationState, Conversations, ForcedAvailability, ForwardResult, Gif, Gifs, HistoryShare, |
| 17 | InvokeRequest, InvokeResponse, Language, LanguageSettings, LanguageSettingsClient, LinkInfo, |
| 18 | MemberHorizon, MessageEmotions, MessageLanguage, MessageLinks, MessageWindow, Messages, |
| 19 | PinnedMessage, Pins, PostFollowState, PresenceLookup, PresenceService, PresenceStatus, Receipts, |
| 20 | RecordingPolicy, SavedMessage, ScheduledDraft, ScheduledDrafts, StatusNote, ThreadMembers, |
| 21 | ThreadActivity, TranslateRequest, Translation, TranslationTrigger, Translator, WindowDirection, |
| 22 | WorkLocationKind, |
| 23 | }; |
| 24 | use chrono::{DateTime, Utc}; |
| 25 | use graph::{ |
| 26 | CloudFile, QuickSite, |
| 27 | Channel, Chat, DriveEntry, DriveFolder, Graph, Member, Message, MessageExtras, MessageTarget, |
| 28 | OutgoingMention, Photo, Presence, SharedFile, Tag, Team, UploadDestination, UploadedFile, User, |
| 29 | }; |
| 30 | |
| 31 | use crate::error::{Error, Result}; |
| 32 | use crate::profile::PersonProfile; |
| 33 | |
| 34 | pub const CHATSVC_CHAT_WRITES: bool = false; |
| 35 | const URGENT_ACK_EMOTION: &str = "acks"; |
| 36 | |
| 37 | #[derive(Debug, Clone)] |
| 38 | pub struct RemotePage { |
| 39 | pub items: Vec<Message>, |
| 40 | pub next_link: Option<String>, |
| 41 | } |
| 42 | |
| 43 | #[derive(Debug, Clone)] |
| 44 | pub struct DeltaPage { |
| 45 | pub items: Vec<Message>, |
| 46 | pub next_link: Option<String>, |
| 47 | pub delta_link: Option<String>, |
| 48 | } |
| 49 | |
| 50 | #[derive(Debug, Clone)] |
| 51 | pub struct ChatsPage { |
| 52 | pub items: Vec<Chat>, |
| 53 | pub next_link: Option<String>, |
| 54 | } |
| 55 | |
| 56 | #[allow(async_fn_in_trait)] |
| 57 | pub trait Remote { |
| 58 | async fn me(&self) -> Result<User>; |
| 59 | async fn chats_page(&self, top: usize) -> Result<ChatsPage>; |
| 60 | async fn chats_at(&self, next_link: &str) -> Result<ChatsPage>; |
| 61 | async fn chat(&self, chat_id: &str) -> Result<Chat>; |
| 62 | async fn chat_members(&self, chat_id: &str) -> Result<Vec<Member>>; |
| 63 | async fn joined_teams(&self) -> Result<Vec<Team>>; |
| 64 | async fn channels_for_teams(&self, team_ids: &[String]) -> Result<Vec<Result<Vec<Channel>>>>; |
| 65 | async fn chat_messages( |
| 66 | &self, |
| 67 | chat_id: &str, |
| 68 | before: Option<DateTime<Utc>>, |
| 69 | top: usize, |
| 70 | ) -> Result<RemotePage>; |
| 71 | async fn chat_message(&self, chat_id: &str, message_id: &str) -> Result<Message>; |
| 72 | async fn channel_messages( |
| 73 | &self, |
| 74 | team_id: &str, |
| 75 | channel_id: &str, |
| 76 | top: usize, |
| 77 | ) -> Result<RemotePage>; |
| 78 | async fn channel_messages_at(&self, next_link: &str) -> Result<RemotePage>; |
| 79 | async fn channel_message( |
| 80 | &self, |
| 81 | team_id: &str, |
| 82 | channel_id: &str, |
| 83 | message_id: &str, |
| 84 | ) -> Result<Message>; |
| 85 | async fn channel_reply( |
| 86 | &self, |
| 87 | team_id: &str, |
| 88 | channel_id: &str, |
| 89 | message_id: &str, |
| 90 | reply_id: &str, |
| 91 | ) -> Result<Message>; |
| 92 | async fn channel_delta( |
| 93 | &self, |
| 94 | team_id: &str, |
| 95 | channel_id: &str, |
| 96 | modified_after: Option<DateTime<Utc>>, |
| 97 | ) -> Result<DeltaPage>; |
| 98 | async fn channel_delta_at(&self, link: &str) -> Result<DeltaPage>; |
| 99 | async fn channel_replies( |
| 100 | &self, |
| 101 | team_id: &str, |
| 102 | channel_id: &str, |
| 103 | root_ids: &[String], |
| 104 | ) -> Result<Vec<Result<Vec<Message>>>>; |
| 105 | async fn send_chat_message( |
| 106 | &self, |
| 107 | chat_id: &str, |
| 108 | html: &str, |
| 109 | mentions: &[OutgoingMention], |
| 110 | extras: &MessageExtras, |
| 111 | ) -> Result<Message>; |
| 112 | async fn send_channel_message( |
| 113 | &self, |
| 114 | team_id: &str, |
| 115 | channel_id: &str, |
| 116 | html: &str, |
| 117 | subject: Option<&str>, |
| 118 | mentions: &[OutgoingMention], |
| 119 | extras: &MessageExtras, |
| 120 | ) -> Result<Message>; |
| 121 | async fn reply_to_channel_message( |
| 122 | &self, |
| 123 | team_id: &str, |
| 124 | channel_id: &str, |
| 125 | message_id: &str, |
| 126 | html: &str, |
| 127 | mentions: &[OutgoingMention], |
| 128 | extras: &MessageExtras, |
| 129 | ) -> Result<Message>; |
| 130 | async fn post_chatsvc_message( |
| 131 | &self, |
| 132 | conversation: &ConversationRef, |
| 133 | html: &str, |
| 134 | display_name: &str, |
| 135 | properties: &serde_json::Value, |
| 136 | ) -> Result<String>; |
| 137 | /// Readable by the members of `conversation_id`; returns the object id and its full size url. |
| 138 | async fn upload_ams_image( |
| 139 | &self, |
| 140 | conversation_id: &str, |
| 141 | bytes: &[u8], |
| 142 | filename: &str, |
| 143 | ) -> Result<chatsvc::ams::AmsImage>; |
| 144 | async fn set_message_cards( |
| 145 | &self, |
| 146 | conversation: &ConversationRef, |
| 147 | message_id: &str, |
| 148 | cards: &str, |
| 149 | ) -> Result<()>; |
| 150 | async fn mark_chat_read(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()>; |
| 151 | async fn mark_chat_unread( |
| 152 | &self, |
| 153 | chat_id: &str, |
| 154 | user_id: &str, |
| 155 | tenant_id: &str, |
| 156 | last_read_at: DateTime<Utc>, |
| 157 | ) -> Result<()>; |
| 158 | async fn hide_chat(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()>; |
| 159 | async fn unhide_chat(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()>; |
| 160 | async fn remove_chat_member(&self, chat_id: &str, user_id: &str) -> Result<()>; |
| 161 | async fn add_chat_members( |
| 162 | &self, |
| 163 | chat_id: &str, |
| 164 | user_ids: &[String], |
| 165 | share: HistoryShare, |
| 166 | ) -> Result<()>; |
| 167 | async fn chat_states(&self) -> Result<Vec<ConversationState>>; |
| 168 | async fn clear_chat_history(&self, _chat_id: &str, _cleared_until_ms: i64) -> Result<()> { |
| 169 | Err(Error::Unsupported("removing chat history")) |
| 170 | } |
| 171 | async fn set_chat_topic(&self, _chat_id: &str, _topic: &str) -> Result<()> { |
| 172 | Err(Error::Unsupported("renaming a chat")) |
| 173 | } |
| 174 | async fn set_chat_muted(&self, chat_id: &str, muted: bool) -> Result<()>; |
| 175 | async fn set_read_horizon(&self, conversation_id: &str, horizon: &str) -> Result<()>; |
| 176 | async fn set_read_bookmark(&self, _conversation_id: &str, _bookmark: &str) -> Result<()> { |
| 177 | Err(Error::Unsupported("marking the notes chat as unread")) |
| 178 | } |
| 179 | async fn set_chat_hidden_at(&self, _chat_id: &str, _hidden_at_ms: Option<i64>) -> Result<()> { |
| 180 | Err(Error::Unsupported("hiding the notes chat")) |
| 181 | } |
| 182 | async fn set_channel_notifications( |
| 183 | &self, |
| 184 | channel_id: &str, |
| 185 | notifications: store::ChannelNotifications, |
| 186 | ) -> Result<()>; |
| 187 | async fn send_typing(&self, conversation: &ConversationRef, active: bool) -> Result<()>; |
| 188 | async fn set_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()>; |
| 189 | async fn unset_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()>; |
| 190 | async fn edit_message( |
| 191 | &self, |
| 192 | target: &MessageTarget, |
| 193 | html: &str, |
| 194 | mentions: &[OutgoingMention], |
| 195 | extras: &MessageExtras, |
| 196 | ) -> Result<()>; |
| 197 | async fn soft_delete_message(&self, user_id: &str, target: &MessageTarget) -> Result<()>; |
| 198 | async fn undo_soft_delete_message(&self, user_id: &str, target: &MessageTarget) -> Result<()>; |
| 199 | async fn create_one_on_one(&self, my_user_id: &str, user_id: &str) -> Result<Chat>; |
| 200 | async fn create_group( |
| 201 | &self, |
| 202 | my_user_id: &str, |
| 203 | user_ids: &[String], |
| 204 | topic: Option<&str>, |
| 205 | ) -> Result<Chat>; |
| 206 | async fn search_people(&self, query: &str) -> Result<Vec<User>>; |
| 207 | |
| 208 | async fn team_tags(&self, _team_id: &str) -> Result<Vec<Tag>> { |
| 209 | Err(Error::Unsupported("team tags")) |
| 210 | } |
| 211 | |
| 212 | async fn channel_description(&self, _team_id: &str, _channel_id: &str) -> Result<String> { |
| 213 | Err(Error::Unsupported("channel description")) |
| 214 | } |
| 215 | |
| 216 | async fn reply_with_quote( |
| 217 | &self, |
| 218 | _chat_id: &str, |
| 219 | _quoted_message_id: &str, |
| 220 | _html: &str, |
| 221 | _mentions: &[OutgoingMention], |
| 222 | _extras: &MessageExtras, |
| 223 | ) -> Result<Message> { |
| 224 | Err(Error::Unsupported("a quoted reply")) |
| 225 | } |
| 226 | |
| 227 | async fn channel_files_folder(&self, _team_id: &str, _channel_id: &str) -> Result<DriveFolder> { |
| 228 | Err(Error::Unsupported("a channel files folder")) |
| 229 | } |
| 230 | |
| 231 | async fn channel_files_root(&self, _team_id: &str, _channel_id: &str) -> Result<DriveEntry> { |
| 232 | Err(Error::Unsupported("a channel library")) |
| 233 | } |
| 234 | |
| 235 | async fn channel_tab_web_url( |
| 236 | &self, |
| 237 | _team_id: &str, |
| 238 | _channel_id: &str, |
| 239 | _tab_id: &str, |
| 240 | ) -> Result<Option<String>> { |
| 241 | Err(Error::Unsupported("a channel tab link")) |
| 242 | } |
| 243 | |
| 244 | async fn channel_member_count(&self, _team_id: &str, _channel_id: &str) -> Result<usize> { |
| 245 | Err(Error::Unsupported("a channel member count")) |
| 246 | } |
| 247 | |
| 248 | async fn channel_members(&self, _team_id: &str, _channel_id: &str) -> Result<Vec<graph::Member>> { |
| 249 | Err(Error::Unsupported("a channel member list")) |
| 250 | } |
| 251 | |
| 252 | async fn list_children(&self, _folder: &DriveFolder) -> Result<Vec<DriveEntry>> { |
| 253 | Err(Error::Unsupported("a folder listing")) |
| 254 | } |
| 255 | |
| 256 | async fn create_folder(&self, _parent: &DriveFolder, _name: &str) -> Result<DriveEntry> { |
| 257 | Err(Error::Unsupported("creating a folder")) |
| 258 | } |
| 259 | |
| 260 | async fn upload_file( |
| 261 | &self, |
| 262 | _destination: &UploadDestination, |
| 263 | _file_name: &str, |
| 264 | _bytes: &[u8], |
| 265 | _progress: &(dyn Fn(u8) + Send + Sync), |
| 266 | ) -> Result<UploadedFile> { |
| 267 | Err(Error::Unsupported("a file upload")) |
| 268 | } |
| 269 | |
| 270 | async fn share_file(&self, _file: &UploadedFile, _user_ids: &[String]) -> Result<()> { |
| 271 | Err(Error::Unsupported("sharing a file")) |
| 272 | } |
| 273 | |
| 274 | async fn recent_files(&self, _top: usize) -> Result<Vec<CloudFile>> { |
| 275 | Err(Error::Unsupported("recent files")) |
| 276 | } |
| 277 | |
| 278 | async fn recent_files_with_owners(&self, _top: usize) -> Result<(Vec<CloudFile>, Vec<(String, String)>)> { |
| 279 | Err(Error::Unsupported("recent files")) |
| 280 | } |
| 281 | |
| 282 | async fn shared_with_me(&self) -> Result<Vec<DriveEntry>> { |
| 283 | Err(Error::Unsupported("shared files")) |
| 284 | } |
| 285 | |
| 286 | async fn quick_access_sites(&self) -> Result<Vec<QuickSite>> { |
| 287 | Err(Error::Unsupported("sites")) |
| 288 | } |
| 289 | |
| 290 | async fn drive_root(&self, _site_id: Option<&str>) -> Result<DriveFolder> { |
| 291 | Err(Error::Unsupported("drive root")) |
| 292 | } |
| 293 | |
| 294 | async fn cloud_file_reference(&self, _file: &CloudFile) -> Result<UploadedFile> { |
| 295 | Err(Error::Unsupported("cloud files")) |
| 296 | } |
| 297 | |
| 298 | async fn delete_file(&self, _file: &UploadedFile) -> Result<()> { |
| 299 | Err(Error::Unsupported("deleting a file")) |
| 300 | } |
| 301 | |
| 302 | async fn resolve_share(&self, _open_url: &str) -> Result<SharedFile> { |
| 303 | Err(Error::Unsupported("resolving a shared file")) |
| 304 | } |
| 305 | |
| 306 | async fn resolve_drive_item(&self, _drive_id: &str, _item_id: &str) -> Result<SharedFile> { |
| 307 | Err(Error::Unsupported("resolving a drive item")) |
| 308 | } |
| 309 | |
| 310 | async fn download_range( |
| 311 | &self, |
| 312 | _download_url: &str, |
| 313 | _start: u64, |
| 314 | _end: Option<u64>, |
| 315 | ) -> Result<Vec<u8>> { |
| 316 | Err(Error::Unsupported("a file download")) |
| 317 | } |
| 318 | |
| 319 | async fn hosted_content(&self, _url: &str) -> Result<Photo> { |
| 320 | Err(Error::Unsupported("hosted content")) |
| 321 | } |
| 322 | |
| 323 | async fn external_image(&self, _url: &str) -> Result<Photo> { |
| 324 | Err(Error::Unsupported("external images")) |
| 325 | } |
| 326 | |
| 327 | async fn user_photos(&self, _user_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> { |
| 328 | Err(Error::Unsupported("profile photos")) |
| 329 | } |
| 330 | |
| 331 | async fn team_photos(&self, _team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> { |
| 332 | Err(Error::Unsupported("team pictures")) |
| 333 | } |
| 334 | |
| 335 | async fn presences(&self, _user_ids: &[String]) -> Result<Vec<Presence>> { |
| 336 | Err(Error::Unsupported("presence")) |
| 337 | } |
| 338 | |
| 339 | async fn person_profile(&self, _user_id: &str) -> Result<PersonProfile> { |
| 340 | Err(Error::Unsupported("profile cards")) |
| 341 | } |
| 342 | |
| 343 | async fn bot_profiles(&self, _bot_ids: &[String]) -> Result<Vec<BotProfile>> { |
| 344 | Err(Error::Unsupported("bot profiles")) |
| 345 | } |
| 346 | |
| 347 | async fn subscribe_presence( |
| 348 | &self, |
| 349 | _endpoint_id: &str, |
| 350 | _trouter_uri: &str, |
| 351 | _user_ids: &[String], |
| 352 | _purge: bool, |
| 353 | ) -> Result<()> { |
| 354 | Err(Error::Unsupported("presence subscriptions")) |
| 355 | } |
| 356 | |
| 357 | async fn own_status(&self, _user_id: &str) -> Result<PresenceStatus> { |
| 358 | Err(Error::Unsupported("own status")) |
| 359 | } |
| 360 | |
| 361 | async fn set_availability(&self, _forced: Option<&ForcedAvailability>) -> Result<()> { |
| 362 | Err(Error::Unsupported("setting availability")) |
| 363 | } |
| 364 | |
| 365 | async fn set_status_note(&self, _note: Option<&StatusNote>) -> Result<()> { |
| 366 | Err(Error::Unsupported("setting the status message")) |
| 367 | } |
| 368 | |
| 369 | async fn set_work_location( |
| 370 | &self, |
| 371 | _location: Option<(WorkLocationKind, DateTime<Utc>)>, |
| 372 | ) -> Result<()> { |
| 373 | Err(Error::Unsupported("setting the work location")) |
| 374 | } |
| 375 | |
| 376 | async fn consumption_horizons(&self, _conversation_id: &str) -> Result<Vec<MemberHorizon>> { |
| 377 | Err(Error::Unsupported("read receipts")) |
| 378 | } |
| 379 | |
| 380 | async fn forward_messages( |
| 381 | &self, |
| 382 | _source_conversation_id: &str, |
| 383 | _target_conversation_id: &str, |
| 384 | _message_ids: &[String], |
| 385 | _comment_html: &str, |
| 386 | ) -> Result<ForwardResult> { |
| 387 | Err(Error::Unsupported("forwarding messages")) |
| 388 | } |
| 389 | |
| 390 | async fn set_saved( |
| 391 | &self, |
| 392 | _conversation_id: &str, |
| 393 | _root_id: &str, |
| 394 | _message_id: &str, |
| 395 | _saved: bool, |
| 396 | ) -> Result<()> { |
| 397 | Err(Error::Unsupported("saving messages")) |
| 398 | } |
| 399 | |
| 400 | async fn list_saved(&self) -> Result<Vec<SavedMessage>> { |
| 401 | Err(Error::Unsupported("saved messages")) |
| 402 | } |
| 403 | |
| 404 | async fn set_post_followed( |
| 405 | &self, |
| 406 | _user_id: &str, |
| 407 | _channel_id: &str, |
| 408 | _root_id: &str, |
| 409 | _followed: bool, |
| 410 | ) -> Result<Option<String>> { |
| 411 | Err(Error::Unsupported("following posts")) |
| 412 | } |
| 413 | |
| 414 | async fn post_follow_states( |
| 415 | &self, |
| 416 | _channel_id: &str, |
| 417 | _root_ids: &[String], |
| 418 | ) -> Result<HashMap<String, PostFollowState>> { |
| 419 | Err(Error::Unsupported("post follow states")) |
| 420 | } |
| 421 | |
| 422 | async fn list_call_logs(&self) -> Result<Vec<CallLogEntry>> { |
| 423 | Err(Error::Unsupported("call history")) |
| 424 | } |
| 425 | |
| 426 | async fn chat_message_window( |
| 427 | &self, |
| 428 | _chat_id: &str, |
| 429 | _anchor_id: &str, |
| 430 | _direction: WindowDirection, |
| 431 | _page_size: usize, |
| 432 | ) -> Result<MessageWindow> { |
| 433 | Err(Error::Unsupported("message windows")) |
| 434 | } |
| 435 | |
| 436 | async fn chat_thread_activities(&self, _chat_id: &str) -> Result<Vec<ThreadActivity>> { |
| 437 | Ok(Vec::new()) |
| 438 | } |
| 439 | |
| 440 | async fn chat_messages_by_id( |
| 441 | &self, |
| 442 | _chat_id: &str, |
| 443 | _message_ids: &[String], |
| 444 | ) -> Result<Vec<Result<Message>>> { |
| 445 | Err(Error::Unsupported("batched message reads")) |
| 446 | } |
| 447 | |
| 448 | async fn chat_pins(&self, _chat_id: &str) -> Result<Vec<PinnedMessage>> { |
| 449 | Err(Error::Unsupported("pinned messages")) |
| 450 | } |
| 451 | |
| 452 | async fn pin_message(&self, _chat_id: &str, _message_id: &str) -> Result<()> { |
| 453 | Err(Error::Unsupported("pinning messages")) |
| 454 | } |
| 455 | |
| 456 | async fn unpin_message( |
| 457 | &self, |
| 458 | _chat_id: &str, |
| 459 | _message_id: &str, |
| 460 | _parent_id: Option<&str>, |
| 461 | ) -> Result<()> { |
| 462 | Err(Error::Unsupported("pinning messages")) |
| 463 | } |
| 464 | |
| 465 | async fn channel_pinned_posts( |
| 466 | &self, |
| 467 | _team_thread_id: &str, |
| 468 | _channel_id: &str, |
| 469 | ) -> Result<Vec<PinnedMessage>> { |
| 470 | Err(Error::Unsupported("pinned channel posts")) |
| 471 | } |
| 472 | |
| 473 | async fn set_post_pinned( |
| 474 | &self, |
| 475 | _team_thread_id: &str, |
| 476 | _channel_id: &str, |
| 477 | _post_id: &str, |
| 478 | _pinned: bool, |
| 479 | ) -> Result<()> { |
| 480 | Err(Error::Unsupported("pinning channel posts")) |
| 481 | } |
| 482 | |
| 483 | async fn activity_feed(&self) -> Result<ActivitySnapshot> { |
| 484 | Err(Error::Unsupported("the activity feed")) |
| 485 | } |
| 486 | |
| 487 | async fn mark_activity_read(&self, _message_id: &str) -> Result<()> { |
| 488 | Err(Error::Unsupported("marking activity as read")) |
| 489 | } |
| 490 | |
| 491 | async fn mark_all_activity_read(&self, _now_ms: i64) -> Result<()> { |
| 492 | Err(Error::Unsupported("marking all activity as read")) |
| 493 | } |
| 494 | |
| 495 | async fn app_consumption_horizon(&self) -> Result<AppConsumptionHorizon> { |
| 496 | Ok(AppConsumptionHorizon::default()) |
| 497 | } |
| 498 | |
| 499 | async fn mark_all_channels_read(&self, _now_ms: i64) -> Result<AppConsumptionHorizon> { |
| 500 | Err(Error::Unsupported("marking all channels as read")) |
| 501 | } |
| 502 | |
| 503 | async fn chat_apps(&self, _chat_id: &str) -> Result<Vec<ChatApp>> { |
| 504 | Err(Error::Unsupported("chat apps")) |
| 505 | } |
| 506 | |
| 507 | async fn invoke_card(&self, _invoke: InvokeRequest) -> Result<InvokeResponse> { |
| 508 | Err(Error::Unsupported("card actions")) |
| 509 | } |
| 510 | |
| 511 | async fn message_links( |
| 512 | &self, |
| 513 | _conversation: &ConversationRef, |
| 514 | _page_size: usize, |
| 515 | ) -> Result<Vec<MessageLinks>> { |
| 516 | Err(Error::Unsupported("link previews")) |
| 517 | } |
| 518 | |
| 519 | async fn message_emotions( |
| 520 | &self, |
| 521 | _conversation: &ConversationRef, |
| 522 | _newest_message_id: &str, |
| 523 | _page_size: usize, |
| 524 | ) -> Result<Vec<MessageEmotions>> { |
| 525 | Err(Error::Unsupported("chat service reactions")) |
| 526 | } |
| 527 | |
| 528 | async fn set_message_links(&self, _target: &MessageTarget, _links_json: &str) -> Result<()> { |
| 529 | Err(Error::Unsupported("link previews")) |
| 530 | } |
| 531 | |
| 532 | async fn link_info(&self, _url: &str) -> Result<LinkInfo> { |
| 533 | Err(Error::Unsupported("link previews")) |
| 534 | } |
| 535 | |
| 536 | async fn message_languages( |
| 537 | &self, |
| 538 | _conversation: &ConversationRef, |
| 539 | _page_size: usize, |
| 540 | ) -> Result<Vec<MessageLanguage>> { |
| 541 | Err(Error::Unsupported("message languages")) |
| 542 | } |
| 543 | |
| 544 | async fn ask_copilot(&self, _ask: &CopilotAsk) -> Result<String> { |
| 545 | Err(Error::Unsupported("Copilot")) |
| 546 | } |
| 547 | |
| 548 | async fn rewrite_draft(&self, _rewrite: &ComposeRewrite) -> Result<String> { |
| 549 | Err(Error::Unsupported("Copilot")) |
| 550 | } |
| 551 | |
| 552 | async fn translate_chat_messages( |
| 553 | &self, |
| 554 | _chat_id: &str, |
| 555 | _to_language: &str, |
| 556 | _messages: &[TranslateRequest], |
| 557 | _trigger: &TranslationTrigger, |
| 558 | ) -> Result<Vec<Translation>> { |
| 559 | Err(Error::Unsupported("translation")) |
| 560 | } |
| 561 | |
| 562 | async fn translate_channel_messages( |
| 563 | &self, |
| 564 | _team_id: &str, |
| 565 | _channel_id: &str, |
| 566 | _root_id: &str, |
| 567 | _to_language: &str, |
| 568 | _messages: &[TranslateRequest], |
| 569 | _trigger: &TranslationTrigger, |
| 570 | ) -> Result<Vec<Translation>> { |
| 571 | Err(Error::Unsupported("translation")) |
| 572 | } |
| 573 | |
| 574 | async fn translation_languages(&self, _locale: &str) -> Result<Vec<Language>> { |
| 575 | Err(Error::Unsupported("translation")) |
| 576 | } |
| 577 | |
| 578 | async fn language_settings(&self) -> Result<LanguageSettings> { |
| 579 | Err(Error::Unsupported("translation settings")) |
| 580 | } |
| 581 | |
| 582 | async fn patch_language_settings(&self, _patch: serde_json::Value) -> Result<()> { |
| 583 | Err(Error::Unsupported("translation settings")) |
| 584 | } |
| 585 | |
| 586 | async fn recording_policy(&self) -> Result<RecordingPolicy> { |
| 587 | Err(Error::Unsupported("recording policy")) |
| 588 | } |
| 589 | |
| 590 | async fn allow_priority_messages(&self) -> Result<bool> { |
| 591 | Err(Error::Unsupported("messaging policy")) |
| 592 | } |
| 593 | |
| 594 | async fn ack_urgent_message(&self, _chat_id: &str, _message_id: &str) -> Result<()> { |
| 595 | Err(Error::Unsupported("urgent message acknowledgement")) |
| 596 | } |
| 597 | |
| 598 | async fn sound_settings(&self) -> Result<SoundSettings> { |
| 599 | Err(Error::Unsupported("sound settings")) |
| 600 | } |
| 601 | |
| 602 | async fn chat_settings(&self) -> Result<ChatSettingsDocument> { |
| 603 | Err(Error::Unsupported("chat settings")) |
| 604 | } |
| 605 | |
| 606 | async fn save_chat_setting(&self, _change: ChatSettingChange) -> Result<ChatSettingsDocument> { |
| 607 | Err(Error::Unsupported("chat settings")) |
| 608 | } |
| 609 | |
| 610 | async fn set_chat_notifications( |
| 611 | &self, |
| 612 | _chat_id: &str, |
| 613 | _current_settings: Option<&str>, |
| 614 | _mode: ChatNotificationMode, |
| 615 | _desktop: DesktopNotifications, |
| 616 | ) -> Result<ChatNotificationWrite> { |
| 617 | Err(Error::Unsupported("chat notifications")) |
| 618 | } |
| 619 | |
| 620 | async fn save_sound_settings( |
| 621 | &self, |
| 622 | _user_mri: &str, |
| 623 | _previous: &SoundSettings, |
| 624 | _updated: &SoundSettings, |
| 625 | ) -> Result<()> { |
| 626 | Err(Error::Unsupported("sound settings")) |
| 627 | } |
| 628 | |
| 629 | async fn search_gifs(&self, _query: &str) -> Result<Vec<Gif>> { |
| 630 | Err(Error::Unsupported("GIF search")) |
| 631 | } |
| 632 | |
| 633 | async fn server_search_init( |
| 634 | &self, |
| 635 | _identity: &SearchIdentity, |
| 636 | _search_session: &SearchSession, |
| 637 | ) -> Result<()> { |
| 638 | Err(Error::Unsupported("server search")) |
| 639 | } |
| 640 | |
| 641 | async fn server_suggestions( |
| 642 | &self, |
| 643 | _identity: &SearchIdentity, |
| 644 | _search_session: &SearchSession, |
| 645 | _text: &str, |
| 646 | ) -> Result<Suggestions> { |
| 647 | Err(Error::Unsupported("server search")) |
| 648 | } |
| 649 | |
| 650 | async fn server_query( |
| 651 | &self, |
| 652 | _identity: &SearchIdentity, |
| 653 | _search_session: &SearchSession, |
| 654 | _request: &QueryRequest, |
| 655 | ) -> Result<QueryResults> { |
| 656 | Err(Error::Unsupported("server search")) |
| 657 | } |
| 658 | |
| 659 | async fn create_scheduled( |
| 660 | &self, |
| 661 | _inner_thread_id: &str, |
| 662 | _html: &str, |
| 663 | _send_at: DateTime<Utc>, |
| 664 | _display_name: &str, |
| 665 | ) -> Result<ScheduledDraft> { |
| 666 | Err(Error::Unsupported("schedule send")) |
| 667 | } |
| 668 | |
| 669 | async fn scheduled_drafts(&self) -> Result<Vec<ScheduledDraft>> { |
| 670 | Err(Error::Unsupported("schedule send")) |
| 671 | } |
| 672 | |
| 673 | async fn update_scheduled( |
| 674 | &self, |
| 675 | _draft: &ScheduledDraft, |
| 676 | _html: &str, |
| 677 | _display_name: &str, |
| 678 | ) -> Result<ScheduledDraft> { |
| 679 | Err(Error::Unsupported("schedule send")) |
| 680 | } |
| 681 | |
| 682 | async fn cancel_scheduled(&self, _draft_id: &str) -> Result<()> { |
| 683 | Err(Error::Unsupported("schedule send")) |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | impl Remote for Graph { |
| 688 | async fn me(&self) -> Result<User> { |
| 689 | Ok(Graph::me(self).await?) |
| 690 | } |
| 691 | |
| 692 | async fn chats_page(&self, top: usize) -> Result<ChatsPage> { |
| 693 | Ok(Graph::chats_page(self, top).await?.into()) |
| 694 | } |
| 695 | |
| 696 | async fn chats_at(&self, next_link: &str) -> Result<ChatsPage> { |
| 697 | Ok(Graph::chats_at(self, next_link).await?.into()) |
| 698 | } |
| 699 | |
| 700 | async fn chat(&self, chat_id: &str) -> Result<Chat> { |
| 701 | Ok(Graph::chat(self, chat_id).await?) |
| 702 | } |
| 703 | |
| 704 | async fn chat_members(&self, chat_id: &str) -> Result<Vec<Member>> { |
| 705 | Ok(Graph::chat_members(self, chat_id).await?) |
| 706 | } |
| 707 | |
| 708 | async fn joined_teams(&self) -> Result<Vec<Team>> { |
| 709 | Ok(Graph::joined_teams(self).await?) |
| 710 | } |
| 711 | |
| 712 | async fn channels_for_teams(&self, team_ids: &[String]) -> Result<Vec<Result<Vec<Channel>>>> { |
| 713 | let listings = Graph::channels_for_teams(self, team_ids).await?; |
| 714 | Ok(listings |
| 715 | .into_iter() |
| 716 | .map(|listing| listing.map_err(Into::into)) |
| 717 | .collect()) |
| 718 | } |
| 719 | |
| 720 | async fn chat_messages( |
| 721 | &self, |
| 722 | chat_id: &str, |
| 723 | before: Option<DateTime<Utc>>, |
| 724 | top: usize, |
| 725 | ) -> Result<RemotePage> { |
| 726 | Ok(Graph::chat_messages(self, chat_id, before, top) |
| 727 | .await? |
| 728 | .into()) |
| 729 | } |
| 730 | |
| 731 | async fn chat_message(&self, chat_id: &str, message_id: &str) -> Result<Message> { |
| 732 | Ok(Graph::chat_message(self, chat_id, message_id).await?) |
| 733 | } |
| 734 | |
| 735 | async fn channel_messages( |
| 736 | &self, |
| 737 | team_id: &str, |
| 738 | channel_id: &str, |
| 739 | top: usize, |
| 740 | ) -> Result<RemotePage> { |
| 741 | Ok(Graph::channel_messages(self, team_id, channel_id, top) |
| 742 | .await? |
| 743 | .into()) |
| 744 | } |
| 745 | |
| 746 | async fn channel_messages_at(&self, next_link: &str) -> Result<RemotePage> { |
| 747 | Ok(Graph::channel_messages_at(self, next_link).await?.into()) |
| 748 | } |
| 749 | |
| 750 | async fn channel_message( |
| 751 | &self, |
| 752 | team_id: &str, |
| 753 | channel_id: &str, |
| 754 | message_id: &str, |
| 755 | ) -> Result<Message> { |
| 756 | Ok(Graph::channel_message(self, team_id, channel_id, message_id).await?) |
| 757 | } |
| 758 | |
| 759 | async fn channel_reply( |
| 760 | &self, |
| 761 | team_id: &str, |
| 762 | channel_id: &str, |
| 763 | message_id: &str, |
| 764 | reply_id: &str, |
| 765 | ) -> Result<Message> { |
| 766 | Ok(Graph::channel_reply(self, team_id, channel_id, message_id, reply_id).await?) |
| 767 | } |
| 768 | |
| 769 | async fn channel_delta( |
| 770 | &self, |
| 771 | team_id: &str, |
| 772 | channel_id: &str, |
| 773 | modified_after: Option<DateTime<Utc>>, |
| 774 | ) -> Result<DeltaPage> { |
| 775 | Ok( |
| 776 | Graph::channel_delta(self, team_id, channel_id, modified_after) |
| 777 | .await? |
| 778 | .into(), |
| 779 | ) |
| 780 | } |
| 781 | |
| 782 | async fn channel_delta_at(&self, link: &str) -> Result<DeltaPage> { |
| 783 | Ok(Graph::channel_delta_at(self, link).await?.into()) |
| 784 | } |
| 785 | |
| 786 | async fn channel_replies( |
| 787 | &self, |
| 788 | team_id: &str, |
| 789 | channel_id: &str, |
| 790 | root_ids: &[String], |
| 791 | ) -> Result<Vec<Result<Vec<Message>>>> { |
| 792 | let listings = Graph::channel_replies(self, team_id, channel_id, root_ids).await?; |
| 793 | Ok(listings |
| 794 | .into_iter() |
| 795 | .map(|listing| listing.map_err(Into::into)) |
| 796 | .collect()) |
| 797 | } |
| 798 | |
| 799 | async fn send_chat_message( |
| 800 | &self, |
| 801 | chat_id: &str, |
| 802 | html: &str, |
| 803 | mentions: &[OutgoingMention], |
| 804 | extras: &MessageExtras, |
| 805 | ) -> Result<Message> { |
| 806 | Ok(Graph::send_chat_message(self, chat_id, html, mentions, extras).await?) |
| 807 | } |
| 808 | |
| 809 | async fn send_channel_message( |
| 810 | &self, |
| 811 | team_id: &str, |
| 812 | channel_id: &str, |
| 813 | html: &str, |
| 814 | subject: Option<&str>, |
| 815 | mentions: &[OutgoingMention], |
| 816 | extras: &MessageExtras, |
| 817 | ) -> Result<Message> { |
| 818 | Ok( |
| 819 | Graph::send_channel_message(self, team_id, channel_id, html, subject, mentions, extras) |
| 820 | .await?, |
| 821 | ) |
| 822 | } |
| 823 | |
| 824 | async fn reply_to_channel_message( |
| 825 | &self, |
| 826 | team_id: &str, |
| 827 | channel_id: &str, |
| 828 | message_id: &str, |
| 829 | html: &str, |
| 830 | mentions: &[OutgoingMention], |
| 831 | extras: &MessageExtras, |
| 832 | ) -> Result<Message> { |
| 833 | Ok(Graph::reply_to_channel_message( |
| 834 | self, team_id, channel_id, message_id, html, mentions, extras, |
| 835 | ) |
| 836 | .await?) |
| 837 | } |
| 838 | |
| 839 | async fn post_chatsvc_message( |
| 840 | &self, |
| 841 | conversation: &ConversationRef, |
| 842 | html: &str, |
| 843 | display_name: &str, |
| 844 | properties: &serde_json::Value, |
| 845 | ) -> Result<String> { |
| 846 | Ok(Messages::new(self.session()) |
| 847 | .post_message(conversation, html, display_name, properties) |
| 848 | .await?) |
| 849 | } |
| 850 | |
| 851 | async fn upload_ams_image( |
| 852 | &self, |
| 853 | conversation_id: &str, |
| 854 | bytes: &[u8], |
| 855 | filename: &str, |
| 856 | ) -> Result<chatsvc::ams::AmsImage> { |
| 857 | Ok(chatsvc::ams::Ams::new(self.session()) |
| 858 | .upload_image(conversation_id, bytes, filename) |
| 859 | .await?) |
| 860 | } |
| 861 | |
| 862 | async fn set_message_cards( |
| 863 | &self, |
| 864 | conversation: &ConversationRef, |
| 865 | message_id: &str, |
| 866 | cards: &str, |
| 867 | ) -> Result<()> { |
| 868 | Ok(Messages::new(self.session()) |
| 869 | .set_cards(conversation, message_id, cards) |
| 870 | .await?) |
| 871 | } |
| 872 | |
| 873 | async fn mark_chat_read(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()> { |
| 874 | Ok(Graph::mark_chat_read(self, chat_id, user_id, tenant_id).await?) |
| 875 | } |
| 876 | |
| 877 | async fn mark_chat_unread( |
| 878 | &self, |
| 879 | chat_id: &str, |
| 880 | user_id: &str, |
| 881 | tenant_id: &str, |
| 882 | last_read_at: DateTime<Utc>, |
| 883 | ) -> Result<()> { |
| 884 | Ok(Graph::mark_chat_unread(self, chat_id, user_id, tenant_id, last_read_at).await?) |
| 885 | } |
| 886 | |
| 887 | async fn hide_chat(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()> { |
| 888 | Ok(Graph::hide_chat(self, chat_id, user_id, tenant_id).await?) |
| 889 | } |
| 890 | |
| 891 | async fn unhide_chat(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()> { |
| 892 | Ok(Graph::unhide_chat(self, chat_id, user_id, tenant_id).await?) |
| 893 | } |
| 894 | |
| 895 | async fn remove_chat_member(&self, chat_id: &str, user_id: &str) -> Result<()> { |
| 896 | Ok(ThreadMembers::new(self.session()) |
| 897 | .remove(chat_id, user_id) |
| 898 | .await?) |
| 899 | } |
| 900 | |
| 901 | async fn add_chat_members( |
| 902 | &self, |
| 903 | chat_id: &str, |
| 904 | user_ids: &[String], |
| 905 | share: HistoryShare, |
| 906 | ) -> Result<()> { |
| 907 | Ok(ThreadMembers::new(self.session()) |
| 908 | .add(chat_id, user_ids, share, Utc::now().timestamp_millis()) |
| 909 | .await?) |
| 910 | } |
| 911 | |
| 912 | async fn chat_states(&self) -> Result<Vec<ConversationState>> { |
| 913 | Ok(Conversations::new(self.session()) |
| 914 | .conversation_states() |
| 915 | .await?) |
| 916 | } |
| 917 | |
| 918 | async fn clear_chat_history(&self, chat_id: &str, cleared_until_ms: i64) -> Result<()> { |
| 919 | Ok(Conversations::new(self.session()) |
| 920 | .clear_history(chat_id, cleared_until_ms) |
| 921 | .await?) |
| 922 | } |
| 923 | |
| 924 | async fn set_chat_topic(&self, chat_id: &str, topic: &str) -> Result<()> { |
| 925 | Ok(ThreadMembers::new(self.session()) |
| 926 | .set_topic(chat_id, topic) |
| 927 | .await?) |
| 928 | } |
| 929 | |
| 930 | async fn set_chat_muted(&self, chat_id: &str, muted: bool) -> Result<()> { |
| 931 | Ok(Conversations::new(self.session()) |
| 932 | .set_alerts(chat_id, !muted) |
| 933 | .await?) |
| 934 | } |
| 935 | |
| 936 | async fn set_read_horizon(&self, conversation_id: &str, horizon: &str) -> Result<()> { |
| 937 | Ok(Conversations::new(self.session()) |
| 938 | .set_read_horizon(conversation_id, horizon) |
| 939 | .await?) |
| 940 | } |
| 941 | |
| 942 | async fn set_read_bookmark(&self, conversation_id: &str, bookmark: &str) -> Result<()> { |
| 943 | Ok(Conversations::new(self.session()) |
| 944 | .set_read_bookmark(conversation_id, bookmark) |
| 945 | .await?) |
| 946 | } |
| 947 | |
| 948 | async fn set_chat_hidden_at(&self, chat_id: &str, hidden_at_ms: Option<i64>) -> Result<()> { |
| 949 | Ok(Conversations::new(self.session()) |
| 950 | .set_hidden_at(chat_id, hidden_at_ms) |
| 951 | .await?) |
| 952 | } |
| 953 | |
| 954 | async fn set_channel_notifications( |
| 955 | &self, |
| 956 | channel_id: &str, |
| 957 | notifications: store::ChannelNotifications, |
| 958 | ) -> Result<()> { |
| 959 | Ok(Conversations::new(self.session()) |
| 960 | .set_channel_notifications( |
| 961 | channel_id, |
| 962 | crate::folders::chatsvc_notifications(notifications), |
| 963 | ) |
| 964 | .await?) |
| 965 | } |
| 966 | |
| 967 | async fn send_typing(&self, conversation: &ConversationRef, active: bool) -> Result<()> { |
| 968 | Ok(Messages::new(self.session()) |
| 969 | .send_typing(conversation, active) |
| 970 | .await?) |
| 971 | } |
| 972 | |
| 973 | /// Teams `ackUrgentMessage`: the emotion `acks` on the message stops the urgent repeat notifications. |
| 974 | async fn ack_urgent_message(&self, chat_id: &str, message_id: &str) -> Result<()> { |
| 975 | Ok(Messages::new(self.session()) |
| 976 | .set_emotion( |
| 977 | &ConversationRef::chat(chat_id), |
| 978 | message_id, |
| 979 | URGENT_ACK_EMOTION, |
| 980 | ) |
| 981 | .await?) |
| 982 | } |
| 983 | |
| 984 | async fn set_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> { |
| 985 | if let Some(key) = chatsvc::reaction_key(reaction_type) { |
| 986 | return Ok(Messages::new(self.session()) |
| 987 | .set_emotion(&conversation_ref(target), target.message_id(), &key) |
| 988 | .await?); |
| 989 | } |
| 990 | Ok(Graph::set_reaction(self, target, reaction_type).await?) |
| 991 | } |
| 992 | |
| 993 | async fn unset_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> { |
| 994 | let keys = chatsvc::reaction_keys(reaction_type); |
| 995 | if !keys.is_empty() { |
| 996 | let keys: Vec<&str> = keys.iter().map(String::as_str).collect(); |
| 997 | return Ok(Messages::new(self.session()) |
| 998 | .unset_emotions(&conversation_ref(target), target.message_id(), &keys) |
| 999 | .await?); |
| 1000 | } |
| 1001 | Ok(Graph::unset_reaction(self, target, reaction_type).await?) |
| 1002 | } |
| 1003 | |
| 1004 | async fn edit_message( |
| 1005 | &self, |
| 1006 | target: &MessageTarget, |
| 1007 | html: &str, |
| 1008 | mentions: &[OutgoingMention], |
| 1009 | extras: &MessageExtras, |
| 1010 | ) -> Result<()> { |
| 1011 | match chatsvc_conversation(target) { |
| 1012 | Some(conversation) if mentions.is_empty() => { |
| 1013 | let html = format!("{}{html}{}", extras.kept_html(), extras.files_html()); |
| 1014 | Ok(Messages::new(self.session()) |
| 1015 | .edit_message(&conversation, target.message_id(), &html) |
| 1016 | .await?) |
| 1017 | } |
| 1018 | Some(_) => Err(Error::Unsupported( |
| 1019 | "editing a channel message with mentions", |
| 1020 | )), |
| 1021 | None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?), |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | async fn soft_delete_message(&self, user_id: &str, target: &MessageTarget) -> Result<()> { |
| 1026 | match chatsvc_conversation(target) { |
| 1027 | Some(conversation) => Ok(Messages::new(self.session()) |
| 1028 | .soft_delete_message(&conversation, target.message_id()) |
| 1029 | .await?), |
| 1030 | None => Ok(Graph::soft_delete_message(self, user_id, target).await?), |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | async fn undo_soft_delete_message(&self, user_id: &str, target: &MessageTarget) -> Result<()> { |
| 1035 | match chatsvc_conversation(target) { |
| 1036 | Some(conversation) => Ok(Messages::new(self.session()) |
| 1037 | .undelete_message(&conversation, target.message_id()) |
| 1038 | .await?), |
| 1039 | None => Ok(Graph::undo_soft_delete_message(self, user_id, target).await?), |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | async fn create_one_on_one(&self, my_user_id: &str, user_id: &str) -> Result<Chat> { |
| 1044 | Ok(Graph::create_one_on_one(self, my_user_id, user_id).await?) |
| 1045 | } |
| 1046 | |
| 1047 | async fn create_group( |
| 1048 | &self, |
| 1049 | my_user_id: &str, |
| 1050 | user_ids: &[String], |
| 1051 | topic: Option<&str>, |
| 1052 | ) -> Result<Chat> { |
| 1053 | Ok(Graph::create_group(self, my_user_id, user_ids, topic).await?) |
| 1054 | } |
| 1055 | |
| 1056 | async fn search_people(&self, query: &str) -> Result<Vec<User>> { |
| 1057 | Ok(Graph::search_people(self, query).await?) |
| 1058 | } |
| 1059 | |
| 1060 | async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> { |
| 1061 | Ok(Graph::team_tags(self, team_id).await?) |
| 1062 | } |
| 1063 | |
| 1064 | async fn channel_description(&self, team_id: &str, channel_id: &str) -> Result<String> { |
| 1065 | Ok(Graph::channel_description(self, team_id, channel_id).await?) |
| 1066 | } |
| 1067 | |
| 1068 | async fn reply_with_quote( |
| 1069 | &self, |
| 1070 | chat_id: &str, |
| 1071 | quoted_message_id: &str, |
| 1072 | html: &str, |
| 1073 | mentions: &[OutgoingMention], |
| 1074 | extras: &MessageExtras, |
| 1075 | ) -> Result<Message> { |
| 1076 | Ok( |
| 1077 | Graph::reply_with_quote(self, chat_id, quoted_message_id, html, mentions, extras) |
| 1078 | .await?, |
| 1079 | ) |
| 1080 | } |
| 1081 | |
| 1082 | async fn channel_files_folder(&self, team_id: &str, channel_id: &str) -> Result<DriveFolder> { |
| 1083 | Ok(Graph::channel_files_folder(self, team_id, channel_id).await?) |
| 1084 | } |
| 1085 | |
| 1086 | async fn channel_files_root(&self, team_id: &str, channel_id: &str) -> Result<DriveEntry> { |
| 1087 | Ok(Graph::channel_files_root(self, team_id, channel_id).await?) |
| 1088 | } |
| 1089 | |
| 1090 | async fn channel_tab_web_url( |
| 1091 | &self, |
| 1092 | team_id: &str, |
| 1093 | channel_id: &str, |
| 1094 | tab_id: &str, |
| 1095 | ) -> Result<Option<String>> { |
| 1096 | Ok(Graph::channel_tab_web_url(self, team_id, channel_id, tab_id).await?) |
| 1097 | } |
| 1098 | |
| 1099 | async fn channel_member_count(&self, team_id: &str, channel_id: &str) -> Result<usize> { |
| 1100 | Ok(Graph::channel_member_count(self, team_id, channel_id).await?) |
| 1101 | } |
| 1102 | |
| 1103 | async fn channel_members(&self, team_id: &str, channel_id: &str) -> Result<Vec<graph::Member>> { |
| 1104 | Ok(Graph::channel_member_list(self, team_id, channel_id).await?) |
| 1105 | } |
| 1106 | |
| 1107 | async fn list_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> { |
| 1108 | Ok(Graph::list_children(self, folder).await?) |
| 1109 | } |
| 1110 | |
| 1111 | async fn create_folder(&self, parent: &DriveFolder, name: &str) -> Result<DriveEntry> { |
| 1112 | Ok(Graph::create_folder(self, parent, name).await?) |
| 1113 | } |
| 1114 | |
| 1115 | async fn upload_file( |
| 1116 | &self, |
| 1117 | destination: &UploadDestination, |
| 1118 | file_name: &str, |
| 1119 | bytes: &[u8], |
| 1120 | progress: &(dyn Fn(u8) + Send + Sync), |
| 1121 | ) -> Result<UploadedFile> { |
| 1122 | Ok(Graph::upload_file(self, destination, file_name, bytes, progress).await?) |
| 1123 | } |
| 1124 | |
| 1125 | async fn share_file(&self, file: &UploadedFile, user_ids: &[String]) -> Result<()> { |
| 1126 | Ok(Graph::share_item(self, file, user_ids).await?) |
| 1127 | } |
| 1128 | |
| 1129 | async fn recent_files(&self, top: usize) -> Result<Vec<CloudFile>> { |
| 1130 | Ok(Graph::recent_files(self, top).await?) |
| 1131 | } |
| 1132 | |
| 1133 | async fn recent_files_with_owners(&self, top: usize) -> Result<(Vec<CloudFile>, Vec<(String, String)>)> { |
| 1134 | Ok(Graph::recent_files_with_owners(self, top).await?) |
| 1135 | } |
| 1136 | |
| 1137 | async fn shared_with_me(&self) -> Result<Vec<DriveEntry>> { |
| 1138 | Ok(Graph::shared_with_me(self).await?) |
| 1139 | } |
| 1140 | |
| 1141 | async fn quick_access_sites(&self) -> Result<Vec<QuickSite>> { |
| 1142 | Ok(Graph::quick_access_sites(self).await?) |
| 1143 | } |
| 1144 | |
| 1145 | async fn drive_root(&self, site_id: Option<&str>) -> Result<DriveFolder> { |
| 1146 | Ok(Graph::drive_root(self, site_id).await?) |
| 1147 | } |
| 1148 | |
| 1149 | async fn cloud_file_reference(&self, file: &CloudFile) -> Result<UploadedFile> { |
| 1150 | Ok(Graph::cloud_file_reference(self, file).await?) |
| 1151 | } |
| 1152 | |
| 1153 | async fn delete_file(&self, file: &UploadedFile) -> Result<()> { |
| 1154 | Ok(Graph::delete_drive_item(self, &file.drive_id, &file.item_id).await?) |
| 1155 | } |
| 1156 | |
| 1157 | async fn resolve_share(&self, open_url: &str) -> Result<SharedFile> { |
| 1158 | Ok(Graph::resolve_share(self, open_url).await?) |
| 1159 | } |
| 1160 | |
| 1161 | async fn resolve_drive_item(&self, drive_id: &str, item_id: &str) -> Result<SharedFile> { |
| 1162 | Ok(Graph::resolve_drive_item(self, drive_id, item_id).await?) |
| 1163 | } |
| 1164 | |
| 1165 | async fn download_range( |
| 1166 | &self, |
| 1167 | download_url: &str, |
| 1168 | start: u64, |
| 1169 | end: Option<u64>, |
| 1170 | ) -> Result<Vec<u8>> { |
| 1171 | Ok(Graph::download_range(self, download_url, start, end).await?) |
| 1172 | } |
| 1173 | |
| 1174 | async fn hosted_content(&self, url: &str) -> Result<Photo> { |
| 1175 | if chatsvc::is_link_image_url(url) { |
| 1176 | let image = Messages::new(self.session()).link_image(url).await?; |
| 1177 | return Ok(Photo { |
| 1178 | bytes: image.bytes, |
| 1179 | content_type: image.content_type, |
| 1180 | }); |
| 1181 | } |
| 1182 | Ok(Graph::download_hosted_content(self, url).await?) |
| 1183 | } |
| 1184 | |
| 1185 | async fn external_image(&self, url: &str) -> Result<Photo> { |
| 1186 | Ok(Graph::download_external_image(self, url).await?) |
| 1187 | } |
| 1188 | |
| 1189 | async fn user_photos(&self, user_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> { |
| 1190 | let photos = Graph::user_photos(self, user_ids).await?; |
| 1191 | Ok(photos |
| 1192 | .into_iter() |
| 1193 | .map(|photo| photo.map_err(Into::into)) |
| 1194 | .collect()) |
| 1195 | } |
| 1196 | |
| 1197 | async fn team_photos(&self, team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> { |
| 1198 | let photos = Graph::team_photos(self, team_ids).await?; |
| 1199 | Ok(photos |
| 1200 | .into_iter() |
| 1201 | .map(|photo| photo.map_err(Into::into)) |
| 1202 | .collect()) |
| 1203 | } |
| 1204 | |
| 1205 | async fn presences(&self, user_ids: &[String]) -> Result<Vec<Presence>> { |
| 1206 | let found = PresenceLookup::new(self.session()) |
| 1207 | .presences(user_ids) |
| 1208 | .await?; |
| 1209 | Ok(found |
| 1210 | .into_iter() |
| 1211 | .map(|presence| Presence { |
| 1212 | user_id: presence.user_id, |
| 1213 | availability: presence.availability, |
| 1214 | activity: presence.activity, |
| 1215 | }) |
| 1216 | .collect()) |
| 1217 | } |
| 1218 | |
| 1219 | async fn person_profile(&self, user_id: &str) -> Result<PersonProfile> { |
| 1220 | crate::profile::load_profile(self, user_id).await |
| 1221 | } |
| 1222 | |
| 1223 | async fn bot_profiles(&self, bot_ids: &[String]) -> Result<Vec<BotProfile>> { |
| 1224 | Ok(BotProfiles::new(self.session()).fetch(bot_ids).await?) |
| 1225 | } |
| 1226 | |
| 1227 | async fn subscribe_presence( |
| 1228 | &self, |
| 1229 | endpoint_id: &str, |
| 1230 | trouter_uri: &str, |
| 1231 | user_ids: &[String], |
| 1232 | purge: bool, |
| 1233 | ) -> Result<()> { |
| 1234 | Ok(PresenceLookup::new(self.session()) |
| 1235 | .subscribe(endpoint_id, trouter_uri, user_ids, purge) |
| 1236 | .await?) |
| 1237 | } |
| 1238 | |
| 1239 | async fn own_status(&self, user_id: &str) -> Result<PresenceStatus> { |
| 1240 | Ok(PresenceService::new(self.session()).status(user_id).await?) |
| 1241 | } |
| 1242 | |
| 1243 | async fn set_availability(&self, forced: Option<&ForcedAvailability>) -> Result<()> { |
| 1244 | Ok(PresenceService::new(self.session()) |
| 1245 | .set_availability(forced) |
| 1246 | .await?) |
| 1247 | } |
| 1248 | |
| 1249 | async fn set_status_note(&self, note: Option<&StatusNote>) -> Result<()> { |
| 1250 | Ok(PresenceService::new(self.session()).set_note(note).await?) |
| 1251 | } |
| 1252 | |
| 1253 | async fn set_work_location( |
| 1254 | &self, |
| 1255 | location: Option<(WorkLocationKind, DateTime<Utc>)>, |
| 1256 | ) -> Result<()> { |
| 1257 | Ok(PresenceService::new(self.session()) |
| 1258 | .set_work_location(location) |
| 1259 | .await?) |
| 1260 | } |
| 1261 | |
| 1262 | async fn consumption_horizons(&self, conversation_id: &str) -> Result<Vec<MemberHorizon>> { |
| 1263 | Ok(Receipts::new(self.session()) |
| 1264 | .consumption_horizons(conversation_id) |
| 1265 | .await?) |
| 1266 | } |
| 1267 | |
| 1268 | async fn forward_messages( |
| 1269 | &self, |
| 1270 | source_conversation_id: &str, |
| 1271 | target_conversation_id: &str, |
| 1272 | message_ids: &[String], |
| 1273 | comment_html: &str, |
| 1274 | ) -> Result<ForwardResult> { |
| 1275 | Ok(Messages::new(self.session()) |
| 1276 | .forward_messages( |
| 1277 | source_conversation_id, |
| 1278 | target_conversation_id, |
| 1279 | message_ids, |
| 1280 | comment_html, |
| 1281 | ) |
| 1282 | .await?) |
| 1283 | } |
| 1284 | |
| 1285 | async fn set_saved( |
| 1286 | &self, |
| 1287 | conversation_id: &str, |
| 1288 | root_id: &str, |
| 1289 | message_id: &str, |
| 1290 | saved: bool, |
| 1291 | ) -> Result<()> { |
| 1292 | Ok(Messages::new(self.session()) |
| 1293 | .set_saved(conversation_id, root_id, message_id, saved) |
| 1294 | .await?) |
| 1295 | } |
| 1296 | |
| 1297 | async fn list_saved(&self) -> Result<Vec<SavedMessage>> { |
| 1298 | Ok(Messages::new(self.session()).list_saved().await?) |
| 1299 | } |
| 1300 | |
| 1301 | async fn set_post_followed( |
| 1302 | &self, |
| 1303 | user_id: &str, |
| 1304 | channel_id: &str, |
| 1305 | root_id: &str, |
| 1306 | followed: bool, |
| 1307 | ) -> Result<Option<String>> { |
| 1308 | Ok(Messages::new(self.session()) |
| 1309 | .set_post_followed(user_id, channel_id, root_id, followed) |
| 1310 | .await?) |
| 1311 | } |
| 1312 | |
| 1313 | async fn post_follow_states( |
| 1314 | &self, |
| 1315 | channel_id: &str, |
| 1316 | root_ids: &[String], |
| 1317 | ) -> Result<HashMap<String, PostFollowState>> { |
| 1318 | Ok(Messages::new(self.session()) |
| 1319 | .post_follow_states(channel_id, root_ids) |
| 1320 | .await?) |
| 1321 | } |
| 1322 | |
| 1323 | async fn list_call_logs(&self) -> Result<Vec<CallLogEntry>> { |
| 1324 | Ok(Messages::new(self.session()).list_call_logs().await?) |
| 1325 | } |
| 1326 | |
| 1327 | async fn chat_message_window( |
| 1328 | &self, |
| 1329 | chat_id: &str, |
| 1330 | anchor_id: &str, |
| 1331 | direction: WindowDirection, |
| 1332 | page_size: usize, |
| 1333 | ) -> Result<MessageWindow> { |
| 1334 | Ok(Messages::new(self.session()) |
| 1335 | .message_window(chat_id, anchor_id, direction, page_size) |
| 1336 | .await?) |
| 1337 | } |
| 1338 | |
| 1339 | async fn chat_thread_activities(&self, chat_id: &str) -> Result<Vec<ThreadActivity>> { |
| 1340 | Ok(Messages::new(self.session()).thread_activities(chat_id).await?) |
| 1341 | } |
| 1342 | |
| 1343 | async fn chat_messages_by_id( |
| 1344 | &self, |
| 1345 | chat_id: &str, |
| 1346 | message_ids: &[String], |
| 1347 | ) -> Result<Vec<Result<Message>>> { |
| 1348 | let messages = Graph::chat_messages_by_id(self, chat_id, message_ids).await?; |
| 1349 | Ok(messages |
| 1350 | .into_iter() |
| 1351 | .map(|message| message.map_err(Into::into)) |
| 1352 | .collect()) |
| 1353 | } |
| 1354 | |
| 1355 | async fn chat_pins(&self, chat_id: &str) -> Result<Vec<PinnedMessage>> { |
| 1356 | Ok(Pins::new(self.session()).chat_pins(chat_id).await?) |
| 1357 | } |
| 1358 | |
| 1359 | async fn pin_message(&self, chat_id: &str, message_id: &str) -> Result<()> { |
| 1360 | Ok(Pins::new(self.session()) |
| 1361 | .pin_message(chat_id, message_id) |
| 1362 | .await?) |
| 1363 | } |
| 1364 | |
| 1365 | async fn unpin_message( |
| 1366 | &self, |
| 1367 | chat_id: &str, |
| 1368 | message_id: &str, |
| 1369 | parent_id: Option<&str>, |
| 1370 | ) -> Result<()> { |
| 1371 | Ok(Pins::new(self.session()) |
| 1372 | .unpin_message(chat_id, message_id, parent_id) |
| 1373 | .await?) |
| 1374 | } |
| 1375 | |
| 1376 | async fn channel_pinned_posts( |
| 1377 | &self, |
| 1378 | team_thread_id: &str, |
| 1379 | channel_id: &str, |
| 1380 | ) -> Result<Vec<PinnedMessage>> { |
| 1381 | Ok(Pins::with_skype_token(self.session()) |
| 1382 | .channel_pinned_posts(team_thread_id, channel_id) |
| 1383 | .await?) |
| 1384 | } |
| 1385 | |
| 1386 | async fn set_post_pinned( |
| 1387 | &self, |
| 1388 | team_thread_id: &str, |
| 1389 | channel_id: &str, |
| 1390 | post_id: &str, |
| 1391 | pinned: bool, |
| 1392 | ) -> Result<()> { |
| 1393 | Ok(Pins::with_skype_token(self.session()) |
| 1394 | .set_post_pinned(team_thread_id, channel_id, post_id, pinned) |
| 1395 | .await?) |
| 1396 | } |
| 1397 | |
| 1398 | async fn activity_feed(&self) -> Result<ActivitySnapshot> { |
| 1399 | Ok(ActivityFeed::new(self.session()).snapshot().await?) |
| 1400 | } |
| 1401 | |
| 1402 | async fn mark_activity_read(&self, message_id: &str) -> Result<()> { |
| 1403 | Ok(ActivityFeed::new(self.session()).mark_read(message_id).await?) |
| 1404 | } |
| 1405 | |
| 1406 | async fn mark_all_activity_read(&self, now_ms: i64) -> Result<()> { |
| 1407 | Ok(ActivityFeed::new(self.session()).mark_all_read(now_ms).await?) |
| 1408 | } |
| 1409 | |
| 1410 | async fn app_consumption_horizon(&self) -> Result<AppConsumptionHorizon> { |
| 1411 | let properties = UserSettings::new(self.session()).properties().await?; |
| 1412 | Ok(parse_app_consumption_horizon(&properties)) |
| 1413 | } |
| 1414 | |
| 1415 | async fn mark_all_channels_read(&self, now_ms: i64) -> Result<AppConsumptionHorizon> { |
| 1416 | Ok(UserSettings::new(self.session()) |
| 1417 | .mark_all_channels_read(now_ms) |
| 1418 | .await?) |
| 1419 | } |
| 1420 | |
| 1421 | async fn chat_apps(&self, chat_id: &str) -> Result<Vec<ChatApp>> { |
| 1422 | Ok(CardActions::new(self.session()).chat_apps(chat_id).await?) |
| 1423 | } |
| 1424 | |
| 1425 | async fn invoke_card(&self, invoke: InvokeRequest) -> Result<InvokeResponse> { |
| 1426 | Ok(CardActions::new(self.session()).invoke(invoke).await?) |
| 1427 | } |
| 1428 | |
| 1429 | async fn message_links( |
| 1430 | &self, |
| 1431 | conversation: &ConversationRef, |
| 1432 | page_size: usize, |
| 1433 | ) -> Result<Vec<MessageLinks>> { |
| 1434 | Ok(Messages::new(self.session()) |
| 1435 | .list_message_links(conversation, page_size) |
| 1436 | .await?) |
| 1437 | } |
| 1438 | |
| 1439 | async fn message_emotions( |
| 1440 | &self, |
| 1441 | conversation: &ConversationRef, |
| 1442 | newest_message_id: &str, |
| 1443 | page_size: usize, |
| 1444 | ) -> Result<Vec<MessageEmotions>> { |
| 1445 | Ok(Messages::new(self.session()) |
| 1446 | .message_emotions( |
| 1447 | &conversation.conversation_id(), |
| 1448 | newest_message_id, |
| 1449 | page_size, |
| 1450 | ) |
| 1451 | .await?) |
| 1452 | } |
| 1453 | |
| 1454 | async fn set_message_links(&self, target: &MessageTarget, links_json: &str) -> Result<()> { |
| 1455 | Ok(Messages::new(self.session()) |
| 1456 | .set_links(&conversation_ref(target), target.message_id(), links_json) |
| 1457 | .await?) |
| 1458 | } |
| 1459 | |
| 1460 | async fn link_info(&self, url: &str) -> Result<LinkInfo> { |
| 1461 | Ok(Messages::new(self.session()).link_info(url).await?) |
| 1462 | } |
| 1463 | |
| 1464 | async fn message_languages( |
| 1465 | &self, |
| 1466 | conversation: &ConversationRef, |
| 1467 | page_size: usize, |
| 1468 | ) -> Result<Vec<MessageLanguage>> { |
| 1469 | Ok(Messages::new(self.session()) |
| 1470 | .list_language_stamps(conversation, page_size) |
| 1471 | .await?) |
| 1472 | } |
| 1473 | |
| 1474 | async fn ask_copilot(&self, ask: &CopilotAsk) -> Result<String> { |
| 1475 | Ok(Copilot::new(self.session()).ask(ask).await?) |
| 1476 | } |
| 1477 | |
| 1478 | async fn rewrite_draft(&self, rewrite: &ComposeRewrite) -> Result<String> { |
| 1479 | Ok(ComposeCopilot::new(self.session()).rewrite(rewrite).await?) |
| 1480 | } |
| 1481 | |
| 1482 | async fn translate_chat_messages( |
| 1483 | &self, |
| 1484 | chat_id: &str, |
| 1485 | to_language: &str, |
| 1486 | messages: &[TranslateRequest], |
| 1487 | trigger: &TranslationTrigger, |
| 1488 | ) -> Result<Vec<Translation>> { |
| 1489 | Ok(Translator::new(self.session()) |
| 1490 | .translate_chat(chat_id, to_language, messages, trigger) |
| 1491 | .await?) |
| 1492 | } |
| 1493 | |
| 1494 | async fn translate_channel_messages( |
| 1495 | &self, |
| 1496 | team_id: &str, |
| 1497 | channel_id: &str, |
| 1498 | root_id: &str, |
| 1499 | to_language: &str, |
| 1500 | messages: &[TranslateRequest], |
| 1501 | trigger: &TranslationTrigger, |
| 1502 | ) -> Result<Vec<Translation>> { |
| 1503 | Ok(Translator::new(self.session()) |
| 1504 | .translate_channel(team_id, channel_id, root_id, to_language, messages, trigger) |
| 1505 | .await?) |
| 1506 | } |
| 1507 | |
| 1508 | async fn translation_languages(&self, locale: &str) -> Result<Vec<Language>> { |
| 1509 | Ok(Translator::new(self.session()).languages(locale).await?) |
| 1510 | } |
| 1511 | |
| 1512 | async fn language_settings(&self) -> Result<LanguageSettings> { |
| 1513 | Ok(LanguageSettingsClient::new(self.session()).read().await?) |
| 1514 | } |
| 1515 | |
| 1516 | async fn recording_policy(&self) -> Result<RecordingPolicy> { |
| 1517 | Ok(LanguageSettingsClient::new(self.session()) |
| 1518 | .read_recording_policy() |
| 1519 | .await?) |
| 1520 | } |
| 1521 | |
| 1522 | async fn allow_priority_messages(&self) -> Result<bool> { |
| 1523 | Ok(LanguageSettingsClient::new(self.session()) |
| 1524 | .read_allow_priority_messages() |
| 1525 | .await?) |
| 1526 | } |
| 1527 | |
| 1528 | async fn patch_language_settings(&self, patch: serde_json::Value) -> Result<()> { |
| 1529 | Ok(LanguageSettingsClient::new(self.session()) |
| 1530 | .patch(patch) |
| 1531 | .await?) |
| 1532 | } |
| 1533 | |
| 1534 | async fn sound_settings(&self) -> Result<SoundSettings> { |
| 1535 | Ok(SoundSettingsClient::new(self.session()).read().await?) |
| 1536 | } |
| 1537 | |
| 1538 | async fn chat_settings(&self) -> Result<ChatSettingsDocument> { |
| 1539 | Ok(ChatSettingsClient::new(self.session()).read().await?) |
| 1540 | } |
| 1541 | |
| 1542 | async fn save_chat_setting(&self, change: ChatSettingChange) -> Result<ChatSettingsDocument> { |
| 1543 | Ok(ChatSettingsClient::new(self.session()).write(change).await?) |
| 1544 | } |
| 1545 | |
| 1546 | async fn set_chat_notifications( |
| 1547 | &self, |
| 1548 | chat_id: &str, |
| 1549 | current_settings: Option<&str>, |
| 1550 | mode: ChatNotificationMode, |
| 1551 | desktop: DesktopNotifications, |
| 1552 | ) -> Result<ChatNotificationWrite> { |
| 1553 | Ok(Conversations::new(self.session()) |
| 1554 | .set_chat_notifications(chat_id, current_settings, mode, desktop) |
| 1555 | .await?) |
| 1556 | } |
| 1557 | |
| 1558 | async fn save_sound_settings( |
| 1559 | &self, |
| 1560 | user_mri: &str, |
| 1561 | previous: &SoundSettings, |
| 1562 | updated: &SoundSettings, |
| 1563 | ) -> Result<()> { |
| 1564 | Ok(SoundSettingsClient::new(self.session()) |
| 1565 | .write(user_mri, previous, updated) |
| 1566 | .await?) |
| 1567 | } |
| 1568 | |
| 1569 | async fn search_gifs(&self, query: &str) -> Result<Vec<Gif>> { |
| 1570 | Ok(Gifs::new(self.session()).search(query).await?) |
| 1571 | } |
| 1572 | |
| 1573 | async fn server_search_init( |
| 1574 | &self, |
| 1575 | identity: &SearchIdentity, |
| 1576 | search_session: &SearchSession, |
| 1577 | ) -> Result<()> { |
| 1578 | Ok(SubstrateSearch::new(self.session(), identity.clone()) |
| 1579 | .init(search_session) |
| 1580 | .await?) |
| 1581 | } |
| 1582 | |
| 1583 | async fn server_suggestions( |
| 1584 | &self, |
| 1585 | identity: &SearchIdentity, |
| 1586 | search_session: &SearchSession, |
| 1587 | text: &str, |
| 1588 | ) -> Result<Suggestions> { |
| 1589 | Ok(SubstrateSearch::new(self.session(), identity.clone()) |
| 1590 | .suggestions(search_session, text) |
| 1591 | .await?) |
| 1592 | } |
| 1593 | |
| 1594 | async fn server_query( |
| 1595 | &self, |
| 1596 | identity: &SearchIdentity, |
| 1597 | search_session: &SearchSession, |
| 1598 | request: &QueryRequest, |
| 1599 | ) -> Result<QueryResults> { |
| 1600 | Ok(SubstrateSearch::new(self.session(), identity.clone()) |
| 1601 | .query(search_session, request) |
| 1602 | .await?) |
| 1603 | } |
| 1604 | |
| 1605 | async fn create_scheduled( |
| 1606 | &self, |
| 1607 | inner_thread_id: &str, |
| 1608 | html: &str, |
| 1609 | send_at: DateTime<Utc>, |
| 1610 | display_name: &str, |
| 1611 | ) -> Result<ScheduledDraft> { |
| 1612 | Ok(ScheduledDrafts::new(self.session()) |
| 1613 | .create(inner_thread_id, html, send_at, display_name) |
| 1614 | .await?) |
| 1615 | } |
| 1616 | |
| 1617 | async fn scheduled_drafts(&self) -> Result<Vec<ScheduledDraft>> { |
| 1618 | Ok(ScheduledDrafts::new(self.session()).list().await?) |
| 1619 | } |
| 1620 | |
| 1621 | async fn update_scheduled( |
| 1622 | &self, |
| 1623 | draft: &ScheduledDraft, |
| 1624 | html: &str, |
| 1625 | display_name: &str, |
| 1626 | ) -> Result<ScheduledDraft> { |
| 1627 | Ok(ScheduledDrafts::new(self.session()) |
| 1628 | .update(draft, html, display_name) |
| 1629 | .await?) |
| 1630 | } |
| 1631 | |
| 1632 | async fn cancel_scheduled(&self, draft_id: &str) -> Result<()> { |
| 1633 | Ok(ScheduledDrafts::new(self.session()) |
| 1634 | .cancel(draft_id) |
| 1635 | .await?) |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | fn chatsvc_conversation(target: &MessageTarget) -> Option<ConversationRef> { |
| 1640 | match target { |
| 1641 | MessageTarget::Chat { .. } => CHATSVC_CHAT_WRITES.then(|| conversation_ref(target)), |
| 1642 | MessageTarget::Channel { .. } => Some(conversation_ref(target)), |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | fn conversation_ref(target: &MessageTarget) -> ConversationRef { |
| 1647 | match target { |
| 1648 | MessageTarget::Chat { chat_id, .. } => ConversationRef::chat(chat_id), |
| 1649 | MessageTarget::Channel { |
| 1650 | channel_id, |
| 1651 | root_id: None, |
| 1652 | .. |
| 1653 | } => ConversationRef::channel_root(channel_id), |
| 1654 | MessageTarget::Channel { |
| 1655 | channel_id, |
| 1656 | root_id: Some(root_id), |
| 1657 | .. |
| 1658 | } => ConversationRef::channel_reply(channel_id, root_id), |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | impl From<graph::Page<Message>> for RemotePage { |
| 1663 | fn from(page: graph::Page<Message>) -> Self { |
| 1664 | RemotePage { |
| 1665 | items: page.items, |
| 1666 | next_link: page.next_link, |
| 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | impl From<graph::Page<Message>> for DeltaPage { |
| 1672 | fn from(page: graph::Page<Message>) -> Self { |
| 1673 | DeltaPage { |
| 1674 | items: page.items, |
| 1675 | next_link: page.next_link, |
| 1676 | delta_link: page.delta_link, |
| 1677 | } |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | impl From<graph::Page<Chat>> for ChatsPage { |
| 1682 | fn from(page: graph::Page<Chat>) -> Self { |
| 1683 | ChatsPage { |
| 1684 | items: page.items, |
| 1685 | next_link: page.next_link, |
| 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | #[cfg(test)] |
| 1691 | mod tests { |
| 1692 | use super::*; |
| 1693 | |
| 1694 | #[test] |
| 1695 | fn channel_targets_route_to_chatsvc() { |
| 1696 | let root = MessageTarget::channel("t", "19:c@thread.tacv2", "m1", None); |
| 1697 | let reply = MessageTarget::channel("t", "19:c@thread.tacv2", "r1", Some("m1")); |
| 1698 | assert_eq!( |
| 1699 | chatsvc_conversation(&root), |
| 1700 | Some(ConversationRef::channel_root("19:c@thread.tacv2")) |
| 1701 | ); |
| 1702 | assert_eq!( |
| 1703 | chatsvc_conversation(&reply), |
| 1704 | Some(ConversationRef::channel_reply("19:c@thread.tacv2", "m1")) |
| 1705 | ); |
| 1706 | } |
| 1707 | |
| 1708 | #[test] |
| 1709 | fn reactions_reach_chats_regardless_of_the_feature_switch() { |
| 1710 | let chat = MessageTarget::chat("19:a@thread.v2", "m1"); |
| 1711 | assert_eq!( |
| 1712 | conversation_ref(&chat), |
| 1713 | ConversationRef::chat("19:a@thread.v2") |
| 1714 | ); |
| 1715 | } |
| 1716 | |
| 1717 | #[test] |
| 1718 | fn chats_follow_the_feature_switch() { |
| 1719 | let chat = MessageTarget::chat("19:a@thread.v2", "m1"); |
| 1720 | assert_eq!(chatsvc_conversation(&chat).is_some(), CHATSVC_CHAT_WRITES); |
| 1721 | } |
| 1722 | } |