BlueGit

ict rusty-teams

Files

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

remote.rs

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