From 5e18691ab54120c5bdcf098beb7aa3c6d5db9f4d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 23 Feb 2022 12:37:12 -0500 Subject: [PATCH] Fix custom emoji parsing --- .../__fixtures__/status-custom-emoji.json | 126 ++++++++++++++++++ .../reducers/__tests__/statuses-test.js | 9 ++ app/soapbox/reducers/statuses.js | 2 +- 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 app/soapbox/__fixtures__/status-custom-emoji.json diff --git a/app/soapbox/__fixtures__/status-custom-emoji.json b/app/soapbox/__fixtures__/status-custom-emoji.json new file mode 100644 index 000000000..ac3f184ee --- /dev/null +++ b/app/soapbox/__fixtures__/status-custom-emoji.json @@ -0,0 +1,126 @@ +{ + "account": { + "acct": "benis911", + "avatar": "https://gleasonator.com/images/avi.png", + "avatar_static": "https://gleasonator.com/images/avi.png", + "bot": false, + "created_at": "2021-03-26T20:42:11.000Z", + "display_name": "benis911", + "emojis": [], + "fields": [], + "followers_count": 0, + "following_count": 0, + "fqn": "benis911@gleasonator.com", + "header": "https://media.gleasonator.com/fc595bbbcf5aabefecd1c2adfe5b7f5457db59847992881668653a0338ba25bd.jpg", + "header_static": "https://media.gleasonator.com/fc595bbbcf5aabefecd1c2adfe5b7f5457db59847992881668653a0338ba25bd.jpg", + "id": "A5c5LK7EJTFR0u26Pg", + "last_status_at": "2022-02-23T17:31:08", + "locked": true, + "note": "hello world 2", + "pleroma": { + "accepts_chat_messages": true, + "also_known_as": [ + "https://gleasonator.com/users/alex", + "https://poa.st/users/alex" + ], + "ap_id": "https://gleasonator.com/users/benis911", + "background_image": null, + "birthday": "2000-01-25", + "favicon": "https://gleasonator.com/favicon.png", + "hide_favorites": true, + "hide_followers": true, + "hide_followers_count": true, + "hide_follows": true, + "hide_follows_count": true, + "is_admin": false, + "is_confirmed": true, + "is_moderator": false, + "is_suggested": false, + "relationship": {}, + "skip_thread_containment": false, + "tags": [] + }, + "source": { + "fields": [], + "note": "hello world 2", + "pleroma": { + "actor_type": "Person", + "discoverable": false + }, + "sensitive": false + }, + "statuses_count": 152, + "url": "https://gleasonator.com/users/benis911", + "username": "benis911" + }, + "application": { + "name": "Soapbox FE", + "website": "https://soapbox.pub/" + }, + "bookmarked": false, + "card": null, + "content": "Hello :ablobcathyper: :ageblobcat: 😂 world 😋 test :blobcatphoto:", + "created_at": "2022-02-23T17:31:07.000Z", + "emojis": [ + { + "shortcode": "ablobcathyper", + "static_url": "https://gleasonator.com/emoji/blobcat/ablobcathyper.png", + "url": "https://gleasonator.com/emoji/blobcat/ablobcathyper.png", + "visible_in_picker": false + }, + { + "shortcode": "ageblobcat", + "static_url": "https://gleasonator.com/emoji/blobcat/ageblobcat.png", + "url": "https://gleasonator.com/emoji/blobcat/ageblobcat.png", + "visible_in_picker": false + }, + { + "shortcode": "blobcatphoto", + "static_url": "https://gleasonator.com/emoji/blobcat/blobcatphoto.png", + "url": "https://gleasonator.com/emoji/blobcat/blobcatphoto.png", + "visible_in_picker": false + } + ], + "favourited": false, + "favourites_count": 0, + "id": "AGm7uC9DaAIGUa4KYK", + "in_reply_to_account_id": null, + "in_reply_to_id": null, + "language": null, + "media_attachments": [], + "mentions": [], + "muted": false, + "pinned": false, + "pleroma": { + "content": { + "text/plain": "Hello :ablobcathyper: :ageblobcat: 😂 world 😋 test :blobcatphoto:" + }, + "conversation_id": "AGm7uC3BwZTOBtFW9w", + "direct_conversation_id": null, + "emoji_reactions": [], + "expires_at": null, + "in_reply_to_account_acct": null, + "local": true, + "parent_visible": false, + "pinned_at": null, + "quote": null, + "quote_url": null, + "quote_visible": false, + "spoiler_text": { + "text/plain": "" + }, + "thread_muted": false + }, + "poll": null, + "reblog": null, + "reblogged": false, + "reblogs_count": 0, + "replies_count": 0, + "sensitive": false, + "spoiler_text": "", + "tags": [], + "text": null, + "uri": "https://gleasonator.com/objects/2dc79219-aed6-40c0-8818-0c2d26ed3436", + "url": "https://gleasonator.com/notice/AGm7uC9DaAIGUa4KYK", + "visibility": "public" +} diff --git a/app/soapbox/reducers/__tests__/statuses-test.js b/app/soapbox/reducers/__tests__/statuses-test.js index 0ca31c745..779c0e847 100644 --- a/app/soapbox/reducers/__tests__/statuses-test.js +++ b/app/soapbox/reducers/__tests__/statuses-test.js @@ -98,6 +98,15 @@ describe('statuses reducer', () => { expect(hidden).toBe(false); }); + it('parses custom emojis', () => { + const status = require('soapbox/__fixtures__/status-custom-emoji.json'); + const action = { type: STATUS_IMPORT, status }; + + const expected = 'Hello :ablobcathyper: :ageblobcat: 😂 world 😋 test :blobcatphoto:'; + + const result = reducer(undefined, action).getIn(['AGm7uC9DaAIGUa4KYK', 'contentHtml']); + expect(result).toBe(expected); + }); }); describe('STATUS_CREATE_REQUEST', () => { diff --git a/app/soapbox/reducers/statuses.js b/app/soapbox/reducers/statuses.js index ab822b59f..aca48b9c1 100644 --- a/app/soapbox/reducers/statuses.js +++ b/app/soapbox/reducers/statuses.js @@ -33,7 +33,7 @@ import { TIMELINE_DELETE } from '../actions/timelines'; const domParser = new DOMParser(); const makeEmojiMap = record => record.get('emojis').reduce((obj, emoji) => { - obj[`:${emoji.get('shortcode')}:`] = emoji; + obj[`:${emoji.get('shortcode')}:`] = emoji.toJS(); return obj; }, {});