BlueGit

ict rusty-teams

Files

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

remote.rs

remote.rs 54.0 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 let image = if chatsvc::is_ams_image_url(url) {
1167 chatsvc::ams::Ams::new(self.session())
1168 .download_image(url)
1169 .await?
1170 } else if chatsvc::is_link_image_url(url) {
1171 Messages::new(self.session()).link_image(url).await?
1172 } else {
1173 return Ok(Graph::download_hosted_content(self, url).await?);
1174 };
1175 Ok(Photo {
1176 bytes: image.bytes,
1177 content_type: image.content_type,
1178 })
1179 }
1180
1181 async fn external_image(&self, url: &str) -> Result<Photo> {
1182 Ok(Graph::download_external_image(self, url).await?)
1183 }
1184
1185 async fn user_photos(&self, user_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
1186 let photos = Graph::user_photos(self, user_ids).await?;
1187 Ok(photos
1188 .into_iter()
1189 .map(|photo| photo.map_err(Into::into))
1190 .collect())
1191 }
1192
1193 async fn team_photos(&self, team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
1194 let photos = Graph::team_photos(self, team_ids).await?;
1195 Ok(photos
1196 .into_iter()
1197 .map(|photo| photo.map_err(Into::into))
1198 .collect())
1199 }
1200
1201 async fn presences(&self, user_ids: &[String]) -> Result<Vec<Presence>> {
1202 let found = PresenceLookup::new(self.session())
1203 .presences(user_ids)
1204 .await?;
1205 Ok(found
1206 .into_iter()
1207 .map(|presence| Presence {
1208 user_id: presence.user_id,
1209 availability: presence.availability,
1210 activity: presence.activity,
1211 })
1212 .collect())
1213 }
1214
1215 async fn person_profile(&self, user_id: &str) -> Result<PersonProfile> {
1216 crate::profile::load_profile(self, user_id).await
1217 }
1218
1219 async fn bot_profiles(&self, bot_ids: &[String]) -> Result<Vec<BotProfile>> {
1220 Ok(BotProfiles::new(self.session()).fetch(bot_ids).await?)
1221 }
1222
1223 async fn subscribe_presence(
1224 &self,
1225 endpoint_id: &str,
1226 trouter_uri: &str,
1227 user_ids: &[String],
1228 purge: bool,
1229 ) -> Result<()> {
1230 Ok(PresenceLookup::new(self.session())
1231 .subscribe(endpoint_id, trouter_uri, user_ids, purge)
1232 .await?)
1233 }
1234
1235 async fn own_status(&self, user_id: &str) -> Result<PresenceStatus> {
1236 Ok(PresenceService::new(self.session()).status(user_id).await?)
1237 }
1238
1239 async fn set_availability(&self, forced: Option<&ForcedAvailability>) -> Result<()> {
1240 Ok(PresenceService::new(self.session())
1241 .set_availability(forced)
1242 .await?)
1243 }
1244
1245 async fn set_status_note(&self, note: Option<&StatusNote>) -> Result<()> {
1246 Ok(PresenceService::new(self.session()).set_note(note).await?)
1247 }
1248
1249 async fn set_work_location(
1250 &self,
1251 location: Option<(WorkLocationKind, DateTime<Utc>)>,
1252 ) -> Result<()> {
1253 Ok(PresenceService::new(self.session())
1254 .set_work_location(location)
1255 .await?)
1256 }
1257
1258 async fn consumption_horizons(&self, conversation_id: &str) -> Result<Vec<MemberHorizon>> {
1259 Ok(Receipts::new(self.session())
1260 .consumption_horizons(conversation_id)
1261 .await?)
1262 }
1263
1264 async fn forward_messages(
1265 &self,
1266 source_conversation_id: &str,
1267 target_conversation_id: &str,
1268 message_ids: &[String],
1269 comment_html: &str,
1270 ) -> Result<ForwardResult> {
1271 Ok(Messages::new(self.session())
1272 .forward_messages(
1273 source_conversation_id,
1274 target_conversation_id,
1275 message_ids,
1276 comment_html,
1277 )
1278 .await?)
1279 }
1280
1281 async fn set_saved(
1282 &self,
1283 conversation_id: &str,
1284 root_id: &str,
1285 message_id: &str,
1286 saved: bool,
1287 ) -> Result<()> {
1288 Ok(Messages::new(self.session())
1289 .set_saved(conversation_id, root_id, message_id, saved)
1290 .await?)
1291 }
1292
1293 async fn list_saved(&self) -> Result<Vec<SavedMessage>> {
1294 Ok(Messages::new(self.session()).list_saved().await?)
1295 }
1296
1297 async fn set_post_followed(
1298 &self,
1299 user_id: &str,
1300 channel_id: &str,
1301 root_id: &str,
1302 followed: bool,
1303 ) -> Result<Option<String>> {
1304 Ok(Messages::new(self.session())
1305 .set_post_followed(user_id, channel_id, root_id, followed)
1306 .await?)
1307 }
1308
1309 async fn post_follow_states(
1310 &self,
1311 channel_id: &str,
1312 root_ids: &[String],
1313 ) -> Result<HashMap<String, PostFollowState>> {
1314 Ok(Messages::new(self.session())
1315 .post_follow_states(channel_id, root_ids)
1316 .await?)
1317 }
1318
1319 async fn list_call_logs(&self) -> Result<Vec<CallLogEntry>> {
1320 Ok(Messages::new(self.session()).list_call_logs().await?)
1321 }
1322
1323 async fn chat_message_window(
1324 &self,
1325 chat_id: &str,
1326 anchor_id: &str,
1327 direction: WindowDirection,
1328 page_size: usize,
1329 ) -> Result<MessageWindow> {
1330 Ok(Messages::new(self.session())
1331 .message_window(chat_id, anchor_id, direction, page_size)
1332 .await?)
1333 }
1334
1335 async fn chat_thread_activities(&self, chat_id: &str) -> Result<Vec<ThreadActivity>> {
1336 Ok(Messages::new(self.session())
1337 .thread_activities(chat_id)
1338 .await?)
1339 }
1340
1341 async fn chat_messages_by_id(
1342 &self,
1343 chat_id: &str,
1344 message_ids: &[String],
1345 ) -> Result<Vec<Result<Message>>> {
1346 let native = NativeChats::new(self.session());
1347 Ok(futures_util::future::join_all(
1348 message_ids
1349 .iter()
1350 .map(|message_id| native.message(chat_id, message_id)),
1351 )
1352 .await)
1353 }
1354
1355 async fn chat_pins(&self, chat_id: &str) -> Result<Vec<PinnedMessage>> {
1356 Ok(Pins::new(self.session()).chat_pins(chat_id).await?)
1357 }
1358
1359 async fn pin_message(&self, chat_id: &str, message_id: &str) -> Result<()> {
1360 Ok(Pins::new(self.session())
1361 .pin_message(chat_id, message_id)
1362 .await?)
1363 }
1364
1365 async fn unpin_message(
1366 &self,
1367 chat_id: &str,
1368 message_id: &str,
1369 parent_id: Option<&str>,
1370 ) -> Result<()> {
1371 Ok(Pins::new(self.session())
1372 .unpin_message(chat_id, message_id, parent_id)
1373 .await?)
1374 }
1375
1376 async fn channel_pinned_posts(
1377 &self,
1378 team_thread_id: &str,
1379 channel_id: &str,
1380 ) -> Result<Vec<PinnedMessage>> {
1381 Ok(Pins::with_skype_token(self.session())
1382 .channel_pinned_posts(team_thread_id, channel_id)
1383 .await?)
1384 }
1385
1386 async fn set_post_pinned(
1387 &self,
1388 team_thread_id: &str,
1389 channel_id: &str,
1390 post_id: &str,
1391 pinned: bool,
1392 ) -> Result<()> {
1393 Ok(Pins::with_skype_token(self.session())
1394 .set_post_pinned(team_thread_id, channel_id, post_id, pinned)
1395 .await?)
1396 }
1397
1398 async fn activity_feed(&self) -> Result<ActivitySnapshot> {
1399 Ok(ActivityFeed::new(self.session()).snapshot().await?)
1400 }
1401
1402 async fn mark_activity_read(&self, message_id: &str) -> Result<()> {
1403 Ok(ActivityFeed::new(self.session())
1404 .mark_read(message_id)
1405 .await?)
1406 }
1407
1408 async fn mark_all_activity_read(&self, now_ms: i64) -> Result<()> {
1409 Ok(ActivityFeed::new(self.session())
1410 .mark_all_read(now_ms)
1411 .await?)
1412 }
1413
1414 async fn app_consumption_horizon(&self) -> Result<AppConsumptionHorizon> {
1415 let properties = UserSettings::new(self.session()).properties().await?;
1416 Ok(parse_app_consumption_horizon(&properties))
1417 }
1418
1419 async fn mark_all_channels_read(&self, now_ms: i64) -> Result<AppConsumptionHorizon> {
1420 Ok(UserSettings::new(self.session())
1421 .mark_all_channels_read(now_ms)
1422 .await?)
1423 }
1424
1425 async fn chat_apps(&self, chat_id: &str) -> Result<Vec<ChatApp>> {
1426 Ok(CardActions::new(self.session()).chat_apps(chat_id).await?)
1427 }
1428
1429 async fn invoke_card(&self, invoke: InvokeRequest) -> Result<InvokeResponse> {
1430 Ok(CardActions::new(self.session()).invoke(invoke).await?)
1431 }
1432
1433 async fn message_links(
1434 &self,
1435 conversation: &ConversationRef,
1436 page_size: usize,
1437 ) -> Result<Vec<MessageLinks>> {
1438 Ok(Messages::new(self.session())
1439 .list_message_links(conversation, page_size)
1440 .await?)
1441 }
1442
1443 async fn message_emotions(
1444 &self,
1445 conversation: &ConversationRef,
1446 newest_message_id: &str,
1447 page_size: usize,
1448 ) -> Result<Vec<MessageEmotions>> {
1449 Ok(Messages::new(self.session())
1450 .message_emotions(
1451 &conversation.conversation_id(),
1452 newest_message_id,
1453 page_size,
1454 )
1455 .await?)
1456 }
1457
1458 async fn set_message_links(&self, target: &MessageTarget, links_json: &str) -> Result<()> {
1459 Ok(Messages::new(self.session())
1460 .set_links(&conversation_ref(target), target.message_id(), links_json)
1461 .await?)
1462 }
1463
1464 async fn link_info(&self, url: &str) -> Result<LinkInfo> {
1465 Ok(Messages::new(self.session()).link_info(url).await?)
1466 }
1467
1468 async fn message_languages(
1469 &self,
1470 conversation: &ConversationRef,
1471 page_size: usize,
1472 ) -> Result<Vec<MessageLanguage>> {
1473 Ok(Messages::new(self.session())
1474 .list_language_stamps(conversation, page_size)
1475 .await?)
1476 }
1477
1478 async fn ask_copilot(&self, ask: &CopilotAsk) -> Result<String> {
1479 Ok(Copilot::new(self.session()).ask(ask).await?)
1480 }
1481
1482 async fn rewrite_draft(&self, rewrite: &ComposeRewrite) -> Result<String> {
1483 Ok(ComposeCopilot::new(self.session()).rewrite(rewrite).await?)
1484 }
1485
1486 async fn translate_chat_messages(
1487 &self,
1488 chat_id: &str,
1489 to_language: &str,
1490 messages: &[TranslateRequest],
1491 trigger: &TranslationTrigger,
1492 ) -> Result<Vec<Translation>> {
1493 Ok(Translator::new(self.session())
1494 .translate_chat(chat_id, to_language, messages, trigger)
1495 .await?)
1496 }
1497
1498 async fn translate_channel_messages(
1499 &self,
1500 team_id: &str,
1501 channel_id: &str,
1502 root_id: &str,
1503 to_language: &str,
1504 messages: &[TranslateRequest],
1505 trigger: &TranslationTrigger,
1506 ) -> Result<Vec<Translation>> {
1507 Ok(Translator::new(self.session())
1508 .translate_channel(team_id, channel_id, root_id, to_language, messages, trigger)
1509 .await?)
1510 }
1511
1512 async fn translation_languages(&self, locale: &str) -> Result<Vec<Language>> {
1513 Ok(Translator::new(self.session()).languages(locale).await?)
1514 }
1515
1516 async fn language_settings(&self) -> Result<LanguageSettings> {
1517 Ok(LanguageSettingsClient::new(self.session()).read().await?)
1518 }
1519
1520 async fn recording_policy(&self) -> Result<RecordingPolicy> {
1521 Ok(LanguageSettingsClient::new(self.session())
1522 .read_recording_policy()
1523 .await?)
1524 }
1525
1526 async fn allow_priority_messages(&self) -> Result<bool> {
1527 Ok(LanguageSettingsClient::new(self.session())
1528 .read_allow_priority_messages()
1529 .await?)
1530 }
1531
1532 async fn patch_language_settings(&self, patch: serde_json::Value) -> Result<()> {
1533 Ok(LanguageSettingsClient::new(self.session())
1534 .patch(patch)
1535 .await?)
1536 }
1537
1538 async fn sound_settings(&self) -> Result<SoundSettings> {
1539 Ok(SoundSettingsClient::new(self.session()).read().await?)
1540 }
1541
1542 async fn chat_settings(&self) -> Result<ChatSettingsDocument> {
1543 Ok(ChatSettingsClient::new(self.session()).read().await?)
1544 }
1545
1546 async fn save_chat_setting(&self, change: ChatSettingChange) -> Result<ChatSettingsDocument> {
1547 Ok(ChatSettingsClient::new(self.session())
1548 .write(change)
1549 .await?)
1550 }
1551
1552 async fn set_chat_notifications(
1553 &self,
1554 chat_id: &str,
1555 current_settings: Option<&str>,
1556 mode: ChatNotificationMode,
1557 desktop: DesktopNotifications,
1558 ) -> Result<ChatNotificationWrite> {
1559 Ok(Conversations::new(self.session())
1560 .set_chat_notifications(chat_id, current_settings, mode, desktop)
1561 .await?)
1562 }
1563
1564 async fn save_sound_settings(
1565 &self,
1566 user_mri: &str,
1567 previous: &SoundSettings,
1568 updated: &SoundSettings,
1569 ) -> Result<()> {
1570 Ok(SoundSettingsClient::new(self.session())
1571 .write(user_mri, previous, updated)
1572 .await?)
1573 }
1574
1575 async fn search_gifs(&self, query: &str) -> Result<Vec<Gif>> {
1576 Ok(Gifs::new(self.session()).search(query).await?)
1577 }
1578
1579 async fn server_search_init(
1580 &self,
1581 identity: &SearchIdentity,
1582 search_session: &SearchSession,
1583 ) -> Result<()> {
1584 Ok(SubstrateSearch::new(self.session(), identity.clone())
1585 .init(search_session)
1586 .await?)
1587 }
1588
1589 async fn server_suggestions(
1590 &self,
1591 identity: &SearchIdentity,
1592 search_session: &SearchSession,
1593 text: &str,
1594 ) -> Result<Suggestions> {
1595 Ok(SubstrateSearch::new(self.session(), identity.clone())
1596 .suggestions(search_session, text)
1597 .await?)
1598 }
1599
1600 async fn server_query(
1601 &self,
1602 identity: &SearchIdentity,
1603 search_session: &SearchSession,
1604 request: &QueryRequest,
1605 ) -> Result<QueryResults> {
1606 Ok(SubstrateSearch::new(self.session(), identity.clone())
1607 .query(search_session, request)
1608 .await?)
1609 }
1610
1611 async fn create_scheduled(
1612 &self,
1613 inner_thread_id: &str,
1614 html: &str,
1615 send_at: DateTime<Utc>,
1616 display_name: &str,
1617 ) -> Result<ScheduledDraft> {
1618 Ok(ScheduledDrafts::new(self.session())
1619 .create(inner_thread_id, html, send_at, display_name)
1620 .await?)
1621 }
1622
1623 async fn scheduled_drafts(&self) -> Result<Vec<ScheduledDraft>> {
1624 Ok(ScheduledDrafts::new(self.session()).list().await?)
1625 }
1626
1627 async fn update_scheduled(
1628 &self,
1629 draft: &ScheduledDraft,
1630 html: &str,
1631 display_name: &str,
1632 ) -> Result<ScheduledDraft> {
1633 Ok(ScheduledDrafts::new(self.session())
1634 .update(draft, html, display_name)
1635 .await?)
1636 }
1637
1638 async fn cancel_scheduled(&self, draft_id: &str) -> Result<()> {
1639 Ok(ScheduledDrafts::new(self.session())
1640 .cancel(draft_id)
1641 .await?)
1642 }
1643}
1644
1645fn chatsvc_conversation(target: &MessageTarget) -> Option<ConversationRef> {
1646 match target {
1647 MessageTarget::Chat { .. } => CHATSVC_CHAT_WRITES.then(|| conversation_ref(target)),
1648 MessageTarget::Channel { .. } => Some(conversation_ref(target)),
1649 }
1650}
1651
1652fn conversation_ref(target: &MessageTarget) -> ConversationRef {
1653 match target {
1654 MessageTarget::Chat { chat_id, .. } => ConversationRef::chat(chat_id),
1655 MessageTarget::Channel {
1656 channel_id,
1657 root_id: None,
1658 ..
1659 } => ConversationRef::channel_root(channel_id),
1660 MessageTarget::Channel {
1661 channel_id,
1662 root_id: Some(root_id),
1663 ..
1664 } => ConversationRef::channel_reply(channel_id, root_id),
1665 }
1666}
1667
1668impl From<graph::Page<Message>> for RemotePage {
1669 fn from(page: graph::Page<Message>) -> Self {
1670 RemotePage {
1671 items: page.items,
1672 next_link: page.next_link,
1673 oldest_at: None,
1674 }
1675 }
1676}
1677
1678impl From<graph::Page<Message>> for DeltaPage {
1679 fn from(page: graph::Page<Message>) -> Self {
1680 DeltaPage {
1681 items: page.items,
1682 next_link: page.next_link,
1683 delta_link: page.delta_link,
1684 }
1685 }
1686}
1687
1688impl From<graph::Page<Chat>> for ChatsPage {
1689 fn from(page: graph::Page<Chat>) -> Self {
1690 ChatsPage {
1691 items: page.items,
1692 next_link: page.next_link,
1693 }
1694 }
1695}
1696
1697#[cfg(test)]
1698mod tests {
1699 use super::*;
1700
1701 #[test]
1702 fn channel_targets_route_to_chatsvc() {
1703 let root = MessageTarget::channel("t", "19:c@thread.tacv2", "m1", None);
1704 let reply = MessageTarget::channel("t", "19:c@thread.tacv2", "r1", Some("m1"));
1705 assert_eq!(
1706 chatsvc_conversation(&root),
1707 Some(ConversationRef::channel_root("19:c@thread.tacv2"))
1708 );
1709 assert_eq!(
1710 chatsvc_conversation(&reply),
1711 Some(ConversationRef::channel_reply("19:c@thread.tacv2", "m1"))
1712 );
1713 }
1714
1715 #[test]
1716 fn reactions_reach_chats_regardless_of_the_feature_switch() {
1717 let chat = MessageTarget::chat("19:a@thread.v2", "m1");
1718 assert_eq!(
1719 conversation_ref(&chat),
1720 ConversationRef::chat("19:a@thread.v2")
1721 );
1722 }
1723
1724 #[test]
1725 fn chats_follow_the_feature_switch() {
1726 let chat = MessageTarget::chat("19:a@thread.v2", "m1");
1727 assert_eq!(chatsvc_conversation(&chat).is_some(), CHATSVC_CHAT_WRITES);
1728 }
1729}