BlueGit

ict rusty-teams

Files

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

remote.rs

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