BlueGit

ict rusty-teams

Files

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

remote.rs

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