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