BlueGit

ict rusty-teams

Files

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

remote.rs

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