BlueGit

ict rusty-teams

Files

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

remote.rs

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