fix: Move notifications to be revision driven (#2709)

This commit is contained in:
Tom Moor
2021-10-31 18:36:16 -07:00
committed by GitHub
parent b6a058147e
commit 5f00e1394d
4 changed files with 58 additions and 44 deletions

View File

@@ -1048,6 +1048,7 @@ router.post("documents.update", auth(), async (ctx) => {
document.lastModifiedById = user.id;
const { collection } = document;
const changed = document.changed();
let transaction;
try {
@@ -1066,30 +1067,32 @@ router.post("documents.update", auth(), async (ctx) => {
throw err;
}
if (publish) {
await Event.create({
name: "documents.publish",
documentId: document.id,
collectionId: document.collectionId,
teamId: document.teamId,
actorId: user.id,
data: { title: document.title },
ip: ctx.request.ip,
});
} else {
await Event.create({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
teamId: document.teamId,
actorId: user.id,
data: {
autosave,
done,
title: document.title,
},
ip: ctx.request.ip,
});
if (changed) {
if (publish) {
await Event.create({
name: "documents.publish",
documentId: document.id,
collectionId: document.collectionId,
teamId: document.teamId,
actorId: user.id,
data: { title: document.title },
ip: ctx.request.ip,
});
} else {
await Event.create({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
teamId: document.teamId,
actorId: user.id,
data: {
autosave,
done,
title: document.title,
},
ip: ctx.request.ip,
});
}
}
if (document.title !== previousTitle) {