fix: update workspace setting

This commit is contained in:
appflowy
2022-05-05 10:45:53 +08:00
parent 6c2c3b0666
commit 448c134704
16 changed files with 197 additions and 121 deletions

View File

@ -10,6 +10,7 @@ pub(crate) enum FolderNotification {
WorkspaceUpdated = 12,
WorkspaceListUpdated = 13,
WorkspaceAppsChanged = 14,
WorkspaceSetting = 15,
AppUpdated = 21,
AppViewsChanged = 24,
ViewUpdated = 31,

View File

@ -31,6 +31,7 @@ pub enum FolderNotification {
WorkspaceUpdated = 12,
WorkspaceListUpdated = 13,
WorkspaceAppsChanged = 14,
WorkspaceSetting = 15,
AppUpdated = 21,
AppViewsChanged = 24,
ViewUpdated = 31,
@ -53,6 +54,7 @@ impl ::protobuf::ProtobufEnum for FolderNotification {
12 => ::std::option::Option::Some(FolderNotification::WorkspaceUpdated),
13 => ::std::option::Option::Some(FolderNotification::WorkspaceListUpdated),
14 => ::std::option::Option::Some(FolderNotification::WorkspaceAppsChanged),
15 => ::std::option::Option::Some(FolderNotification::WorkspaceSetting),
21 => ::std::option::Option::Some(FolderNotification::AppUpdated),
24 => ::std::option::Option::Some(FolderNotification::AppViewsChanged),
31 => ::std::option::Option::Some(FolderNotification::ViewUpdated),
@ -72,6 +74,7 @@ impl ::protobuf::ProtobufEnum for FolderNotification {
FolderNotification::WorkspaceUpdated,
FolderNotification::WorkspaceListUpdated,
FolderNotification::WorkspaceAppsChanged,
FolderNotification::WorkspaceSetting,
FolderNotification::AppUpdated,
FolderNotification::AppViewsChanged,
FolderNotification::ViewUpdated,
@ -107,14 +110,15 @@ impl ::protobuf::reflect::ProtobufValue for FolderNotification {
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x17dart_notification.proto*\x9f\x02\n\x12FolderNotification\x12\x0b\n\
\n\x17dart_notification.proto*\xb5\x02\n\x12FolderNotification\x12\x0b\n\
\x07Unknown\x10\0\x12\x17\n\x13UserCreateWorkspace\x10\n\x12\x17\n\x13Us\
erDeleteWorkspace\x10\x0b\x12\x14\n\x10WorkspaceUpdated\x10\x0c\x12\x18\
\n\x14WorkspaceListUpdated\x10\r\x12\x18\n\x14WorkspaceAppsChanged\x10\
\x0e\x12\x0e\n\nAppUpdated\x10\x15\x12\x13\n\x0fAppViewsChanged\x10\x18\
\x12\x0f\n\x0bViewUpdated\x10\x1f\x12\x0f\n\x0bViewDeleted\x10\x20\x12\
\x10\n\x0cViewRestored\x10!\x12\x14\n\x10UserUnauthorized\x10d\x12\x11\n\
\x0cTrashUpdated\x10\xe8\x07b\x06proto3\
\x0e\x12\x14\n\x10WorkspaceSetting\x10\x0f\x12\x0e\n\nAppUpdated\x10\x15\
\x12\x13\n\x0fAppViewsChanged\x10\x18\x12\x0f\n\x0bViewUpdated\x10\x1f\
\x12\x0f\n\x0bViewDeleted\x10\x20\x12\x10\n\x0cViewRestored\x10!\x12\x14\
\n\x10UserUnauthorized\x10d\x12\x11\n\x0cTrashUpdated\x10\xe8\x07b\x06pr\
oto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -7,6 +7,7 @@ enum FolderNotification {
WorkspaceUpdated = 12;
WorkspaceListUpdated = 13;
WorkspaceAppsChanged = 14;
WorkspaceSetting = 15;
AppUpdated = 21;
AppViewsChanged = 24;
ViewUpdated = 31;

View File

@ -1,4 +1,5 @@
use crate::services::AppController;
use crate::manager::FolderManager;
use crate::services::{notify_workspace_setting_did_change, AppController};
use crate::{
entities::{
trash::Trash,
@ -69,10 +70,12 @@ pub(crate) async fn delete_view_handler(
pub(crate) async fn set_latest_view_handler(
data: Data<ViewId>,
folder: AppData<Arc<FolderManager>>,
controller: AppData<Arc<ViewController>>,
) -> Result<(), FlowyError> {
let view_id: ViewId = data.into_inner();
let _ = controller.set_latest_view(&view_id.value)?;
let _ = notify_workspace_setting_did_change(&folder, &view_id).await?;
Ok(())
}

View File

@ -1,3 +1,4 @@
use crate::manager::FolderManager;
use crate::{
dart_notification::*,
errors::*,
@ -190,6 +191,44 @@ impl WorkspaceController {
}
}
pub async fn notify_workspace_setting_did_change(
folder_manager: &Arc<FolderManager>,
view_id: &str,
) -> FlowyResult<()> {
let user_id = folder_manager.user.user_id()?;
let token = folder_manager.user.token()?;
let workspace_id = get_current_workspace()?;
let workspace_setting = folder_manager
.persistence
.begin_transaction(|transaction| {
let workspace = folder_manager.workspace_controller.read_local_workspace(
workspace_id.clone(),
&user_id,
&transaction,
)?;
let setting = match transaction.read_view(view_id) {
Ok(latest_view) => CurrentWorkspaceSetting {
workspace,
latest_view: Some(latest_view),
},
Err(_) => CurrentWorkspaceSetting {
workspace,
latest_view: None,
},
};
Ok(setting)
})
.await?;
send_dart_notification(&token, FolderNotification::WorkspaceSetting)
.payload(workspace_setting)
.send();
Ok(())
}
const CURRENT_WORKSPACE_ID: &str = "current_workspace_id";
pub fn set_current_workspace(workspace_id: &str) {