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