| 1 | use graph::{DriveEntry, DriveFolder, UploadDestination, UploadedFile}; |
| 2 | |
| 3 | use crate::engine::{Conversation, SyncEngine}; |
| 4 | use crate::error::{Error, Result}; |
| 5 | use crate::remote::Remote; |
| 6 | |
| 7 | impl<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 |
| 41 | .channel_members(team_id, &general_channel_id) |
| 42 | .await |
| 43 | } |
| 44 | |
| 45 | pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> { |
| 46 | self.remote.list_children(folder).await |
| 47 | } |
| 48 | |
| 49 | pub async fn create_library_folder( |
| 50 | &self, |
| 51 | parent: &DriveFolder, |
| 52 | name: &str, |
| 53 | ) -> Result<DriveEntry> { |
| 54 | self.remote.create_folder(parent, name).await |
| 55 | } |
| 56 | |
| 57 | pub async fn upload_to_library( |
| 58 | &self, |
| 59 | folder: &DriveFolder, |
| 60 | file_name: &str, |
| 61 | bytes: &[u8], |
| 62 | progress: impl Fn(u8) + Send + Sync, |
| 63 | ) -> Result<UploadedFile> { |
| 64 | self.remote |
| 65 | .upload_file( |
| 66 | &UploadDestination::Folder(folder.clone()), |
| 67 | file_name, |
| 68 | bytes, |
| 69 | &progress, |
| 70 | ) |
| 71 | .await |
| 72 | } |
| 73 | } |