forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji_actions.jsx
66 lines (53 loc) · 2 KB
/
emoji_actions.jsx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import * as EmojiActions from 'mattermost-redux/actions/emojis';
import {getEmojiMap} from 'selectors/emojis';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import store from 'stores/redux_store.jsx';
import EmojiStore from 'stores/emoji_store.jsx';
import {ActionTypes} from 'utils/constants.jsx';
export async function addEmoji(emoji, image, success, error) {
const {data, error: err} = await EmojiActions.createCustomEmoji(emoji, image)(store.dispatch, store.getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function deleteEmoji(emojiId, success, error) {
const {data, error: err} = await EmojiActions.deleteCustomEmoji(emojiId)(store.dispatch, store.getState);
if (data) {
// Needed to remove recently used emoji
AppDispatcher.handleServerAction({
type: ActionTypes.REMOVED_CUSTOM_EMOJI,
id: emojiId,
});
if (success) {
success(data);
}
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function loadRecentlyUsedCustomEmojis() {
return async (dispatch, getState) => {
if (getState().entities.general.config.EnableCustomEmoji !== 'true') {
return {data: true};
}
const recentEmojis = EmojiStore.getRecentEmojis();
const emojiMap = getEmojiMap(getState());
const missingEmojis = recentEmojis.filter((name) => !emojiMap.has(name));
missingEmojis.forEach((name) => {
EmojiActions.getCustomEmojiByName(name)(dispatch, getState);
});
return {data: true};
};
}
export function incrementEmojiPickerPage() {
return async (dispatch) => {
dispatch({
type: ActionTypes.INCREMENT_EMOJI_PICKER_PAGE,
});
return {data: true};
};
}