BlueGit

ict rusty-teams

Files

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

remote.rs

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