Node.js based forum software built for the modern web
fix(activitypub): keep emoji tags when tag is a single object
Julian Lam740511cf0d30
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.jsindex 815198ebbc..89b55e2077 100644--- a/src/activitypub/notes.js+++ b/src/activitypub/notes.js@@ -223,9 +223,9 @@ Notes.assert = async (uid, input, options = { skipChecks: false, queue: false })// Extract emoji metadata for title renderingconst titleEmoji = [];- const emojiTags = Array.isArray(_activitypub.tag) ?- _activitypub.tag.filter(tag => tag?.type === 'Emoji') :- [];+ const rawTags = _activitypub.tag;+ const tagList = Array.isArray(rawTags) ? rawTags : (rawTags ? [rawTags] : []);+ const emojiTags = tagList.filter(tag => tag?.type === 'Emoji');for (const tag of emojiTags) {const { name, icon } = tag;if (!name || !icon?.url) continue;diff --git a/test/activitypub/notes.js b/test/activitypub/notes.jsindex deb615fe95..bbea4e5385 100644--- a/test/activitypub/notes.js+++ b/test/activitypub/notes.js@@ -74,6 +74,33 @@ describe('Notes', () => {assert(exists);});+ it('should extract emoji metadata when the tag property is a single object rather than an array', async () => {+ const { id } = helpers.mocks.note({+ name: null, // no name so the title is generated from the content+ content: '<p>Hello :test: world</p>',+ tag: {+ type: 'Emoji',+ name: 'test',+ icon: { url: 'https://example.com/emoji.png' },+ },+ });+ const assertion = await activitypub.notes.assert(0, id, { skipChecks: true });+ assert(assertion);++ const { tid, count } = assertion;+ assert(tid);+ assert.strictEqual(count, 1);++ const exists = await topics.exists(tid);+ assert(exists);++ // A single-object "tag" must still yield emoji metadata (#15023)+ const titleEmoji = await topics.getTopicField(tid, 'titleEmoji');+ assert(Array.isArray(titleEmoji));+ assert.strictEqual(titleEmoji.length, 1);+ assert.strictEqual(titleEmoji[0].code, ':test:');+ });+describe('Content warnings', () => {it('should store contentWarning for Note with summary and sensitive: true', async () => {const cwText = 'Spoiler: major plot twist';