fix: accidental saving of ephemeral _activitypub object into db, should plumb into hooks only

This commit is contained in:
Julian Lam
2024-03-13 11:19:50 -04:00
parent c6624b6341
commit 81b319f494
2 changed files with 5 additions and 6 deletions

View File

@@ -35,7 +35,6 @@ module.exports = function (Posts) {
tid: tid, tid: tid,
content: content, content: content,
timestamp: timestamp, timestamp: timestamp,
_activitypub,
}; };
if (data.toPid) { if (data.toPid) {
@@ -48,8 +47,7 @@ module.exports = function (Posts) {
postData.handle = data.handle; postData.handle = data.handle;
} }
let result = await plugins.hooks.fire('filter:post.create', { post: postData, data: data }); ({ post: postData } = await plugins.hooks.fire('filter:post.create', { post: postData, data: data }));
postData = result.post;
await db.setObject(`post:${postData.pid}`, postData); await db.setObject(`post:${postData.pid}`, postData);
const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']); const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']);
@@ -66,9 +64,9 @@ module.exports = function (Posts) {
Posts.uploads.sync(postData.pid), Posts.uploads.sync(postData.pid),
]); ]);
result = await plugins.hooks.fire('filter:post.get', { post: postData, uid: data.uid }); const result = await plugins.hooks.fire('filter:post.get', { post: postData, uid: data.uid });
result.post.isMain = isMain; result.post.isMain = isMain;
plugins.hooks.fire('action:post.save', { post: _.clone(result.post) }); plugins.hooks.fire('action:post.save', { post: { ...result.post, _activitypub } });
return result.post; return result.post;
}; };

View File

@@ -20,6 +20,7 @@ module.exports = function (Posts) {
}); });
Posts.edit = async function (data) { Posts.edit = async function (data) {
const { _activitypub } = data;
const canEdit = await privileges.posts.canEdit(data.pid, data.uid); const canEdit = await privileges.posts.canEdit(data.pid, data.uid);
if (!canEdit.flag) { if (!canEdit.flag) {
throw new Error(canEdit.message); throw new Error(canEdit.message);
@@ -89,7 +90,7 @@ module.exports = function (Posts) {
}); });
await topics.syncBacklinks(returnPostData); await topics.syncBacklinks(returnPostData);
plugins.hooks.fire('action:post.edit', { post: _.clone(returnPostData), data: data, uid: data.uid }); plugins.hooks.fire('action:post.edit', { post: { ...returnPostData, _activitypub }, data: data, uid: data.uid });
require('./cache').del(String(postData.pid)); require('./cache').del(String(postData.pid));
pubsub.publish('post:edit', String(postData.pid)); pubsub.publish('post:edit', String(postData.pid));