BlueGit

ict rusty-teams

Files

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

remote.rs

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