BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / remote.rs

remote.rs

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