mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-18 14:30:22 +01:00
refactor: move post attachment handling directly into posts.create
This commit is contained in:
@@ -210,7 +210,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
activitypub.helpers.log(`[notes/assert] ${count} new note(s) found.`);
|
activitypub.helpers.log(`[notes/assert] ${count} new note(s) found.`);
|
||||||
|
|
||||||
if (!hasTid) {
|
if (!hasTid) {
|
||||||
const { to, cc, attachment } = mainPost._activitypub;
|
const { to, cc } = mainPost._activitypub;
|
||||||
const tags = await Notes._normalizeTags(mainPost._activitypub.tag || []);
|
const tags = await Notes._normalizeTags(mainPost._activitypub.tag || []);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -239,7 +239,6 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
id: tid,
|
id: tid,
|
||||||
path: mainPost._activitypub.image,
|
path: mainPost._activitypub.image,
|
||||||
}) : null,
|
}) : null,
|
||||||
posts.attachments.update(mainPid, attachment),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (context) {
|
if (context) {
|
||||||
@@ -249,16 +248,13 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const post of unprocessed) {
|
for (const post of unprocessed) {
|
||||||
const { to, cc, attachment } = post._activitypub;
|
const { to, cc } = post._activitypub;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await topics.reply(post);
|
await topics.reply(post);
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await Promise.all([
|
await Notes.updateLocalRecipients(post.pid, { to, cc });
|
||||||
Notes.updateLocalRecipients(post.pid, { to, cc }),
|
|
||||||
posts.attachments.update(post.pid, attachment),
|
|
||||||
]);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
activitypub.helpers.log(`[activitypub/notes.assert] Could not add reply (${post.pid}): ${e.message}`);
|
activitypub.helpers.log(`[activitypub/notes.assert] Could not add reply (${post.pid}): ${e.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ module.exports = function (Posts) {
|
|||||||
const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']);
|
const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']);
|
||||||
postData.cid = topicData.cid;
|
postData.cid = topicData.cid;
|
||||||
|
|
||||||
|
const hasAttachment = _activitypub.attachment && _activitypub.attachment.length;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetAdd('posts:pid', timestamp, postData.pid),
|
db.sortedSetAdd('posts:pid', timestamp, postData.pid),
|
||||||
utils.isNumber(pid) ? db.incrObjectField('global', 'postCount') : null,
|
utils.isNumber(pid) ? db.incrObjectField('global', 'postCount') : null,
|
||||||
@@ -79,7 +81,8 @@ module.exports = function (Posts) {
|
|||||||
categories.onNewPostMade(topicData.cid, topicData.pinned, postData),
|
categories.onNewPostMade(topicData.cid, topicData.pinned, postData),
|
||||||
groups.onNewPostMade(postData),
|
groups.onNewPostMade(postData),
|
||||||
addReplyTo(postData, timestamp),
|
addReplyTo(postData, timestamp),
|
||||||
Posts.uploads.sync(postData.pid),
|
Posts.uploads.sync(pid),
|
||||||
|
hasAttachment ? Posts.attachments.update(pid, _activitypub.attachment) : null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const 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 });
|
||||||
|
|||||||
Reference in New Issue
Block a user