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