BlueGit

ict rusty-teams

Files

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

remote.rs

remote.rs 47.6 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, ActivitySnapshot, AppConsumptionHorizon, ChatNotificationMode,
7 ChatNotificationWrite, ChatSettingChange, ChatSettingsClient, ChatSettingsDocument,
8 DesktopNotifications, 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 activity_feed(&self) -> Result<ActivitySnapshot> {
404 Err(Error::Unsupported("the activity feed"))
405 }
406
407 async fn mark_activity_read(&self, _message_id: &str) -> Result<()> {
408 Err(Error::Unsupported("marking activity as read"))
409 }
410
411 async fn mark_all_activity_read(&self, _now_ms: i64) -> Result<()> {
412 Err(Error::Unsupported("marking all activity as read"))
413 }
414
415 async fn app_consumption_horizon(&self) -> Result<AppConsumptionHorizon> {
416 Ok(AppConsumptionHorizon::default())
417 }
418
419 async fn mark_all_channels_read(&self, _now_ms: i64) -> Result<AppConsumptionHorizon> {
420 Err(Error::Unsupported("marking all channels as read"))
421 }
422
423 async fn chat_apps(&self, _chat_id: &str) -> Result<Vec<ChatApp>> {
424 Err(Error::Unsupported("chat apps"))
425 }
426
427 async fn invoke_card(&self, _invoke: InvokeRequest) -> Result<InvokeResponse> {
428 Err(Error::Unsupported("card actions"))
429 }
430
431 async fn message_links(
432 &self,
433 _conversation: &ConversationRef,
434 _page_size: usize,
435 ) -> Result<Vec<MessageLinks>> {
436 Err(Error::Unsupported("link previews"))
437 }
438
439 async fn message_emotions(
440 &self,
441 _conversation: &ConversationRef,
442 _newest_message_id: &str,
443 _page_size: usize,
444 ) -> Result<Vec<MessageEmotions>> {
445 Err(Error::Unsupported("chat service reactions"))
446 }
447
448 async fn set_message_links(&self, _target: &MessageTarget, _links_json: &str) -> Result<()> {
449 Err(Error::Unsupported("link previews"))
450 }
451
452 async fn link_info(&self, _url: &str) -> Result<LinkInfo> {
453 Err(Error::Unsupported("link previews"))
454 }
455
456 async fn message_languages(
457 &self,
458 _conversation: &ConversationRef,
459 _page_size: usize,
460 ) -> Result<Vec<MessageLanguage>> {
461 Err(Error::Unsupported("message languages"))
462 }
463
464 async fn translate_chat_messages(
465 &self,
466 _chat_id: &str,
467 _to_language: &str,
468 _messages: &[TranslateRequest],
469 _trigger: &TranslationTrigger,
470 ) -> Result<Vec<Translation>> {
471 Err(Error::Unsupported("translation"))
472 }
473
474 async fn translate_channel_messages(
475 &self,
476 _team_id: &str,
477 _channel_id: &str,
478 _root_id: &str,
479 _to_language: &str,
480 _messages: &[TranslateRequest],
481 _trigger: &TranslationTrigger,
482 ) -> Result<Vec<Translation>> {
483 Err(Error::Unsupported("translation"))
484 }
485
486 async fn translation_languages(&self, _locale: &str) -> Result<Vec<Language>> {
487 Err(Error::Unsupported("translation"))
488 }
489
490 async fn language_settings(&self) -> Result<LanguageSettings> {
491 Err(Error::Unsupported("translation settings"))
492 }
493
494 async fn patch_language_settings(&self, _patch: serde_json::Value) -> Result<()> {
495 Err(Error::Unsupported("translation settings"))
496 }
497
498 async fn recording_policy(&self) -> Result<RecordingPolicy> {
499 Err(Error::Unsupported("recording policy"))
500 }
501
502 async fn allow_priority_messages(&self) -> Result<bool> {
503 Err(Error::Unsupported("messaging policy"))
504 }
505
506 async fn ack_urgent_message(&self, _chat_id: &str, _message_id: &str) -> Result<()> {
507 Err(Error::Unsupported("urgent message acknowledgement"))
508 }
509
510 async fn sound_settings(&self) -> Result<SoundSettings> {
511 Err(Error::Unsupported("sound settings"))
512 }
513
514 async fn chat_settings(&self) -> Result<ChatSettingsDocument> {
515 Err(Error::Unsupported("chat settings"))
516 }
517
518 async fn save_chat_setting(&self, _change: ChatSettingChange) -> Result<ChatSettingsDocument> {
519 Err(Error::Unsupported("chat settings"))
520 }
521
522 async fn set_chat_notifications(
523 &self,
524 _chat_id: &str,
525 _current_settings: Option<&str>,
526 _mode: ChatNotificationMode,
527 _desktop: DesktopNotifications,
528 ) -> Result<ChatNotificationWrite> {
529 Err(Error::Unsupported("chat notifications"))
530 }
531
532 async fn save_sound_settings(
533 &self,
534 _user_mri: &str,
535 _previous: &SoundSettings,
536 _updated: &SoundSettings,
537 ) -> Result<()> {
538 Err(Error::Unsupported("sound settings"))
539 }
540
541 async fn search_gifs(&self, _query: &str) -> Result<Vec<Gif>> {
542 Err(Error::Unsupported("GIF search"))
543 }
544
545 async fn server_search_init(
546 &self,
547 _identity: &SearchIdentity,
548 _search_session: &SearchSession,
549 ) -> Result<()> {
550 Err(Error::Unsupported("server search"))
551 }
552
553 async fn server_suggestions(
554 &self,
555 _identity: &SearchIdentity,
556 _search_session: &SearchSession,
557 _text: &str,
558 ) -> Result<Suggestions> {
559 Err(Error::Unsupported("server search"))
560 }
561
562 async fn server_query(
563 &self,
564 _identity: &SearchIdentity,
565 _search_session: &SearchSession,
566 _request: &QueryRequest,
567 ) -> Result<QueryResults> {
568 Err(Error::Unsupported("server search"))
569 }
570
571 async fn create_scheduled(
572 &self,
573 _inner_thread_id: &str,
574 _html: &str,
575 _send_at: DateTime<Utc>,
576 _display_name: &str,
577 ) -> Result<ScheduledDraft> {
578 Err(Error::Unsupported("schedule send"))
579 }
580
581 async fn scheduled_drafts(&self) -> Result<Vec<ScheduledDraft>> {
582 Err(Error::Unsupported("schedule send"))
583 }
584
585 async fn update_scheduled(
586 &self,
587 _draft: &ScheduledDraft,
588 _html: &str,
589 _display_name: &str,
590 ) -> Result<ScheduledDraft> {
591 Err(Error::Unsupported("schedule send"))
592 }
593
594 async fn cancel_scheduled(&self, _draft_id: &str) -> Result<()> {
595 Err(Error::Unsupported("schedule send"))
596 }
597}
598
599impl Remote for Graph {
600 async fn me(&self) -> Result<User> {
601 Ok(Graph::me(self).await?)
602 }
603
604 async fn chats_page(&self, top: usize) -> Result<ChatsPage> {
605 Ok(Graph::chats_page(self, top).await?.into())
606 }
607
608 async fn chats_at(&self, next_link: &str) -> Result<ChatsPage> {
609 Ok(Graph::chats_at(self, next_link).await?.into())
610 }
611
612 async fn chat(&self, chat_id: &str) -> Result<Chat> {
613 Ok(Graph::chat(self, chat_id).await?)
614 }
615
616 async fn chat_members(&self, chat_id: &str) -> Result<Vec<Member>> {
617 Ok(Graph::chat_members(self, chat_id).await?)
618 }
619
620 async fn joined_teams(&self) -> Result<Vec<Team>> {
621 Ok(Graph::joined_teams(self).await?)
622 }
623
624 async fn channels_for_teams(&self, team_ids: &[String]) -> Result<Vec<Result<Vec<Channel>>>> {
625 let listings = Graph::channels_for_teams(self, team_ids).await?;
626 Ok(listings
627 .into_iter()
628 .map(|listing| listing.map_err(Into::into))
629 .collect())
630 }
631
632 async fn chat_messages(
633 &self,
634 chat_id: &str,
635 before: Option<DateTime<Utc>>,
636 top: usize,
637 ) -> Result<RemotePage> {
638 Ok(Graph::chat_messages(self, chat_id, before, top)
639 .await?
640 .into())
641 }
642
643 async fn chat_message(&self, chat_id: &str, message_id: &str) -> Result<Message> {
644 Ok(Graph::chat_message(self, chat_id, message_id).await?)
645 }
646
647 async fn channel_messages(
648 &self,
649 team_id: &str,
650 channel_id: &str,
651 top: usize,
652 ) -> Result<RemotePage> {
653 Ok(Graph::channel_messages(self, team_id, channel_id, top)
654 .await?
655 .into())
656 }
657
658 async fn channel_messages_at(&self, next_link: &str) -> Result<RemotePage> {
659 Ok(Graph::channel_messages_at(self, next_link).await?.into())
660 }
661
662 async fn channel_message(
663 &self,
664 team_id: &str,
665 channel_id: &str,
666 message_id: &str,
667 ) -> Result<Message> {
668 Ok(Graph::channel_message(self, team_id, channel_id, message_id).await?)
669 }
670
671 async fn channel_reply(
672 &self,
673 team_id: &str,
674 channel_id: &str,
675 message_id: &str,
676 reply_id: &str,
677 ) -> Result<Message> {
678 Ok(Graph::channel_reply(self, team_id, channel_id, message_id, reply_id).await?)
679 }
680
681 async fn channel_delta(
682 &self,
683 team_id: &str,
684 channel_id: &str,
685 modified_after: Option<DateTime<Utc>>,
686 ) -> Result<DeltaPage> {
687 Ok(
688 Graph::channel_delta(self, team_id, channel_id, modified_after)
689 .await?
690 .into(),
691 )
692 }
693
694 async fn channel_delta_at(&self, link: &str) -> Result<DeltaPage> {
695 Ok(Graph::channel_delta_at(self, link).await?.into())
696 }
697
698 async fn channel_replies(
699 &self,
700 team_id: &str,
701 channel_id: &str,
702 root_ids: &[String],
703 ) -> Result<Vec<Result<Vec<Message>>>> {
704 let listings = Graph::channel_replies(self, team_id, channel_id, root_ids).await?;
705 Ok(listings
706 .into_iter()
707 .map(|listing| listing.map_err(Into::into))
708 .collect())
709 }
710
711 async fn send_chat_message(
712 &self,
713 chat_id: &str,
714 html: &str,
715 mentions: &[OutgoingMention],
716 extras: &MessageExtras,
717 ) -> Result<Message> {
718 Ok(Graph::send_chat_message(self, chat_id, html, mentions, extras).await?)
719 }
720
721 async fn send_channel_message(
722 &self,
723 team_id: &str,
724 channel_id: &str,
725 html: &str,
726 subject: Option<&str>,
727 mentions: &[OutgoingMention],
728 extras: &MessageExtras,
729 ) -> Result<Message> {
730 Ok(
731 Graph::send_channel_message(self, team_id, channel_id, html, subject, mentions, extras)
732 .await?,
733 )
734 }
735
736 async fn reply_to_channel_message(
737 &self,
738 team_id: &str,
739 channel_id: &str,
740 message_id: &str,
741 html: &str,
742 mentions: &[OutgoingMention],
743 extras: &MessageExtras,
744 ) -> Result<Message> {
745 Ok(Graph::reply_to_channel_message(
746 self, team_id, channel_id, message_id, html, mentions, extras,
747 )
748 .await?)
749 }
750
751 async fn post_chatsvc_message(
752 &self,
753 conversation: &ConversationRef,
754 html: &str,
755 display_name: &str,
756 properties: &serde_json::Value,
757 ) -> Result<String> {
758 Ok(Messages::new(self.session())
759 .post_message(conversation, html, display_name, properties)
760 .await?)
761 }
762
763 async fn mark_chat_read(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()> {
764 Ok(Graph::mark_chat_read(self, chat_id, user_id, tenant_id).await?)
765 }
766
767 async fn mark_chat_unread(
768 &self,
769 chat_id: &str,
770 user_id: &str,
771 tenant_id: &str,
772 last_read_at: DateTime<Utc>,
773 ) -> Result<()> {
774 Ok(Graph::mark_chat_unread(self, chat_id, user_id, tenant_id, last_read_at).await?)
775 }
776
777 async fn hide_chat(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()> {
778 Ok(Graph::hide_chat(self, chat_id, user_id, tenant_id).await?)
779 }
780
781 async fn unhide_chat(&self, chat_id: &str, user_id: &str, tenant_id: &str) -> Result<()> {
782 Ok(Graph::unhide_chat(self, chat_id, user_id, tenant_id).await?)
783 }
784
785 async fn remove_chat_member(&self, chat_id: &str, user_id: &str) -> Result<()> {
786 Ok(ThreadMembers::new(self.session())
787 .remove(chat_id, user_id)
788 .await?)
789 }
790
791 async fn add_chat_members(
792 &self,
793 chat_id: &str,
794 user_ids: &[String],
795 share: HistoryShare,
796 ) -> Result<()> {
797 Ok(ThreadMembers::new(self.session())
798 .add(chat_id, user_ids, share, Utc::now().timestamp_millis())
799 .await?)
800 }
801
802 async fn chat_states(&self) -> Result<Vec<ConversationState>> {
803 Ok(Conversations::new(self.session())
804 .conversation_states()
805 .await?)
806 }
807
808 async fn clear_chat_history(&self, chat_id: &str, cleared_until_ms: i64) -> Result<()> {
809 Ok(Conversations::new(self.session())
810 .clear_history(chat_id, cleared_until_ms)
811 .await?)
812 }
813
814 async fn set_chat_topic(&self, chat_id: &str, topic: &str) -> Result<()> {
815 Ok(ThreadMembers::new(self.session())
816 .set_topic(chat_id, topic)
817 .await?)
818 }
819
820 async fn set_chat_muted(&self, chat_id: &str, muted: bool) -> Result<()> {
821 Ok(Conversations::new(self.session())
822 .set_alerts(chat_id, !muted)
823 .await?)
824 }
825
826 async fn set_read_horizon(&self, conversation_id: &str, horizon: &str) -> Result<()> {
827 Ok(Conversations::new(self.session())
828 .set_read_horizon(conversation_id, horizon)
829 .await?)
830 }
831
832 async fn set_read_bookmark(&self, conversation_id: &str, bookmark: &str) -> Result<()> {
833 Ok(Conversations::new(self.session())
834 .set_read_bookmark(conversation_id, bookmark)
835 .await?)
836 }
837
838 async fn set_chat_hidden_at(&self, chat_id: &str, hidden_at_ms: Option<i64>) -> Result<()> {
839 Ok(Conversations::new(self.session())
840 .set_hidden_at(chat_id, hidden_at_ms)
841 .await?)
842 }
843
844 async fn set_channel_notifications(
845 &self,
846 channel_id: &str,
847 notifications: store::ChannelNotifications,
848 ) -> Result<()> {
849 Ok(Conversations::new(self.session())
850 .set_channel_notifications(
851 channel_id,
852 crate::folders::chatsvc_notifications(notifications),
853 )
854 .await?)
855 }
856
857 async fn send_typing(&self, conversation: &ConversationRef, active: bool) -> Result<()> {
858 Ok(Messages::new(self.session())
859 .send_typing(conversation, active)
860 .await?)
861 }
862
863 /// Teams `ackUrgentMessage`: the emotion `acks` on the message stops the urgent repeat notifications.
864 async fn ack_urgent_message(&self, chat_id: &str, message_id: &str) -> Result<()> {
865 Ok(Messages::new(self.session())
866 .set_emotion(
867 &ConversationRef::chat(chat_id),
868 message_id,
869 URGENT_ACK_EMOTION,
870 )
871 .await?)
872 }
873
874 async fn set_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {
875 if let Some(key) = chatsvc::reaction_key(reaction_type) {
876 return Ok(Messages::new(self.session())
877 .set_emotion(&conversation_ref(target), target.message_id(), &key)
878 .await?);
879 }
880 Ok(Graph::set_reaction(self, target, reaction_type).await?)
881 }
882
883 async fn unset_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {
884 let keys = chatsvc::reaction_keys(reaction_type);
885 if !keys.is_empty() {
886 let keys: Vec<&str> = keys.iter().map(String::as_str).collect();
887 return Ok(Messages::new(self.session())
888 .unset_emotions(&conversation_ref(target), target.message_id(), &keys)
889 .await?);
890 }
891 Ok(Graph::unset_reaction(self, target, reaction_type).await?)
892 }
893
894 async fn edit_message(
895 &self,
896 target: &MessageTarget,
897 html: &str,
898 mentions: &[OutgoingMention],
899 extras: &MessageExtras,
900 ) -> Result<()> {
901 match chatsvc_conversation(target) {
902 Some(conversation) if mentions.is_empty() => {
903 let html = format!("{}{html}{}", extras.kept_html(), extras.files_html());
904 Ok(Messages::new(self.session())
905 .edit_message(&conversation, target.message_id(), &html)
906 .await?)
907 }
908 Some(_) => Err(Error::Unsupported(
909 "editing a channel message with mentions",
910 )),
911 None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
912 }
913 }
914
915 async fn soft_delete_message(&self, user_id: &str, target: &MessageTarget) -> Result<()> {
916 match chatsvc_conversation(target) {
917 Some(conversation) => Ok(Messages::new(self.session())
918 .soft_delete_message(&conversation, target.message_id())
919 .await?),
920 None => Ok(Graph::soft_delete_message(self, user_id, target).await?),
921 }
922 }
923
924 async fn undo_soft_delete_message(&self, user_id: &str, target: &MessageTarget) -> Result<()> {
925 match chatsvc_conversation(target) {
926 Some(conversation) => Ok(Messages::new(self.session())
927 .undelete_message(&conversation, target.message_id())
928 .await?),
929 None => Ok(Graph::undo_soft_delete_message(self, user_id, target).await?),
930 }
931 }
932
933 async fn create_one_on_one(&self, my_user_id: &str, user_id: &str) -> Result<Chat> {
934 Ok(Graph::create_one_on_one(self, my_user_id, user_id).await?)
935 }
936
937 async fn create_group(
938 &self,
939 my_user_id: &str,
940 user_ids: &[String],
941 topic: Option<&str>,
942 ) -> Result<Chat> {
943 Ok(Graph::create_group(self, my_user_id, user_ids, topic).await?)
944 }
945
946 async fn search_people(&self, query: &str) -> Result<Vec<User>> {
947 Ok(Graph::search_people(self, query).await?)
948 }
949
950 async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {
951 Ok(Graph::team_tags(self, team_id).await?)
952 }
953
954 async fn reply_with_quote(
955 &self,
956 chat_id: &str,
957 quoted_message_id: &str,
958 html: &str,
959 mentions: &[OutgoingMention],
960 extras: &MessageExtras,
961 ) -> Result<Message> {
962 Ok(
963 Graph::reply_with_quote(self, chat_id, quoted_message_id, html, mentions, extras)
964 .await?,
965 )
966 }
967
968 async fn channel_files_folder(&self, team_id: &str, channel_id: &str) -> Result<DriveFolder> {
969 Ok(Graph::channel_files_folder(self, team_id, channel_id).await?)
970 }
971
972 async fn channel_files_root(&self, team_id: &str, channel_id: &str) -> Result<DriveEntry> {
973 Ok(Graph::channel_files_root(self, team_id, channel_id).await?)
974 }
975
976 async fn channel_tab_web_url(
977 &self,
978 team_id: &str,
979 channel_id: &str,
980 tab_id: &str,
981 ) -> Result<Option<String>> {
982 Ok(Graph::channel_tab_web_url(self, team_id, channel_id, tab_id).await?)
983 }
984
985 async fn list_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
986 Ok(Graph::list_children(self, folder).await?)
987 }
988
989 async fn create_folder(&self, parent: &DriveFolder, name: &str) -> Result<DriveEntry> {
990 Ok(Graph::create_folder(self, parent, name).await?)
991 }
992
993 async fn upload_file(
994 &self,
995 destination: &UploadDestination,
996 file_name: &str,
997 bytes: &[u8],
998 progress: &(dyn Fn(u8) + Send + Sync),
999 ) -> Result<UploadedFile> {
1000 Ok(Graph::upload_file(self, destination, file_name, bytes, progress).await?)
1001 }
1002
1003 async fn share_file(&self, file: &UploadedFile, user_ids: &[String]) -> Result<()> {
1004 Ok(Graph::share_item(self, file, user_ids).await?)
1005 }
1006
1007 async fn delete_file(&self, file: &UploadedFile) -> Result<()> {
1008 Ok(Graph::delete_drive_item(self, &file.drive_id, &file.item_id).await?)
1009 }
1010
1011 async fn resolve_share(&self, open_url: &str) -> Result<SharedFile> {
1012 Ok(Graph::resolve_share(self, open_url).await?)
1013 }
1014
1015 async fn resolve_drive_item(&self, drive_id: &str, item_id: &str) -> Result<SharedFile> {
1016 Ok(Graph::resolve_drive_item(self, drive_id, item_id).await?)
1017 }
1018
1019 async fn download_range(
1020 &self,
1021 download_url: &str,
1022 start: u64,
1023 end: Option<u64>,
1024 ) -> Result<Vec<u8>> {
1025 Ok(Graph::download_range(self, download_url, start, end).await?)
1026 }
1027
1028 async fn hosted_content(&self, url: &str) -> Result<Photo> {
1029 if chatsvc::is_link_image_url(url) {
1030 let image = Messages::new(self.session()).link_image(url).await?;
1031 return Ok(Photo {
1032 bytes: image.bytes,
1033 content_type: image.content_type,
1034 });
1035 }
1036 Ok(Graph::download_hosted_content(self, url).await?)
1037 }
1038
1039 async fn external_image(&self, url: &str) -> Result<Photo> {
1040 Ok(Graph::download_external_image(self, url).await?)
1041 }
1042
1043 async fn user_photos(&self, user_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
1044 let photos = Graph::user_photos(self, user_ids).await?;
1045 Ok(photos
1046 .into_iter()
1047 .map(|photo| photo.map_err(Into::into))
1048 .collect())
1049 }
1050
1051 async fn presences(&self, user_ids: &[String]) -> Result<Vec<Presence>> {
1052 let found = PresenceLookup::new(self.session())
1053 .presences(user_ids)
1054 .await?;
1055 Ok(found
1056 .into_iter()
1057 .map(|presence| Presence {
1058 user_id: presence.user_id,
1059 availability: presence.availability,
1060 activity: presence.activity,
1061 })
1062 .collect())
1063 }
1064
1065 async fn person_profile(&self, user_id: &str) -> Result<PersonProfile> {
1066 crate::profile::load_profile(self, user_id).await
1067 }
1068
1069 async fn bot_profiles(&self, bot_ids: &[String]) -> Result<Vec<BotProfile>> {
1070 Ok(BotProfiles::new(self.session()).fetch(bot_ids).await?)
1071 }
1072
1073 async fn subscribe_presence(
1074 &self,
1075 endpoint_id: &str,
1076 trouter_uri: &str,
1077 user_ids: &[String],
1078 purge: bool,
1079 ) -> Result<()> {
1080 Ok(PresenceLookup::new(self.session())
1081 .subscribe(endpoint_id, trouter_uri, user_ids, purge)
1082 .await?)
1083 }
1084
1085 async fn own_status(&self, user_id: &str) -> Result<PresenceStatus> {
1086 Ok(PresenceService::new(self.session()).status(user_id).await?)
1087 }
1088
1089 async fn set_availability(&self, forced: Option<&ForcedAvailability>) -> Result<()> {
1090 Ok(PresenceService::new(self.session())
1091 .set_availability(forced)
1092 .await?)
1093 }
1094
1095 async fn set_status_note(&self, note: Option<&StatusNote>) -> Result<()> {
1096 Ok(PresenceService::new(self.session()).set_note(note).await?)
1097 }
1098
1099 async fn set_work_location(
1100 &self,
1101 location: Option<(WorkLocationKind, DateTime<Utc>)>,
1102 ) -> Result<()> {
1103 Ok(PresenceService::new(self.session())
1104 .set_work_location(location)
1105 .await?)
1106 }
1107
1108 async fn consumption_horizons(&self, conversation_id: &str) -> Result<Vec<MemberHorizon>> {
1109 Ok(Receipts::new(self.session())
1110 .consumption_horizons(conversation_id)
1111 .await?)
1112 }
1113
1114 async fn forward_messages(
1115 &self,
1116 source_conversation_id: &str,
1117 target_conversation_id: &str,
1118 message_ids: &[String],
1119 comment_html: &str,
1120 ) -> Result<ForwardResult> {
1121 Ok(Messages::new(self.session())
1122 .forward_messages(
1123 source_conversation_id,
1124 target_conversation_id,
1125 message_ids,
1126 comment_html,
1127 )
1128 .await?)
1129 }
1130
1131 async fn set_saved(
1132 &self,
1133 conversation_id: &str,
1134 root_id: &str,
1135 message_id: &str,
1136 saved: bool,
1137 ) -> Result<()> {
1138 Ok(Messages::new(self.session())
1139 .set_saved(conversation_id, root_id, message_id, saved)
1140 .await?)
1141 }
1142
1143 async fn list_saved(&self) -> Result<Vec<SavedMessage>> {
1144 Ok(Messages::new(self.session()).list_saved().await?)
1145 }
1146
1147 async fn list_call_logs(&self) -> Result<Vec<CallLogEntry>> {
1148 Ok(Messages::new(self.session()).list_call_logs().await?)
1149 }
1150
1151 async fn chat_message_window(
1152 &self,
1153 chat_id: &str,
1154 anchor_id: &str,
1155 direction: WindowDirection,
1156 page_size: usize,
1157 ) -> Result<MessageWindow> {
1158 Ok(Messages::new(self.session())
1159 .message_window(chat_id, anchor_id, direction, page_size)
1160 .await?)
1161 }
1162
1163 async fn chat_messages_by_id(
1164 &self,
1165 chat_id: &str,
1166 message_ids: &[String],
1167 ) -> Result<Vec<Result<Message>>> {
1168 let messages = Graph::chat_messages_by_id(self, chat_id, message_ids).await?;
1169 Ok(messages
1170 .into_iter()
1171 .map(|message| message.map_err(Into::into))
1172 .collect())
1173 }
1174
1175 async fn chat_pins(&self, chat_id: &str) -> Result<Vec<PinnedMessage>> {
1176 Ok(Pins::new(self.session()).chat_pins(chat_id).await?)
1177 }
1178
1179 async fn pin_message(&self, chat_id: &str, message_id: &str) -> Result<()> {
1180 Ok(Pins::new(self.session())
1181 .pin_message(chat_id, message_id)
1182 .await?)
1183 }
1184
1185 async fn unpin_message(
1186 &self,
1187 chat_id: &str,
1188 message_id: &str,
1189 parent_id: Option<&str>,
1190 ) -> Result<()> {
1191 Ok(Pins::new(self.session())
1192 .unpin_message(chat_id, message_id, parent_id)
1193 .await?)
1194 }
1195
1196 async fn channel_pinned_posts(
1197 &self,
1198 team_thread_id: &str,
1199 channel_id: &str,
1200 ) -> Result<Vec<PinnedMessage>> {
1201 Ok(Pins::with_skype_token(self.session())
1202 .channel_pinned_posts(team_thread_id, channel_id)
1203 .await?)
1204 }
1205
1206 async fn set_post_pinned(
1207 &self,
1208 team_thread_id: &str,
1209 channel_id: &str,
1210 post_id: &str,
1211 pinned: bool,
1212 ) -> Result<()> {
1213 Ok(Pins::with_skype_token(self.session())
1214 .set_post_pinned(team_thread_id, channel_id, post_id, pinned)
1215 .await?)
1216 }
1217
1218 async fn activity_feed(&self) -> Result<ActivitySnapshot> {
1219 Ok(ActivityFeed::new(self.session()).snapshot().await?)
1220 }
1221
1222 async fn mark_activity_read(&self, message_id: &str) -> Result<()> {
1223 Ok(ActivityFeed::new(self.session()).mark_read(message_id).await?)
1224 }
1225
1226 async fn mark_all_activity_read(&self, now_ms: i64) -> Result<()> {
1227 Ok(ActivityFeed::new(self.session()).mark_all_read(now_ms).await?)
1228 }
1229
1230 async fn app_consumption_horizon(&self) -> Result<AppConsumptionHorizon> {
1231 let properties = UserSettings::new(self.session()).properties().await?;
1232 Ok(parse_app_consumption_horizon(&properties))
1233 }
1234
1235 async fn mark_all_channels_read(&self, now_ms: i64) -> Result<AppConsumptionHorizon> {
1236 Ok(UserSettings::new(self.session())
1237 .mark_all_channels_read(now_ms)
1238 .await?)
1239 }
1240
1241 async fn chat_apps(&self, chat_id: &str) -> Result<Vec<ChatApp>> {
1242 Ok(CardActions::new(self.session()).chat_apps(chat_id).await?)
1243 }
1244
1245 async fn invoke_card(&self, invoke: InvokeRequest) -> Result<InvokeResponse> {
1246 Ok(CardActions::new(self.session()).invoke(invoke).await?)
1247 }
1248
1249 async fn message_links(
1250 &self,
1251 conversation: &ConversationRef,
1252 page_size: usize,
1253 ) -> Result<Vec<MessageLinks>> {
1254 Ok(Messages::new(self.session())
1255 .list_message_links(conversation, page_size)
1256 .await?)
1257 }
1258
1259 async fn message_emotions(
1260 &self,
1261 conversation: &ConversationRef,
1262 newest_message_id: &str,
1263 page_size: usize,
1264 ) -> Result<Vec<MessageEmotions>> {
1265 Ok(Messages::new(self.session())
1266 .message_emotions(
1267 &conversation.conversation_id(),
1268 newest_message_id,
1269 page_size,
1270 )
1271 .await?)
1272 }
1273
1274 async fn set_message_links(&self, target: &MessageTarget, links_json: &str) -> Result<()> {
1275 Ok(Messages::new(self.session())
1276 .set_links(&conversation_ref(target), target.message_id(), links_json)
1277 .await?)
1278 }
1279
1280 async fn link_info(&self, url: &str) -> Result<LinkInfo> {
1281 Ok(Messages::new(self.session()).link_info(url).await?)
1282 }
1283
1284 async fn message_languages(
1285 &self,
1286 conversation: &ConversationRef,
1287 page_size: usize,
1288 ) -> Result<Vec<MessageLanguage>> {
1289 Ok(Messages::new(self.session())
1290 .list_language_stamps(conversation, page_size)
1291 .await?)
1292 }
1293
1294 async fn translate_chat_messages(
1295 &self,
1296 chat_id: &str,
1297 to_language: &str,
1298 messages: &[TranslateRequest],
1299 trigger: &TranslationTrigger,
1300 ) -> Result<Vec<Translation>> {
1301 Ok(Translator::new(self.session())
1302 .translate_chat(chat_id, to_language, messages, trigger)
1303 .await?)
1304 }
1305
1306 async fn translate_channel_messages(
1307 &self,
1308 team_id: &str,
1309 channel_id: &str,
1310 root_id: &str,
1311 to_language: &str,
1312 messages: &[TranslateRequest],
1313 trigger: &TranslationTrigger,
1314 ) -> Result<Vec<Translation>> {
1315 Ok(Translator::new(self.session())
1316 .translate_channel(team_id, channel_id, root_id, to_language, messages, trigger)
1317 .await?)
1318 }
1319
1320 async fn translation_languages(&self, locale: &str) -> Result<Vec<Language>> {
1321 Ok(Translator::new(self.session()).languages(locale).await?)
1322 }
1323
1324 async fn language_settings(&self) -> Result<LanguageSettings> {
1325 Ok(LanguageSettingsClient::new(self.session()).read().await?)
1326 }
1327
1328 async fn recording_policy(&self) -> Result<RecordingPolicy> {
1329 Ok(LanguageSettingsClient::new(self.session())
1330 .read_recording_policy()
1331 .await?)
1332 }
1333
1334 async fn allow_priority_messages(&self) -> Result<bool> {
1335 Ok(LanguageSettingsClient::new(self.session())
1336 .read_allow_priority_messages()
1337 .await?)
1338 }
1339
1340 async fn patch_language_settings(&self, patch: serde_json::Value) -> Result<()> {
1341 Ok(LanguageSettingsClient::new(self.session())
1342 .patch(patch)
1343 .await?)
1344 }
1345
1346 async fn sound_settings(&self) -> Result<SoundSettings> {
1347 Ok(SoundSettingsClient::new(self.session()).read().await?)
1348 }
1349
1350 async fn chat_settings(&self) -> Result<ChatSettingsDocument> {
1351 Ok(ChatSettingsClient::new(self.session()).read().await?)
1352 }
1353
1354 async fn save_chat_setting(&self, change: ChatSettingChange) -> Result<ChatSettingsDocument> {
1355 Ok(ChatSettingsClient::new(self.session()).write(change).await?)
1356 }
1357
1358 async fn set_chat_notifications(
1359 &self,
1360 chat_id: &str,
1361 current_settings: Option<&str>,
1362 mode: ChatNotificationMode,
1363 desktop: DesktopNotifications,
1364 ) -> Result<ChatNotificationWrite> {
1365 Ok(Conversations::new(self.session())
1366 .set_chat_notifications(chat_id, current_settings, mode, desktop)
1367 .await?)
1368 }
1369
1370 async fn save_sound_settings(
1371 &self,
1372 user_mri: &str,
1373 previous: &SoundSettings,
1374 updated: &SoundSettings,
1375 ) -> Result<()> {
1376 Ok(SoundSettingsClient::new(self.session())
1377 .write(user_mri, previous, updated)
1378 .await?)
1379 }
1380
1381 async fn search_gifs(&self, query: &str) -> Result<Vec<Gif>> {
1382 Ok(Gifs::new(self.session()).search(query).await?)
1383 }
1384
1385 async fn server_search_init(
1386 &self,
1387 identity: &SearchIdentity,
1388 search_session: &SearchSession,
1389 ) -> Result<()> {
1390 Ok(SubstrateSearch::new(self.session(), identity.clone())
1391 .init(search_session)
1392 .await?)
1393 }
1394
1395 async fn server_suggestions(
1396 &self,
1397 identity: &SearchIdentity,
1398 search_session: &SearchSession,
1399 text: &str,
1400 ) -> Result<Suggestions> {
1401 Ok(SubstrateSearch::new(self.session(), identity.clone())
1402 .suggestions(search_session, text)
1403 .await?)
1404 }
1405
1406 async fn server_query(
1407 &self,
1408 identity: &SearchIdentity,
1409 search_session: &SearchSession,
1410 request: &QueryRequest,
1411 ) -> Result<QueryResults> {
1412 Ok(SubstrateSearch::new(self.session(), identity.clone())
1413 .query(search_session, request)
1414 .await?)
1415 }
1416
1417 async fn create_scheduled(
1418 &self,
1419 inner_thread_id: &str,
1420 html: &str,
1421 send_at: DateTime<Utc>,
1422 display_name: &str,
1423 ) -> Result<ScheduledDraft> {
1424 Ok(ScheduledDrafts::new(self.session())
1425 .create(inner_thread_id, html, send_at, display_name)
1426 .await?)
1427 }
1428
1429 async fn scheduled_drafts(&self) -> Result<Vec<ScheduledDraft>> {
1430 Ok(ScheduledDrafts::new(self.session()).list().await?)
1431 }
1432
1433 async fn update_scheduled(
1434 &self,
1435 draft: &ScheduledDraft,
1436 html: &str,
1437 display_name: &str,
1438 ) -> Result<ScheduledDraft> {
1439 Ok(ScheduledDrafts::new(self.session())
1440 .update(draft, html, display_name)
1441 .await?)
1442 }
1443
1444 async fn cancel_scheduled(&self, draft_id: &str) -> Result<()> {
1445 Ok(ScheduledDrafts::new(self.session())
1446 .cancel(draft_id)
1447 .await?)
1448 }
1449}
1450
1451fn chatsvc_conversation(target: &MessageTarget) -> Option<ConversationRef> {
1452 match target {
1453 MessageTarget::Chat { .. } => CHATSVC_CHAT_WRITES.then(|| conversation_ref(target)),
1454 MessageTarget::Channel { .. } => Some(conversation_ref(target)),
1455 }
1456}
1457
1458fn conversation_ref(target: &MessageTarget) -> ConversationRef {
1459 match target {
1460 MessageTarget::Chat { chat_id, .. } => ConversationRef::chat(chat_id),
1461 MessageTarget::Channel {
1462 channel_id,
1463 root_id: None,
1464 ..
1465 } => ConversationRef::channel_root(channel_id),
1466 MessageTarget::Channel {
1467 channel_id,
1468 root_id: Some(root_id),
1469 ..
1470 } => ConversationRef::channel_reply(channel_id, root_id),
1471 }
1472}
1473
1474impl From<graph::Page<Message>> for RemotePage {
1475 fn from(page: graph::Page<Message>) -> Self {
1476 RemotePage {
1477 items: page.items,
1478 next_link: page.next_link,
1479 }
1480 }
1481}
1482
1483impl From<graph::Page<Message>> for DeltaPage {
1484 fn from(page: graph::Page<Message>) -> Self {
1485 DeltaPage {
1486 items: page.items,
1487 next_link: page.next_link,
1488 delta_link: page.delta_link,
1489 }
1490 }
1491}
1492
1493impl From<graph::Page<Chat>> for ChatsPage {
1494 fn from(page: graph::Page<Chat>) -> Self {
1495 ChatsPage {
1496 items: page.items,
1497 next_link: page.next_link,
1498 }
1499 }
1500}
1501
1502#[cfg(test)]
1503mod tests {
1504 use super::*;
1505
1506 #[test]
1507 fn channel_targets_route_to_chatsvc() {
1508 let root = MessageTarget::channel("t", "19:c@thread.tacv2", "m1", None);
1509 let reply = MessageTarget::channel("t", "19:c@thread.tacv2", "r1", Some("m1"));
1510 assert_eq!(
1511 chatsvc_conversation(&root),
1512 Some(ConversationRef::channel_root("19:c@thread.tacv2"))
1513 );
1514 assert_eq!(
1515 chatsvc_conversation(&reply),
1516 Some(ConversationRef::channel_reply("19:c@thread.tacv2", "m1"))
1517 );
1518 }
1519
1520 #[test]
1521 fn reactions_reach_chats_regardless_of_the_feature_switch() {
1522 let chat = MessageTarget::chat("19:a@thread.v2", "m1");
1523 assert_eq!(
1524 conversation_ref(&chat),
1525 ConversationRef::chat("19:a@thread.v2")
1526 );
1527 }
1528
1529 #[test]
1530 fn chats_follow_the_feature_switch() {
1531 let chat = MessageTarget::chat("19:a@thread.v2", "m1");
1532 assert_eq!(chatsvc_conversation(&chat).is_some(), CHATSVC_CHAT_WRITES);
1533 }
1534}