Implement getReactForStatus(), start oneEmojiPerAccount()
This commit is contained in:
parent
0e5971545f
commit
792ca08d03
2 changed files with 24 additions and 9 deletions
|
@ -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' }] },
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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') && '👍';
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue