BlueGit

ict rusty-teams

Files

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

remote.rs

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