fix: Occassional user context not available in collaborative persistence
This commit is contained in:
parent
a600a897c3
commit
9865eab61c
|
@ -52,7 +52,7 @@ export default class Persistence {
|
||||||
documentName,
|
documentName,
|
||||||
}: {
|
}: {
|
||||||
document: Y.Doc,
|
document: Y.Doc,
|
||||||
context: { user: User },
|
context: { user: ?User },
|
||||||
documentName: string,
|
documentName: string,
|
||||||
}) => {
|
}) => {
|
||||||
const [, documentId] = documentName.split(".");
|
const [, documentId] = documentName.split(".");
|
||||||
|
@ -63,7 +63,7 @@ export default class Persistence {
|
||||||
await documentUpdater({
|
await documentUpdater({
|
||||||
documentId,
|
documentId,
|
||||||
ydoc: document,
|
ydoc: document,
|
||||||
userId: context.user.id,
|
userId: context.user?.id,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error("Unable to persist document", err, {
|
Logger.error("Unable to persist document", err, {
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default async function documentUpdater({
|
||||||
}: {
|
}: {
|
||||||
documentId: string,
|
documentId: string,
|
||||||
ydoc: Y.Doc,
|
ydoc: Y.Doc,
|
||||||
userId: string,
|
userId?: string,
|
||||||
}) {
|
}) {
|
||||||
const document = await Document.findByPk(documentId);
|
const document = await Document.findByPk(documentId);
|
||||||
const state = Y.encodeStateAsUpdate(ydoc);
|
const state = Y.encodeStateAsUpdate(ydoc);
|
||||||
|
@ -38,7 +38,8 @@ export default async function documentUpdater({
|
||||||
text,
|
text,
|
||||||
state: Buffer.from(state),
|
state: Buffer.from(state),
|
||||||
updatedAt: isUnchanged ? document.updatedAt : new Date(),
|
updatedAt: isUnchanged ? document.updatedAt : new Date(),
|
||||||
lastModifiedById: isUnchanged ? document.lastModifiedById : userId,
|
lastModifiedById:
|
||||||
|
isUnchanged || !userId ? document.lastModifiedById : userId,
|
||||||
collaboratorIds,
|
collaboratorIds,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Reference in New Issue