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