feat: add support for renaming and updating the icon for workspaces (#4806)

This commit is contained in:
Zack
2024-03-04 16:05:16 +08:00
committed by GitHub
parent f8962edfd7
commit 2af93a9bcb
14 changed files with 283 additions and 37 deletions

View File

@ -225,6 +225,9 @@ pub struct UserWorkspacePB {
#[pb(index = 2)]
pub name: String,
#[pb(index = 3)]
pub created_at_timestamp: i64,
}
impl From<UserWorkspace> for UserWorkspacePB {
@ -232,6 +235,7 @@ impl From<UserWorkspace> for UserWorkspacePB {
Self {
workspace_id: value.id,
name: value.name,
created_at_timestamp: value.created_at.timestamp(),
}
}
}

View File

@ -116,3 +116,24 @@ pub struct CreateWorkspacePB {
#[validate(custom = "required_not_empty_str")]
pub name: String,
}
#[derive(ProtoBuf, Default, Clone, Validate)]
pub struct RenameWorkspacePB {
#[pb(index = 1)]
#[validate(custom = "required_not_empty_str")]
pub workspace_id: String,
#[pb(index = 2)]
#[validate(custom = "required_not_empty_str")]
pub new_name: String,
}
#[derive(ProtoBuf, Default, Clone, Validate)]
pub struct ChangeWorkspaceIconPB {
#[pb(index = 1)]
#[validate(custom = "required_not_empty_str")]
pub workspace_id: String,
#[pb(index = 2)]
pub new_icon: String,
}

View File

@ -683,3 +683,29 @@ pub async fn delete_workspace_handler(
manager.delete_workspace(&workspace_id).await?;
Ok(())
}
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn rename_workspace_handler(
rename_workspace_param: AFPluginData<RenameWorkspacePB>,
manager: AFPluginState<Weak<UserManager>>,
) -> Result<(), FlowyError> {
let params = rename_workspace_param.try_into_inner()?;
let manager = upgrade_manager(manager)?;
manager
.patch_workspace(&params.workspace_id, Some(&params.new_name), None)
.await?;
Ok(())
}
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn change_workspace_icon_handler(
change_workspace_icon_param: AFPluginData<ChangeWorkspaceIconPB>,
manager: AFPluginState<Weak<UserManager>>,
) -> Result<(), FlowyError> {
let params = change_workspace_icon_param.try_into_inner()?;
let manager = upgrade_manager(manager)?;
manager
.patch_workspace(&params.workspace_id, None, Some(&params.new_icon))
.await?;
Ok(())
}

View File

@ -62,6 +62,8 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
.event(UserEvent::GetAllWorkspace, get_all_workspace_handler)
.event(UserEvent::CreateWorkspace, create_workspace_handler)
.event(UserEvent::DeleteWorkspace, delete_workspace_handler)
.event(UserEvent::RenameWorkspace, rename_workspace_handler)
.event(UserEvent::ChangeWorkspaceIcon, change_workspace_icon_handler)
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
@ -200,6 +202,12 @@ pub enum UserEvent {
#[event(input = "UserWorkspaceIdPB")]
DeleteWorkspace = 43,
#[event(input = "RenameWorkspacePB")]
RenameWorkspace = 44,
#[event(input = "ChangeWorkspaceIconPB")]
ChangeWorkspaceIcon = 45,
}
pub trait UserStatusCallback: Send + Sync + 'static {

View File

@ -167,6 +167,21 @@ impl UserManager {
Ok(new_workspace)
}
pub async fn patch_workspace(
&self,
workspace_id: &str,
new_workspace_name: Option<&str>,
new_workspace_icon: Option<&str>,
) -> FlowyResult<()> {
self
.cloud_services
.get_user_service()?
.patch_workspace(workspace_id, new_workspace_name, new_workspace_icon)
.await?;
Ok(())
}
pub async fn delete_workspace(&self, workspace_id: &str) -> FlowyResult<()> {
self
.cloud_services