refactor(core): implement doc created/updated by service (#12150)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Documents now automatically track and display "created by" and "updated by" user information.
  - Document creation and update timestamps are now managed and shown more accurately.
  - Workspace and document metadata (name, avatar) updates are more responsive and reliable.
  - Document creation supports middleware for customizing properties and behavior.

- **Improvements**
  - Simplified and unified event handling for document list updates, reducing redundant event subscriptions.
  - Enhanced integration of editor and theme settings into the document creation process.
  - Explicit Yjs document initialization for improved workspace stability and reliability.
  - Consolidated journal-related metadata display in document icons and titles for clarity.

- **Bug Fixes**
  - Fixed inconsistencies in how workspace and document names are set and updated.
  - Improved accuracy of "last updated" indicators by handling timestamps automatically.

- **Refactor**
  - Removed deprecated event subjects and direct metadata manipulation in favor of more robust, reactive patterns.
  - Streamlined document creation logic across various features (quick search, journal, recording, etc.).
  - Simplified user avatar display components and removed cloud metadata dependencies.
  - Removed legacy editor setting and theme service dependencies from multiple modules.

- **Chores**
  - Updated internal APIs and interfaces to support new metadata and event handling mechanisms.
  - Cleaned up unused code and dependencies related to editor settings and theme services.
  - Skipped flaky end-to-end test to improve test suite stability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-05-08 07:53:33 +00:00
parent 93d74ff220
commit 2d1600fa00
56 changed files with 496 additions and 458 deletions
@@ -2,14 +2,17 @@ import { getAFFiNEWorkspaceSchema } from '@affine/core/modules/workspace';
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
import type { DocSnapshot, Store } from '@blocksuite/affine/store';
import { Transformer } from '@blocksuite/affine/store';
import { Doc as YDoc } from 'yjs';
const getCollection = (() => {
let collection: WorkspaceImpl | null = null;
return async function () {
if (collection) {
return collection;
}
collection = new WorkspaceImpl({});
collection = new WorkspaceImpl({
id: 'edgeless-settings',
rootDoc: new YDoc({ guid: 'edgeless-settings' }),
});
collection.meta.initialize();
return collection;
};
@@ -38,22 +38,11 @@ export const ProfilePanel = () => {
}, [workspace])
);
const [name, setName] = useState('');
const currentName = useLiveData(workspace.name$);
useEffect(() => {
if (workspace?.docCollection) {
setName(workspace.docCollection.meta.name ?? UNTITLED_WORKSPACE_NAME);
const dispose =
workspace.docCollection.meta.commonFieldsUpdated.subscribe(() => {
setName(workspace.docCollection.meta.name ?? UNTITLED_WORKSPACE_NAME);
});
return () => {
dispose.unsubscribe();
};
} else {
setName(UNTITLED_WORKSPACE_NAME);
}
return;
}, [workspace]);
setName(currentName ?? UNTITLED_WORKSPACE_NAME);
}, [currentName]);
const setWorkspaceAvatar = useCallback(
async (file: File | null) => {
@@ -61,14 +50,14 @@ export const ProfilePanel = () => {
return;
}
if (!file) {
workspace.docCollection.meta.setAvatar('');
workspace.setAvatar('');
return;
}
try {
const reducedFile = await validateAndReduceImage(file);
const blobs = workspace.docCollection.blobSync;
const blobId = await blobs.set(reducedFile);
workspace.docCollection.meta.setAvatar(blobId);
workspace.setAvatar(blobId);
} catch (error) {
console.error(error);
throw error;
@@ -82,7 +71,7 @@ export const ProfilePanel = () => {
if (!workspace) {
return;
}
workspace.docCollection.meta.setName(name);
workspace.setName(name);
},
[workspace]
);