BlueGit

ict rusty-teams

Files

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

remote.rs

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