mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
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:
@@ -2,7 +2,6 @@ import { DesktopApiService } from '@affine/core/modules/desktop-api';
|
||||
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||
import type { SettingTab } from '@affine/core/modules/dialogs/constant';
|
||||
import { DocsService } from '@affine/core/modules/doc';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { JournalService } from '@affine/core/modules/journal';
|
||||
import { LifecycleService } from '@affine/core/modules/lifecycle';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
@@ -52,15 +51,9 @@ export function setupEvents(frameworkProvider: FrameworkProvider) {
|
||||
return;
|
||||
}
|
||||
const { workspace } = currentWorkspace;
|
||||
const editorSettingService =
|
||||
frameworkProvider.get(EditorSettingService);
|
||||
const docsService = workspace.scope.get(DocsService);
|
||||
const editorSetting = editorSettingService.editorSetting;
|
||||
|
||||
const docProps = {
|
||||
note: editorSetting.get('affine:note'),
|
||||
};
|
||||
const page = docsService.createDoc({ docProps, primaryMode: type });
|
||||
const page = docsService.createDoc({ primaryMode: type });
|
||||
workspace.scope.get(WorkbenchService).workbench.openDoc(page.id);
|
||||
})
|
||||
.catch(err => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { DocProps } from '@affine/core/blocksuite/initialization';
|
||||
import { DocsService } from '@affine/core/modules/doc';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { AudioAttachmentService } from '@affine/core/modules/media/services/audio-attachment';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
@@ -8,7 +7,6 @@ import { apis, events } from '@affine/electron-api';
|
||||
import { i18nTime } from '@affine/i18n';
|
||||
import track from '@affine/track';
|
||||
import type { AttachmentBlockModel } from '@blocksuite/affine/model';
|
||||
import { Text } from '@blocksuite/affine/store';
|
||||
import type { BlobEngine } from '@blocksuite/affine/sync';
|
||||
import type { FrameworkProvider } from '@toeverything/infra';
|
||||
|
||||
@@ -40,10 +38,7 @@ export function setupRecordingEvents(frameworkProvider: FrameworkProvider) {
|
||||
return;
|
||||
}
|
||||
const { workspace } = currentWorkspace;
|
||||
const editorSettingService =
|
||||
frameworkProvider.get(EditorSettingService);
|
||||
const docsService = workspace.scope.get(DocsService);
|
||||
const editorSetting = editorSettingService.editorSetting;
|
||||
const aiEnabled = isAiEnabled(frameworkProvider);
|
||||
|
||||
const timestamp = i18nTime(status.startTime, {
|
||||
@@ -54,15 +49,6 @@ export function setupRecordingEvents(frameworkProvider: FrameworkProvider) {
|
||||
});
|
||||
|
||||
const docProps: DocProps = {
|
||||
note: editorSetting.get('affine:note'),
|
||||
page: {
|
||||
title: new Text(
|
||||
'Recording ' +
|
||||
(status.appName ?? 'System Audio') +
|
||||
' ' +
|
||||
timestamp
|
||||
),
|
||||
},
|
||||
onStoreLoad: (doc, { noteId }) => {
|
||||
(async () => {
|
||||
// name + timestamp(readable) + extension
|
||||
@@ -136,7 +122,12 @@ export function setupRecordingEvents(frameworkProvider: FrameworkProvider) {
|
||||
});
|
||||
},
|
||||
};
|
||||
const page = docsService.createDoc({ docProps, primaryMode: 'page' });
|
||||
const page = docsService.createDoc({
|
||||
docProps,
|
||||
title:
|
||||
'Recording ' + (status.appName ?? 'System Audio') + ' ' + timestamp,
|
||||
primaryMode: 'page',
|
||||
});
|
||||
workspace.scope.get(WorkbenchService).workbench.openDoc(page.id);
|
||||
}
|
||||
})().catch(console.error);
|
||||
|
||||
Reference in New Issue
Block a user