diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 9094d077b1..19f149caec 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -95,6 +95,7 @@ inbox.update = async (req) => { switch (true) { case isNote: { const postData = await activitypub.mocks.post(object); + postData.tags = await activitypub.notes._normalizeTags(postData._activitypub.tag, postData.cid); await posts.edit(postData); const isDeleted = await posts.getPostField(object.id, 'deleted'); if (isDeleted) { diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 3bae10b50f..b569768f98 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -355,12 +355,13 @@ Mocks.post = async (objects) => { uid, pid, // tid, --> purposely omitted - name, content, sourceContent, timestamp, toPid, + title: name, // used in post.edit + edited, editor: edited ? uid : undefined, _activitypub: { to, cc, audience, attachment, tag, url, image }, diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 747eeb54d2..963ec5469f 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -27,6 +27,24 @@ async function unlock(value) { await db.deleteObjectField('locks', value); } +Notes._normalizeTags = async (tag, cid) => { + const systemTags = (meta.config.systemTags || '').split(','); + const maxTags = await categories.getCategoryField(cid, 'maxTags'); + const tags = (tag || []) + .map((tag) => { + tag.name = tag.name.startsWith('#') ? tag.name.slice(1) : tag.name; + return tag; + }) + .filter(o => o.type === 'Hashtag' && !systemTags.includes(o.name)) + .map(t => t.name); + + if (tags.length > maxTags) { + tags.length = maxTags; + } + + return tags; +}; + Notes.assert = async (uid, input, options = { skipChecks: false }) => { /** * Given the id or object of any as:Note, either retrieves the full context (if resolvable), @@ -166,22 +184,9 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { const count = unprocessed.length; activitypub.helpers.log(`[notes/assert] ${count} new note(s) found.`); - let tags; if (!hasTid) { const { to, cc, attachment } = mainPost._activitypub; - const systemTags = (meta.config.systemTags || '').split(','); - const maxTags = await categories.getCategoryField(cid, 'maxTags'); - tags = (mainPost._activitypub.tag || []) - .map((tag) => { - tag.name = tag.name.startsWith('#') ? tag.name.slice(1) : tag.name; - return tag; - }) - .filter(o => o.type === 'Hashtag' && !systemTags.includes(o.name)) - .map(t => t.name); - - if (tags.length > maxTags) { - tags.length = maxTags; - } + const tags = Notes._normalizeTags(mainPost._activitypub.tag || []); await Promise.all([ topics.post({ diff --git a/src/posts/edit.js b/src/posts/edit.js index 610a659e4f..077616b29e 100644 --- a/src/posts/edit.js +++ b/src/posts/edit.js @@ -35,7 +35,7 @@ module.exports = function (Posts) { await scheduledTopicCheck(data, topicData); data.content = data.content === null ? postData.content : data.content; - const oldContent = postData.content; // for diffing purposes + const oldContent = postData.sourceContent || postData.content; // for diffing purposes const editPostData = getEditPostData(data, topicData, postData); if (data.handle) { @@ -55,7 +55,7 @@ module.exports = function (Posts) { ]); await Posts.setPostFields(data.pid, result.post); - const contentChanged = data.content !== oldContent || + const contentChanged = ((data.sourceContent || data.content) !== oldContent) || topic.renamed || topic.tagsupdated; @@ -194,6 +194,7 @@ module.exports = function (Posts) { function getEditPostData(data, topicData, postData) { const editPostData = { content: data.content, + sourceContent: data.sourceContent, editor: data.uid, };