builder.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use crate::client_folder::FolderOperations;
  2. use crate::{
  3. client_folder::{default_folder_operations, FolderPad},
  4. errors::SyncResult,
  5. };
  6. use flowy_sync::util::make_operations_from_revisions;
  7. use folder_model::{TrashRevision, WorkspaceRevision};
  8. use revision_model::Revision;
  9. use serde::{Deserialize, Serialize};
  10. #[derive(Serialize, Deserialize)]
  11. pub(crate) struct FolderPadBuilder {
  12. workspaces: Vec<WorkspaceRevision>,
  13. trash: Vec<TrashRevision>,
  14. }
  15. impl FolderPadBuilder {
  16. pub(crate) fn new() -> Self {
  17. Self {
  18. workspaces: vec![],
  19. trash: vec![],
  20. }
  21. }
  22. #[allow(dead_code)]
  23. pub(crate) fn with_workspace(mut self, workspaces: Vec<WorkspaceRevision>) -> Self {
  24. self.workspaces = workspaces;
  25. self
  26. }
  27. #[allow(dead_code)]
  28. pub(crate) fn with_trash(mut self, trash: Vec<TrashRevision>) -> Self {
  29. self.trash = trash;
  30. self
  31. }
  32. pub(crate) fn build_with_revisions(self, revisions: Vec<Revision>) -> SyncResult<FolderPad> {
  33. let mut operations: FolderOperations = make_operations_from_revisions(revisions)?;
  34. if operations.is_empty() {
  35. operations = default_folder_operations();
  36. }
  37. FolderPad::from_operations(operations)
  38. }
  39. #[allow(dead_code)]
  40. pub(crate) fn build(self) -> SyncResult<FolderPad> {
  41. FolderPad::new(self.workspaces, self.trash)
  42. }
  43. }