/* @flow */
import { createSelector } from 'reselect';
import { getRawRealmEmoji } from '../directSelectors';
import { getAuth } from '../account/accountSelectors';
import { getFullUrl } from '../utils/url';

export const getAllRealmEmojiById = createSelector(getAuth, getRawRealmEmoji, (auth, emojis) =>
  Object.keys(emojis).reduce((list, key) => {
    list[key] = { ...emojis[key], source_url: getFullUrl(emojis[key].source_url, auth.realm) };
    return list;
  }, {}),
);

export const getActiveRealmEmojiById = createSelector(getAllRealmEmojiById, emojis =>
  Object.keys(emojis)
    .filter(emoji => !emojis[emoji].deactivated)
    .reduce((list, key) => {
      list[key] = emojis[key];
      return list;
    }, {}),
);

/* @flow */
import { createSelector } from 'reselect';
import { getRawRealmEmoji } from '../directSelectors';
import { getAuth } from '../account/accountSelectors';
import { getFullUrl } from '../utils/url';

export const getAllRealmEmojiById = createSelector(getAuth, getRawRealmEmoji, (auth, emojis) =>
  Object.keys(emojis).reduce((result, key) => {
    result[key] = { ...emojis[key], source_url: getFullUrl(emojis[key].source_url, auth.realm) };
    return result;
  }, {}),
);

export const getActiveRealmEmojiById = createSelector(getAllRealmEmojiById, emojis =>
  Object.keys(emojis)
    .filter(emoji => !emojis[emoji].deactivated)
    .reduce((result, key) => {
      result[key] = emojis[key];
      return result;
    }, {}),
);

Fix misleading variable name `list` for non-lists.
emoji: Fix misleading variable name `list` for non-lists.

The `Array#reduce` method basically operates on a list... but
these variables are referring to essentially the opposite thing!
The array (or "list") acts as input, but this variable / this
parameter to the inner function is the *output* we're in the
middle of building.

That makes this misnaming super confusing if you don't have the
specifics of the `Array#reduce` signature solid in your head;
and in any event, it's just wrong.  Fix it.
