mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-12-27 23:24:38 +00:00
chore: refresh user profile when open workspace
This commit is contained in:
parent
d893b89e4d
commit
3bd34226c3
@ -46,7 +46,7 @@ class UserListener {
|
||||
///
|
||||
DidUpdateUserWorkspaceCallback? onUserWorkspaceUpdated;
|
||||
DidUpdateUserWorkspaceSetting? onUserWorkspaceSettingUpdated;
|
||||
|
||||
DidUpdateUserWorkspaceCallback? onUserWorkspaceOpened;
|
||||
void start({
|
||||
void Function(UserProfileNotifyValue)? onProfileUpdated,
|
||||
DidUpdateUserWorkspacesCallback? onUserWorkspaceListUpdated,
|
||||
@ -60,7 +60,6 @@ class UserListener {
|
||||
this.onUserWorkspaceListUpdated = onUserWorkspaceListUpdated;
|
||||
this.onUserWorkspaceUpdated = onUserWorkspaceUpdated;
|
||||
this.onUserWorkspaceSettingUpdated = onUserWorkspaceSettingUpdated;
|
||||
|
||||
_userParser = UserNotificationParser(
|
||||
id: _userProfile.id.toString(),
|
||||
callback: _userNotificationCallback,
|
||||
@ -107,6 +106,13 @@ class UserListener {
|
||||
?.call(WorkspaceSettingsPB.fromBuffer(r)),
|
||||
);
|
||||
break;
|
||||
case user.UserNotification.DidOpenWorkspace:
|
||||
result.fold(
|
||||
(payload) => _profileNotifier?.value =
|
||||
FlowyResult.success(UserProfilePB.fromBuffer(payload)),
|
||||
(error) => _profileNotifier?.value = FlowyResult.failure(error),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -41,11 +41,13 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
|
||||
onUserWorkspaceListUpdated: (workspaces) =>
|
||||
add(UserWorkspaceEvent.updateWorkspaces(workspaces)),
|
||||
onUserWorkspaceUpdated: (workspace) {
|
||||
// If currentWorkspace is updated, eg. Icon or Name, we should notify
|
||||
// the UI to render the updated information.
|
||||
final currentWorkspace = state.currentWorkspace;
|
||||
if (currentWorkspace?.workspaceId == workspace.workspaceId) {
|
||||
add(UserWorkspaceEvent.updateCurrentWorkspace(workspace));
|
||||
if (!isClosed) {
|
||||
// If currentWorkspace is updated, eg. Icon or Name, we should notify
|
||||
// the UI to render the updated information.
|
||||
final currentWorkspace = state.currentWorkspace;
|
||||
if (currentWorkspace?.workspaceId == workspace.workspaceId) {
|
||||
add(UserWorkspaceEvent.updateCurrentWorkspace(workspace));
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
29
frontend/rust-lib/Cargo.lock
generated
29
frontend/rust-lib/Cargo.lock
generated
@ -2819,14 +2819,11 @@ dependencies = [
|
||||
"arc-swap",
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"client-api",
|
||||
"collab",
|
||||
"collab-document",
|
||||
"collab-entity",
|
||||
"collab-folder",
|
||||
"collab-integrate",
|
||||
"collab-plugins",
|
||||
"dashmap 6.0.1",
|
||||
"flowy-codegen",
|
||||
"flowy-derive",
|
||||
@ -2835,12 +2832,10 @@ dependencies = [
|
||||
"flowy-notification",
|
||||
"flowy-search-pub",
|
||||
"flowy-sqlite",
|
||||
"flowy-user-pub",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
"nanoid",
|
||||
"num_enum",
|
||||
"protobuf",
|
||||
"regex",
|
||||
"serde",
|
||||
@ -3086,6 +3081,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
"num_enum",
|
||||
"protobuf",
|
||||
"quickcheck",
|
||||
"quickcheck_macros",
|
||||
@ -4868,6 +4864,27 @@ dependencies = [
|
||||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179"
|
||||
dependencies = [
|
||||
"num_enum_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.94",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.32.1"
|
||||
|
||||
@ -102,6 +102,7 @@ derive_builder = "0.20.2"
|
||||
tantivy = { version = "0.24.0" }
|
||||
af-plugin = { version = "0.1" }
|
||||
af-local-ai = { version = "0.1" }
|
||||
num_enum = "0.7.3"
|
||||
|
||||
# Please using the following command to update the revision id
|
||||
# Current directory: frontend
|
||||
|
||||
@ -8,13 +8,10 @@ edition = "2021"
|
||||
[dependencies]
|
||||
collab = { workspace = true }
|
||||
collab-folder = { workspace = true }
|
||||
collab-document = { workspace = true }
|
||||
collab-entity = { workspace = true }
|
||||
collab-plugins = { workspace = true }
|
||||
collab-integrate = { workspace = true }
|
||||
flowy-folder-pub = { workspace = true }
|
||||
flowy-search-pub = { workspace = true }
|
||||
flowy-user-pub = { workspace = true }
|
||||
flowy-sqlite = { workspace = true }
|
||||
flowy-derive.workspace = true
|
||||
flowy-notification = { workspace = true }
|
||||
@ -29,9 +26,6 @@ lib-dispatch = { workspace = true }
|
||||
bytes.workspace = true
|
||||
lib-infra = { workspace = true }
|
||||
tokio = { workspace = true, features = ["sync"] }
|
||||
nanoid = "0.4.0"
|
||||
lazy_static = "1.4.0"
|
||||
chrono = { workspace = true, default-features = false, features = ["clock"] }
|
||||
strum_macros = "0.21"
|
||||
protobuf.workspace = true
|
||||
uuid.workspace = true
|
||||
@ -44,6 +38,7 @@ client-api = { workspace = true }
|
||||
regex = "1.9.5"
|
||||
futures = "0.3.31"
|
||||
dashmap.workspace = true
|
||||
num_enum.workspace = true
|
||||
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@ -9,9 +9,7 @@ use crate::manager_observer::{
|
||||
notify_child_views_changed, notify_did_update_workspace, notify_parent_view_did_change,
|
||||
ChildViewChangeReason,
|
||||
};
|
||||
use crate::notification::{
|
||||
folder_notification_builder, send_current_workspace_notification, FolderNotification,
|
||||
};
|
||||
use crate::notification::{folder_notification_builder, FolderNotification};
|
||||
use crate::publish_util::{generate_publish_name, view_pb_to_publish_view};
|
||||
use crate::share::{ImportData, ImportItem, ImportParams};
|
||||
use crate::util::{folder_not_init_error, workspace_data_not_sync_error};
|
||||
@ -1255,7 +1253,12 @@ impl FolderManager {
|
||||
workspace_id: workspace_id.to_string(),
|
||||
latest_view: view,
|
||||
};
|
||||
send_current_workspace_notification(FolderNotification::DidUpdateWorkspaceSetting, setting);
|
||||
folder_notification_builder(
|
||||
self.user.user_id()?,
|
||||
FolderNotification::DidUpdateWorkspaceSetting,
|
||||
)
|
||||
.payload(setting)
|
||||
.send();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
use lib_dispatch::prelude::ToBytes;
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use tracing::trace;
|
||||
|
||||
const FOLDER_OBSERVABLE_SOURCE: &str = "Workspace";
|
||||
|
||||
#[derive(ProtoBuf_Enum, Debug, Default)]
|
||||
#[derive(ProtoBuf_Enum, Debug, Default, IntoPrimitive, TryFromPrimitive)]
|
||||
#[repr(i32)]
|
||||
pub enum FolderNotification {
|
||||
#[default]
|
||||
Unknown = 0,
|
||||
@ -17,6 +18,7 @@ pub enum FolderNotification {
|
||||
DidUpdateWorkspaceViews = 3,
|
||||
/// Trigger when the settings of the workspace are changed. The changes including the latest visiting view, etc
|
||||
DidUpdateWorkspaceSetting = 4,
|
||||
|
||||
DidUpdateView = 10,
|
||||
DidUpdateChildViews = 11,
|
||||
/// Trigger after deleting the view
|
||||
@ -39,36 +41,6 @@ pub enum FolderNotification {
|
||||
DidUpdateSectionViews = 39,
|
||||
}
|
||||
|
||||
impl std::convert::From<FolderNotification> for i32 {
|
||||
fn from(notification: FolderNotification) -> Self {
|
||||
notification as i32
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<i32> for FolderNotification {
|
||||
fn from(value: i32) -> Self {
|
||||
match value {
|
||||
1 => FolderNotification::DidCreateWorkspace,
|
||||
2 => FolderNotification::DidUpdateWorkspace,
|
||||
3 => FolderNotification::DidUpdateWorkspaceViews,
|
||||
4 => FolderNotification::DidUpdateWorkspaceSetting,
|
||||
10 => FolderNotification::DidUpdateView,
|
||||
11 => FolderNotification::DidUpdateChildViews,
|
||||
12 => FolderNotification::DidDeleteView,
|
||||
13 => FolderNotification::DidRestoreView,
|
||||
14 => FolderNotification::DidMoveViewToTrash,
|
||||
15 => FolderNotification::DidUpdateTrash,
|
||||
16 => FolderNotification::DidUpdateFolderSnapshotState,
|
||||
17 => FolderNotification::DidUpdateFolderSyncUpdate,
|
||||
36 => FolderNotification::DidFavoriteView,
|
||||
37 => FolderNotification::DidUnfavoriteView,
|
||||
38 => FolderNotification::DidUpdateRecentViews,
|
||||
39 => FolderNotification::DidUpdateSectionViews,
|
||||
_ => FolderNotification::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
pub(crate) fn folder_notification_builder<T: ToString>(
|
||||
id: T,
|
||||
@ -78,12 +50,3 @@ pub(crate) fn folder_notification_builder<T: ToString>(
|
||||
trace!("folder_notification_builder: id = {id}, ty = {ty:?}");
|
||||
NotificationBuilder::new(&id, ty, FOLDER_OBSERVABLE_SOURCE)
|
||||
}
|
||||
|
||||
/// 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";
|
||||
pub(crate) fn send_current_workspace_notification<T: ToBytes>(ty: FolderNotification, payload: T) {
|
||||
folder_notification_builder(CURRENT_WORKSPACE, ty)
|
||||
.payload(payload)
|
||||
.send();
|
||||
}
|
||||
|
||||
@ -46,6 +46,7 @@ tokio-stream = "0.1.14"
|
||||
semver = "1.0.22"
|
||||
validator = { workspace = true, features = ["derive"] }
|
||||
rayon = "1.10.0"
|
||||
num_enum.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
fake = "2.0.0"
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
use crate::entities::AuthStateChangedPB;
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
|
||||
use crate::entities::AuthStateChangedPB;
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use tracing::trace;
|
||||
|
||||
const USER_OBSERVABLE_SOURCE: &str = "User";
|
||||
|
||||
#[derive(ProtoBuf_Enum, Debug, Default)]
|
||||
#[derive(ProtoBuf_Enum, Debug, Default, IntoPrimitive, TryFromPrimitive, Clone)]
|
||||
#[repr(i32)]
|
||||
pub(crate) enum UserNotification {
|
||||
#[default]
|
||||
Unknown = 0,
|
||||
@ -18,17 +20,13 @@ pub(crate) enum UserNotification {
|
||||
DidLoadUserAwareness = 7,
|
||||
// TODO: implement reminder observer
|
||||
DidUpdateReminder = 8,
|
||||
DidOpenWorkspace = 9,
|
||||
}
|
||||
|
||||
impl std::convert::From<UserNotification> for i32 {
|
||||
fn from(notification: UserNotification) -> Self {
|
||||
notification as i32
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub(crate) fn send_notification(id: &str, ty: UserNotification) -> NotificationBuilder {
|
||||
NotificationBuilder::new(id, ty, USER_OBSERVABLE_SOURCE)
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
pub(crate) fn send_notification<T: ToString>(id: T, ty: UserNotification) -> NotificationBuilder {
|
||||
trace!("UserNotification: id = {}, ty = {:?}", id.to_string(), ty);
|
||||
NotificationBuilder::new(&id.to_string(), ty, USER_OBSERVABLE_SOURCE)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace")]
|
||||
|
||||
@ -7,8 +7,8 @@ use std::sync::Arc;
|
||||
|
||||
use crate::entities::{
|
||||
RepeatedUserWorkspacePB, SubscribeWorkspacePB, SuccessWorkspaceSubscriptionPB,
|
||||
UpdateUserWorkspaceSettingPB, UserWorkspacePB, WorkspaceSettingsPB, WorkspaceSubscriptionInfoPB,
|
||||
WorkspaceTypePB,
|
||||
UpdateUserWorkspaceSettingPB, UserProfilePB, UserWorkspacePB, WorkspaceSettingsPB,
|
||||
WorkspaceSubscriptionInfoPB, WorkspaceTypePB,
|
||||
};
|
||||
use crate::notification::{send_notification, UserNotification};
|
||||
use crate::services::billing_check::PeriodicallyCheckBillingState;
|
||||
@ -215,6 +215,11 @@ impl UserManager {
|
||||
);
|
||||
}
|
||||
|
||||
let pb = UserProfilePB::from(profile);
|
||||
send_notification(uid, UserNotification::DidOpenWorkspace)
|
||||
.payload(pb)
|
||||
.send();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user