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