pass userId and avatar to awareness

This commit is contained in:
Philipinho
2026-09-29 21:39:07 +01:00
parent 00619d9868
commit f2d81744bb
2 changed files with 13 additions and 1 deletions
@@ -471,7 +471,9 @@ export const collabExtensions: CollabExtensions = (provider, user) => [
CollaborationCaret.configure({
provider,
user: {
id: user.id,
name: user.name,
avatarUrl: user.avatarUrl,
color: randomElement(userColors),
},
}),
@@ -224,7 +224,12 @@ export class PersistenceExtension implements Extension {
}
// Drop malformed awareness before it is broadcast
async beforeHandleAwareness({ states }: beforeHandleAwarenessPayload) {
async beforeHandleAwareness({
states,
context,
}: beforeHandleAwarenessPayload) {
const user = context?.user;
for (const [clientId, state] of states) {
if (!isRenderableObject(state)) {
states.delete(clientId);
@@ -235,6 +240,11 @@ export class PersistenceExtension implements Extension {
delete state.user;
}
if (state.user && user) {
state.user.id = user.id;
state.user.avatarUrl = user.avatarUrl ?? null;
}
if (
'cursor' in state &&
state.cursor !== null &&