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