diff --git a/CHANGELOG.md b/CHANGELOG.md index 48fb6ddc0..f1d774e85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ServiceWorker: switch to a network-first strategy. The "An update is available!" prompt goes away. - Posts: increased font size of focused status in threads. - Posts: let "mute conversation" be clicked from any feed, not just noficiations. +- Posts: display all emoji reactions. ### Fixed - Chats: media attachments rendering at the wrong size and/or causing the chat to scroll on load. diff --git a/app/soapbox/utils/__tests__/emoji-reacts.test.ts b/app/soapbox/utils/__tests__/emoji-reacts.test.ts index 97f8e34db..f5c6f150c 100644 --- a/app/soapbox/utils/__tests__/emoji-reacts.test.ts +++ b/app/soapbox/utils/__tests__/emoji-reacts.test.ts @@ -5,7 +5,6 @@ import { normalizeStatus } from 'soapbox/normalizers'; import { sortEmoji, mergeEmojiFavourites, - filterEmoji, oneEmojiPerAccount, reduceEmoji, getReactForStatus, @@ -22,29 +21,10 @@ const ALLOWED_EMOJI = ImmutableList([ '😡', ]); -describe('filterEmoji', () => { - describe('with a mix of allowed and disallowed emoji', () => { - const emojiReacts = fromJS([ - { 'count': 1, 'me': true, 'name': '🌵' }, - { 'count': 1, 'me': true, 'name': '😂' }, - { 'count': 1, 'me': true, 'name': '👀' }, - { 'count': 1, 'me': true, 'name': '🍩' }, - { 'count': 1, 'me': true, 'name': '😡' }, - { 'count': 1, 'me': true, 'name': '🔪' }, - { 'count': 1, 'me': true, 'name': '😠' }, - ]) as ImmutableList>; - it('filters only allowed emoji', () => { - expect(filterEmoji(emojiReacts, ALLOWED_EMOJI)).toEqual(fromJS([ - { 'count': 1, 'me': true, 'name': '😂' }, - { 'count': 1, 'me': true, 'name': '😡' }, - ])); - }); - }); -}); - describe('sortEmoji', () => { describe('with an unsorted list of emoji', () => { const emojiReacts = fromJS([ + { 'count': 7, 'me': true, 'name': '😃' }, { 'count': 7, 'me': true, 'name': '😯' }, { 'count': 3, 'me': true, 'name': '😢' }, { 'count': 1, 'me': true, 'name': '😡' }, @@ -53,11 +33,12 @@ describe('sortEmoji', () => { { 'count': 15, 'me': true, 'name': '❤' }, ]) as ImmutableList>; it('sorts the emoji by count', () => { - expect(sortEmoji(emojiReacts)).toEqual(fromJS([ + expect(sortEmoji(emojiReacts, ALLOWED_EMOJI)).toEqual(fromJS([ { 'count': 20, 'me': true, 'name': '👍' }, { 'count': 15, 'me': true, 'name': '❤' }, { 'count': 7, 'me': true, 'name': '😯' }, { 'count': 7, 'me': true, 'name': '😂' }, + { 'count': 7, 'me': true, 'name': '😃' }, { 'count': 3, 'me': true, 'name': '😢' }, { 'count': 1, 'me': true, 'name': '😡' }, ])); @@ -127,6 +108,10 @@ describe('reduceEmoji', () => { { 'count': 7, 'me': false, 'name': '😂' }, { 'count': 3, 'me': false, 'name': '😢' }, { 'count': 1, 'me': false, 'name': '😡' }, + { 'count': 1, 'me': true, 'name': '🔪' }, + { 'count': 1, 'me': true, 'name': '🌵' }, + { 'count': 1, 'me': false, 'name': '👀' }, + { 'count': 1, 'me': false, 'name': '🍩' }, ])); }); }); diff --git a/app/soapbox/utils/emoji-reacts.ts b/app/soapbox/utils/emoji-reacts.ts index 2e13627d3..b9104e783 100644 --- a/app/soapbox/utils/emoji-reacts.ts +++ b/app/soapbox/utils/emoji-reacts.ts @@ -19,12 +19,10 @@ export const ALLOWED_EMOJI = ImmutableList([ type Account = ImmutableMap; type EmojiReact = ImmutableMap; -export const sortEmoji = (emojiReacts: ImmutableList): ImmutableList => ( - emojiReacts.sortBy(emojiReact => -emojiReact.get('count')) -); - -export const mergeEmoji = (emojiReacts: ImmutableList): ImmutableList => ( - emojiReacts // TODO: Merge similar emoji +export const sortEmoji = (emojiReacts: ImmutableList, allowedEmoji: ImmutableList): ImmutableList => ( + emojiReacts + .sortBy(emojiReact => + -(emojiReact.get('count') + Number(allowedEmoji.includes(emojiReact.get('name'))))) ); export const mergeEmojiFavourites = (emojiReacts = ImmutableList(), favouritesCount: number, favourited: boolean) => { @@ -70,15 +68,11 @@ export const oneEmojiPerAccount = (emojiReacts: ImmutableList, me: M .reverse(); }; -export const filterEmoji = (emojiReacts: ImmutableList, allowedEmoji = ALLOWED_EMOJI): ImmutableList => ( - emojiReacts.filter(emojiReact => ( - allowedEmoji.includes(emojiReact.get('name')) - ))); - export const reduceEmoji = (emojiReacts: ImmutableList, favouritesCount: number, favourited: boolean, allowedEmoji = ALLOWED_EMOJI): ImmutableList => ( - filterEmoji(sortEmoji(mergeEmoji(mergeEmojiFavourites( - emojiReacts, favouritesCount, favourited, - ))), allowedEmoji)); + sortEmoji( + mergeEmojiFavourites(emojiReacts, favouritesCount, favourited), + allowedEmoji, + )); export const getReactForStatus = (status: any, allowedEmoji = ALLOWED_EMOJI): string | undefined => { const result = reduceEmoji(