BlueGit

ict rusty-teams

Files

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

remote.rs

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