BlueGit

ict rusty-teams

Files

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

remote.rs

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