feat(core): doc level awareness (#10646)

This commit is contained in:
EYHN
2025-03-06 06:05:45 +00:00
parent 2b30d756e2
commit 5c8b81581c
14 changed files with 65 additions and 79 deletions

View File

@@ -39,6 +39,7 @@ import { type Framework } from '@toeverything/infra';
import { DocScope } from '../doc/scopes/doc';
import { DocService } from '../doc/services/doc';
import { EditorScope } from '../editor';
import { GlobalCache, GlobalState } from '../storage/providers/global';
import { GlobalStateService } from '../storage/services/global';
import { UrlService } from '../url';
@@ -63,6 +64,7 @@ import { AuthService } from './services/auth';
import { CaptchaService } from './services/captcha';
import { CloudDocMetaService } from './services/cloud-doc-meta';
import { DefaultServerService } from './services/default-server';
import { EditorUserCursorLabelService } from './services/editor-user-cursor-label';
import { EventSourceService } from './services/eventsource';
import { FetchService } from './services/fetch';
import { GraphQLService } from './services/graphql';
@@ -168,4 +170,10 @@ export function configureCloudModule(framework: Framework) {
.entity(WorkspaceInvoices, [WorkspaceService, WorkspaceServerService])
.service(SelfhostLicenseService, [SelfhostLicenseStore, WorkspaceService])
.store(SelfhostLicenseStore, [WorkspaceServerService]);
framework
.scope(WorkspaceScope)
.scope(DocScope)
.scope(EditorScope)
.service(EditorUserCursorLabelService, [WorkspaceServerService]);
}

View File

@@ -0,0 +1,27 @@
import { OnEvent, Service } from '@toeverything/infra';
import type { Editor } from '../../editor';
import { EditorInitialized } from '../../editor/events';
import type { WorkspaceServerService } from './workspace-server';
@OnEvent(EditorInitialized, i => i.onEditorInitialized)
export class EditorUserCursorLabelService extends Service {
constructor(private readonly workspaceServerService: WorkspaceServerService) {
super();
}
onEditorInitialized(editor: Editor) {
if (this.workspaceServerService.server) {
const subscription =
this.workspaceServerService.server.account$.subscribe(account => {
editor.doc.blockSuiteDoc.awarenessStore.awareness.setLocalStateField(
'user',
{
name: account?.label,
}
);
});
this.disposables.push(() => subscription.unsubscribe());
}
}
}