mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: paser workspce pb (#2005)
This commit is contained in:
parent
caffb9fdcf
commit
888c7977eb
@ -83,11 +83,10 @@ class UserWorkspaceListener {
|
|||||||
PublishNotifier();
|
PublishNotifier();
|
||||||
|
|
||||||
FolderNotificationListener? _listener;
|
FolderNotificationListener? _listener;
|
||||||
final UserProfilePB _userProfile;
|
|
||||||
|
|
||||||
UserWorkspaceListener({
|
UserWorkspaceListener({
|
||||||
required UserProfilePB userProfile,
|
required UserProfilePB userProfile,
|
||||||
}) : _userProfile = userProfile;
|
});
|
||||||
|
|
||||||
void start({
|
void start({
|
||||||
void Function(AuthNotifyValue)? onAuthChanged,
|
void Function(AuthNotifyValue)? onAuthChanged,
|
||||||
@ -106,14 +105,18 @@ class UserWorkspaceListener {
|
|||||||
_settingChangedNotifier?.addPublishListener(onSettingUpdated);
|
_settingChangedNotifier?.addPublishListener(onSettingUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The "current-workspace" is predefined in the backend. Do not try to
|
||||||
|
// modify it
|
||||||
_listener = FolderNotificationListener(
|
_listener = FolderNotificationListener(
|
||||||
objectId: _userProfile.token,
|
objectId: "current-workspace",
|
||||||
handler: _handleObservableType,
|
handler: _handleObservableType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleObservableType(
|
void _handleObservableType(
|
||||||
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
FolderNotification ty,
|
||||||
|
Either<Uint8List, FlowyError> result,
|
||||||
|
) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case FolderNotification.DidCreateWorkspace:
|
case FolderNotification.DidCreateWorkspace:
|
||||||
case FolderNotification.DidDeleteWorkspace:
|
case FolderNotification.DidDeleteWorkspace:
|
||||||
|
@ -11,6 +11,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use flowy_sqlite::kv::KV;
|
use flowy_sqlite::kv::KV;
|
||||||
use folder_model::{AppRevision, WorkspaceRevision};
|
use folder_model::{AppRevision, WorkspaceRevision};
|
||||||
|
use lib_dispatch::prelude::ToBytes;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct WorkspaceController {
|
pub struct WorkspaceController {
|
||||||
@ -41,7 +42,6 @@ impl WorkspaceController {
|
|||||||
) -> Result<WorkspaceRevision, FlowyError> {
|
) -> Result<WorkspaceRevision, FlowyError> {
|
||||||
let workspace = self.create_workspace_on_server(params.clone()).await?;
|
let workspace = self.create_workspace_on_server(params.clone()).await?;
|
||||||
let user_id = self.user.user_id()?;
|
let user_id = self.user.user_id()?;
|
||||||
let token = self.user.token()?;
|
|
||||||
let workspaces = self
|
let workspaces = self
|
||||||
.persistence
|
.persistence
|
||||||
.begin_transaction(|transaction| {
|
.begin_transaction(|transaction| {
|
||||||
@ -53,9 +53,7 @@ impl WorkspaceController {
|
|||||||
.map(|workspace_rev| workspace_rev.into())
|
.map(|workspace_rev| workspace_rev.into())
|
||||||
.collect();
|
.collect();
|
||||||
let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
|
let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
|
||||||
send_notification(&token, FolderNotification::DidCreateWorkspace)
|
send_workspace_notification(FolderNotification::DidCreateWorkspace, repeated_workspace);
|
||||||
.payload(repeated_workspace)
|
|
||||||
.send();
|
|
||||||
set_current_workspace(&user_id, &workspace.id);
|
set_current_workspace(&user_id, &workspace.id);
|
||||||
Ok(workspace)
|
Ok(workspace)
|
||||||
}
|
}
|
||||||
@ -76,9 +74,7 @@ impl WorkspaceController {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
send_notification(&workspace_id, FolderNotification::DidUpdateWorkspace)
|
send_workspace_notification(FolderNotification::DidUpdateWorkspace, workspace);
|
||||||
.payload(workspace)
|
|
||||||
.send();
|
|
||||||
self.update_workspace_on_server(params)?;
|
self.update_workspace_on_server(params)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -87,7 +83,6 @@ impl WorkspaceController {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) async fn delete_workspace(&self, workspace_id: &str) -> Result<(), FlowyError> {
|
pub(crate) async fn delete_workspace(&self, workspace_id: &str) -> Result<(), FlowyError> {
|
||||||
let user_id = self.user.user_id()?;
|
let user_id = self.user.user_id()?;
|
||||||
let token = self.user.token()?;
|
|
||||||
let repeated_workspace = self
|
let repeated_workspace = self
|
||||||
.persistence
|
.persistence
|
||||||
.begin_transaction(|transaction| {
|
.begin_transaction(|transaction| {
|
||||||
@ -95,9 +90,8 @@ impl WorkspaceController {
|
|||||||
self.read_workspaces(None, &user_id, &transaction)
|
self.read_workspaces(None, &user_id, &transaction)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
send_notification(&token, FolderNotification::DidDeleteWorkspace)
|
|
||||||
.payload(repeated_workspace)
|
send_workspace_notification(FolderNotification::DidDeleteWorkspace, repeated_workspace);
|
||||||
.send();
|
|
||||||
self.delete_workspace_on_server(workspace_id)?;
|
self.delete_workspace_on_server(workspace_id)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -224,7 +218,6 @@ pub async fn notify_workspace_setting_did_change(
|
|||||||
view_id: &str,
|
view_id: &str,
|
||||||
) -> FlowyResult<()> {
|
) -> FlowyResult<()> {
|
||||||
let user_id = folder_manager.user.user_id()?;
|
let user_id = folder_manager.user.user_id()?;
|
||||||
let token = folder_manager.user.token()?;
|
|
||||||
let workspace_id = get_current_workspace(&user_id)?;
|
let workspace_id = get_current_workspace(&user_id)?;
|
||||||
|
|
||||||
let workspace_setting = folder_manager
|
let workspace_setting = folder_manager
|
||||||
@ -250,13 +243,22 @@ pub async fn notify_workspace_setting_did_change(
|
|||||||
Ok(setting)
|
Ok(setting)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
send_workspace_notification(
|
||||||
send_notification(&token, FolderNotification::DidUpdateWorkspaceSetting)
|
FolderNotification::DidUpdateWorkspaceSetting,
|
||||||
.payload(workspace_setting)
|
workspace_setting,
|
||||||
.send();
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The [CURRENT_WORKSPACE] represents as the current workspace that opened by the
|
||||||
|
/// user. Only one workspace can be opened at a time.
|
||||||
|
const CURRENT_WORKSPACE: &str = "current-workspace";
|
||||||
|
fn send_workspace_notification<T: ToBytes>(ty: FolderNotification, payload: T) {
|
||||||
|
send_notification(CURRENT_WORKSPACE, ty)
|
||||||
|
.payload(payload)
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
|
||||||
const CURRENT_WORKSPACE_ID: &str = "current_workspace_id";
|
const CURRENT_WORKSPACE_ID: &str = "current_workspace_id";
|
||||||
|
|
||||||
pub fn set_current_workspace(_user_id: &str, workspace_id: &str) {
|
pub fn set_current_workspace(_user_id: &str, workspace_id: &str) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user