Implement getReactForStatus(), start oneEmojiPerAccount()

merge-requests/18/head
Alex Gleason 2020-05-21 23:52:10 -05:00
rodzic 0e5971545f
commit 792ca08d03
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 24 dodań i 9 usunięć

Wyświetl plik

@ -121,14 +121,14 @@ describe('oneEmojiPerAccount', () => {
it('reduces to one react per account', () => {
const emojiReacts = fromJS([
// Sorted
{ 'count': 20, 'me': true, 'name': '👍', accounts: [{ id: '1' }, { id: '2' }] },
{ 'count': 15, 'me': true, 'name': '❤', accounts: [{ id: '1' }, { id: '2' }] },
{ 'count': 7, 'me': true, 'name': '😯', accounts: [{ id: '1' }] },
{ 'count': 7, 'me': false, 'name': '😂', accounts: [{ id: '3' }] },
{ 'count': 2, 'me': true, 'name': '👍', accounts: [{ id: '1' }, { id: '2' }] },
{ 'count': 2, 'me': true, 'name': '❤', accounts: [{ id: '1' }, { id: '2' }] },
{ 'count': 1, 'me': true, 'name': '😯', accounts: [{ id: '1' }] },
{ 'count': 1, 'me': false, 'name': '😂', accounts: [{ id: '3' }] },
]);
expect(oneEmojiPerAccount(emojiReacts)).toEqual(fromJS([
{ 'count': 20, 'me': true, 'name': '👍', accounts: [{ id: '1' }, { id: '2' }] },
{ 'count': 7, 'me': false, 'name': '😂', accounts: [{ id: '3' }] },
{ 'count': 2, 'me': true, 'name': '👍', accounts: [{ id: '1' }, { id: '2' }] },
{ 'count': 1, 'me': false, 'name': '😂', accounts: [{ id: '3' }] },
]));
});
});

Wyświetl plik

@ -1,4 +1,7 @@
import { Map as ImmutableMap } from 'immutable';
import {
Map as ImmutableMap,
List as ImmutableList,
} from 'immutable';
// https://emojipedia.org/facebook/
export const ALLOWED_EMOJI = [
@ -31,7 +34,13 @@ export const mergeEmojiFavourites = (emojiReacts, favouritesCount) => {
};
export const oneEmojiPerAccount = emojiReacts => {
return; // TODO
emojiReacts = emojiReacts.reverse();
return emojiReacts.reduce((acc, cur) => {
if (acc.filter(
e => e.get('me') && e.get('name') !== cur.get('name')
).length > 0) return acc.delete(cur); // FIXME: Incomplete
return acc;
}, emojiReacts).reverse();
};
export const filterEmoji = emojiReacts => (
@ -45,5 +54,11 @@ export const reduceEmoji = (emojiReacts, favouritesCount) => (
)))));
export const getReactForStatus = status => {
return; // TODO
const emojiReacts = status.getIn(['pleroma', 'emoji_reactions'], ImmutableList());
const emojiReact = emojiReacts.reduce((acc, cur) => {
if (acc) return acc;
if (cur.get('me') === true) return cur.get('name');
return acc;
}, false);
return emojiReact ? emojiReact : status.get('favourited') && '👍';
};