BlueGit

ict rusty-teams

Files

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

remote.rs

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