feat(core): doc level awareness (#10646)
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user