BlueGit

ict rusty-teams

Files

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

library.rs

library.rs 2.3 KiB Download Raw
1use graph::{DriveEntry, DriveFolder, UploadDestination, UploadedFile};
2
3use crate::engine::{Conversation, SyncEngine};
4use crate::error::{Error, Result};
5use crate::remote::Remote;
6
7impl<R: Remote> SyncEngine<R> {
8 pub async fn channel_library_root(&self, channel_id: &str) -> Result<DriveEntry> {
9 let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
10 return Err(Error::Unsupported("a library for a chat"));
11 };
12 self.remote.channel_files_root(&team_id, channel_id).await
13 }
14
15 pub async fn channel_tab_web_url(
16 &self,
17 channel_id: &str,
18 tab_id: &str,
19 ) -> Result<Option<String>> {
20 let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
21 return Err(Error::Unsupported("a tab link for a chat"));
22 };
23 self.remote
24 .channel_tab_web_url(&team_id, channel_id, tab_id)
25 .await
26 }
27
28 pub async fn channel_member_count(&self, channel_id: &str) -> Result<usize> {
29 let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
30 return Err(Error::Unsupported("a member count for a chat"));
31 };
32 self.remote.channel_member_count(&team_id, channel_id).await
33 }
34
35 pub async fn team_members(&self, team_id: &str) -> Result<Vec<graph::Member>> {
36 let general_channel_id = self
37 .store
38 .team_thread_id(team_id)?
39 .ok_or(Error::Unsupported("a team without its General channel"))?;
40 self.remote.channel_members(team_id, &general_channel_id).await
41 }
42
43 pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
44 self.remote.list_children(folder).await
45 }
46
47 pub async fn create_library_folder(
48 &self,
49 parent: &DriveFolder,
50 name: &str,
51 ) -> Result<DriveEntry> {
52 self.remote.create_folder(parent, name).await
53 }
54
55 pub async fn upload_to_library(
56 &self,
57 folder: &DriveFolder,
58 file_name: &str,
59 bytes: &[u8],
60 progress: impl Fn(u8) + Send + Sync,
61 ) -> Result<UploadedFile> {
62 self.remote
63 .upload_file(
64 &UploadDestination::Folder(folder.clone()),
65 file_name,
66 bytes,
67 &progress,
68 )
69 .await
70 }
71}