BlueGit

ict rusty-teams

Files

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

remote.rs

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