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
@@ -1,49 +0,0 @@
import { WorkspaceService } from '@affine/core/modules/workspace';
import { useLiveData, useService } from '@toeverything/infra';
import { useEffect } from 'react';
import { AuthService } from '../../../modules/cloud';
const SyncAwarenessInnerLoggedIn = () => {
const authService = useService(AuthService);
const account = useLiveData(authService.session.account$);
const currentWorkspace = useService(WorkspaceService).workspace;
useEffect(() => {
if (account && currentWorkspace) {
currentWorkspace.docCollection.awarenessStore.awareness.setLocalStateField(
'user',
{
name: account.label,
// TODO(@eyhn): add avatar?
}
);
return () => {
currentWorkspace.docCollection.awarenessStore.awareness.setLocalStateField(
'user',
null
);
};
}
return;
}, [currentWorkspace, account]);
return null;
};
const SyncAwarenessInner = () => {
const session = useService(AuthService).session;
const loginStatus = useLiveData(session.status$);
if (loginStatus === 'authenticated') {
return <SyncAwarenessInnerLoggedIn />;
}
return null;
};
// TODO(@eyhn): we could do something more interesting here, e.g., show where the current user is
export const SyncAwareness = () => {
return <SyncAwarenessInner />;
};
@@ -8,7 +8,6 @@ import {
CopilotClient,
setupAIProvider,
} from '@affine/core/blocksuite/ai';
import { SyncAwareness } from '@affine/core/components/affine/awareness';
import { useRegisterFindInPageCommands } from '@affine/core/components/hooks/affine/use-register-find-in-page-commands';
import { useRegisterWorkspaceCommands } from '@affine/core/components/hooks/use-register-workspace-commands';
import { OverCapacityNotification } from '@affine/core/components/over-capacity';
@@ -176,7 +175,6 @@ export const WorkspaceSideEffects = () => {
return (
<>
<QuickSearchContainer />
<SyncAwareness />
<OverCapacityNotification />
</>
);