BlueGit

ict rusty-teams

Files

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

remote.rs

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