feat: log all post edits to the event log, return eid when logging events, plumb eid into Update(Note) to federate out as a unique id

This commit is contained in:
Julian Lam
2024-03-13 15:27:59 -04:00
parent 0bfdbb6a5c
commit 83392f3ca2
3 changed files with 11 additions and 6 deletions

View File

@@ -131,7 +131,7 @@ activitypubApi.update.profile = enabledCheck(async (caller, { uid }) => {
}); });
}); });
activitypubApi.update.note = enabledCheck(async (caller, { post }) => { activitypubApi.update.note = enabledCheck(async (caller, { post, eid }) => {
const object = await activitypub.mocks.note(post); const object = await activitypub.mocks.note(post);
const { targets } = await buildRecipients(object, post.user.uid); const { targets } = await buildRecipients(object, post.user.uid);
@@ -142,6 +142,7 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
} }
const payload = { const payload = {
id: `${nconf.get('url')}/api/v3/events/${eid}`,
type: 'Update', type: 'Update',
to: object.to, to: object.to,
cc: object.cc, cc: object.cc,

View File

@@ -112,16 +112,16 @@ postsAPI.edit = async function (caller, data) {
if (editResult.topic.isMainPost) { if (editResult.topic.isMainPost) {
await topics.thumbs.migrate(data.uuid, editResult.topic.tid); await topics.thumbs.migrate(data.uuid, editResult.topic.tid);
} }
const selfPost = parseInt(caller.uid, 10) === parseInt(editResult.post.uid, 10); let eid;
if (!selfPost && editResult.post.changed) { if (editResult.post.changed) {
await events.log({ ({ eid } = await events.log({
type: `post-edit`, type: `post-edit`,
uid: caller.uid, uid: caller.uid,
ip: caller.ip, ip: caller.ip,
pid: editResult.post.pid, pid: editResult.post.pid,
oldContent: editResult.post.oldContent, oldContent: editResult.post.oldContent,
newContent: editResult.post.newContent, newContent: editResult.post.newContent,
}); }));
} }
if (editResult.topic.renamed) { if (editResult.topic.renamed) {
@@ -140,7 +140,9 @@ postsAPI.edit = async function (caller, data) {
if (!editResult.post.deleted) { if (!editResult.post.deleted) {
websockets.in(`topic_${editResult.topic.tid}`).emit('event:post_edited', editResult); websockets.in(`topic_${editResult.topic.tid}`).emit('event:post_edited', editResult);
await require('.').activitypub.update.note(caller, { post: postObj[0] }); if (eid) {
await require('.').activitypub.update.note(caller, { post: postObj[0], eid });
}
return returnData; return returnData;
} }

View File

@@ -96,6 +96,8 @@ events.log = async function (data) {
db.setObject(`event:${eid}`, data), db.setObject(`event:${eid}`, data),
]); ]);
plugins.hooks.fire('action:events.log', { data: data }); plugins.hooks.fire('action:events.log', { data: data });
return { eid };
}; };
events.getEvents = async function (filter, start, stop, from, to) { events.getEvents = async function (filter, start, stop, from, to) {