diff --git a/src/posts/create.js b/src/posts/create.js index e74299c27c..fa7ca1d071 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -18,6 +18,7 @@ module.exports = function (Posts) { const content = data.content.toString(); const timestamp = data.timestamp || Date.now(); const isMain = data.isMain || false; + let hasAttachment = false; if (!uid && parseInt(uid, 10) !== 0) { throw new Error('[[error:invalid-uid]]'); @@ -46,23 +47,25 @@ module.exports = function (Posts) { if (_activitypub.audience) { postData.audience = _activitypub.audience; } - } - // Rewrite emoji references to inline image assets - if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) { - _activitypub.tag - .filter(tag => tag.type === 'Emoji' && - tag.icon && tag.icon.type === 'Image') - .forEach((tag) => { - if (!tag.name.startsWith(':')) { - tag.name = `:${tag.name}`; - } - if (!tag.name.endsWith(':')) { - tag.name = `${tag.name}:`; - } + // Rewrite emoji references to inline image assets + if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) { + _activitypub.tag + .filter(tag => tag.type === 'Emoji' && + tag.icon && tag.icon.type === 'Image') + .forEach((tag) => { + if (!tag.name.startsWith(':')) { + tag.name = `:${tag.name}`; + } + if (!tag.name.endsWith(':')) { + tag.name = `${tag.name}:`; + } - postData.content = postData.content.replace(new RegExp(tag.name, 'g'), ``); - }); + postData.content = postData.content.replace(new RegExp(tag.name, 'g'), ``); + }); + } + + hasAttachment = _activitypub && _activitypub.attachment && _activitypub.attachment.length; } ({ post: postData } = await plugins.hooks.fire('filter:post.create', { post: postData, data: data })); @@ -71,8 +74,6 @@ module.exports = function (Posts) { const topicData = await topics.getTopicFields(tid, ['cid', 'pinned']); postData.cid = topicData.cid; - const hasAttachment = _activitypub && _activitypub.attachment && _activitypub.attachment.length; - await Promise.all([ db.sortedSetAdd('posts:pid', timestamp, postData.pid), utils.isNumber(pid) ? db.incrObjectField('global', 'postCount') : null,