summaryrefslogtreecommitdiffstats
path: root/webapp/actions/emoji_actions.jsx
blob: 128a9325a1cac9b3e5d9129304383c8de5f3c061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import AppDispatcher from 'dispatcher/app_dispatcher.jsx';

import UserStore from 'stores/user_store.jsx';

import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';

import {ActionTypes} from 'utils/constants.jsx';

export function loadEmoji(getProfiles = true) {
    Client.listEmoji(
        (data) => {
            AppDispatcher.handleServerAction({
                type: ActionTypes.RECEIVED_CUSTOM_EMOJIS,
                emojis: data
            });

            if (getProfiles) {
                loadProfilesForEmoji(data);
            }
        },
        (err) => {
            AsyncClient.dispatchError(err, 'listEmoji');
        }
    );
}

function loadProfilesForEmoji(emojiList) {
    const profilesToLoad = {};
    for (let i = 0; i < emojiList.length; i++) {
        const emoji = emojiList[i];
        if (!UserStore.hasProfile(emoji.creator_id)) {
            profilesToLoad[emoji.creator_id] = true;
        }
    }

    const list = Object.keys(profilesToLoad);
    if (list.length === 0) {
        return;
    }

    AsyncClient.getProfilesByIds(list);
}