This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
emoji_actions.jsx
74 lines (57 loc) · 2.02 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
67
68
69
70
71
72
73
74
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as EmojiActions from 'mattermost-redux/actions/emojis';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {setRecentEmojis} from 'actions/local_storage';
import {getEmojiMap, getRecentEmojis} from 'selectors/emojis';
import {ActionTypes} from 'utils/constants';
export function loadRecentlyUsedCustomEmojis() {
return async (dispatch, getState) => {
const state = getState();
const config = getConfig(state);
if (config.EnableCustomEmoji !== 'true') {
return {data: true};
}
const recentEmojis = getRecentEmojis(state);
const emojiMap = getEmojiMap(state);
const missingEmojis = recentEmojis.filter((name) => !emojiMap.has(name));
missingEmojis.forEach((name) => {
dispatch(EmojiActions.getCustomEmojiByName(name));
});
return {data: true};
};
}
export function incrementEmojiPickerPage() {
return async (dispatch) => {
dispatch({
type: ActionTypes.INCREMENT_EMOJI_PICKER_PAGE,
});
return {data: true};
};
}
const MAXIMUM_RECENT_EMOJI = 27;
export function addRecentEmoji(alias) {
return (dispatch, getState) => {
const state = getState();
const recentEmojis = getRecentEmojis(state);
const emojiMap = getEmojiMap(state);
let name;
const emoji = emojiMap.get(alias);
if (!emoji) {
return;
} else if (emoji.name) {
name = emoji.name;
} else {
name = emoji.aliases[0];
}
const index = recentEmojis.indexOf(name);
if (index !== -1) {
recentEmojis.splice(index, 1);
}
recentEmojis.push(name);
if (recentEmojis.length > MAXIMUM_RECENT_EMOJI) {
recentEmojis.splice(0, recentEmojis.length - MAXIMUM_RECENT_EMOJI);
}
dispatch(setRecentEmojis(recentEmojis));
};
}