BlueGit

ict rusty-teams

Files

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

remote.rs

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