|
|
@@ -1,9 +1,11 @@
|
|
1
|
|
-// @flow
|
|
2
|
|
-
|
|
|
1
|
+// @ts-ignore
|
|
3
|
2
|
import aliases from 'react-emoji-render/data/aliases';
|
|
|
3
|
+// eslint-disable-next-line lines-around-comment
|
|
|
4
|
+// @ts-ignore
|
|
4
|
5
|
import emojiAsciiAliases from 'react-emoji-render/data/asciiAliases';
|
|
5
|
6
|
|
|
6
|
|
-import { escapeRegexp } from '../base/util';
|
|
|
7
|
+import { IState } from '../app/types';
|
|
|
8
|
+import { escapeRegexp } from '../base/util/helpers';
|
|
7
|
9
|
|
|
8
|
10
|
/**
|
|
9
|
11
|
* An ASCII emoticon regexp array to find and replace old-style ASCII
|
|
|
@@ -15,7 +17,7 @@ import { escapeRegexp } from '../base/util';
|
|
15
|
17
|
* on web too once we drop support for browsers that don't support
|
|
16
|
18
|
* unicode emoji rendering.
|
|
17
|
19
|
*/
|
|
18
|
|
-const ASCII_EMOTICON_REGEXP_ARRAY: Array<Array<Object>> = [];
|
|
|
20
|
+const ASCII_EMOTICON_REGEXP_ARRAY: Array<[RegExp, string]> = [];
|
|
19
|
21
|
|
|
20
|
22
|
/**
|
|
21
|
23
|
* An emoji regexp array to find and replace alias emoticons
|
|
|
@@ -27,7 +29,7 @@ const ASCII_EMOTICON_REGEXP_ARRAY: Array<Array<Object>> = [];
|
|
27
|
29
|
* on web too once we drop support for browsers that don't support
|
|
28
|
30
|
* unicode emoji rendering.
|
|
29
|
31
|
*/
|
|
30
|
|
-const SLACK_EMOJI_REGEXP_ARRAY: Array<Array<Object>> = [];
|
|
|
32
|
+const SLACK_EMOJI_REGEXP_ARRAY: Array<[RegExp, string]> = [];
|
|
31
|
33
|
|
|
32
|
34
|
(function() {
|
|
33
|
35
|
for (const [ key, value ] of Object.entries(aliases)) {
|
|
|
@@ -36,7 +38,7 @@ const SLACK_EMOJI_REGEXP_ARRAY: Array<Array<Object>> = [];
|
|
36
|
38
|
const asciiEmoticons = emojiAsciiAliases[key];
|
|
37
|
39
|
|
|
38
|
40
|
if (asciiEmoticons) {
|
|
39
|
|
- const asciiEscapedValues = asciiEmoticons.map(v => escapeRegexp(v));
|
|
|
41
|
+ const asciiEscapedValues = asciiEmoticons.map((v: string) => escapeRegexp(v));
|
|
40
|
42
|
|
|
41
|
43
|
const asciiRegexp = `(${asciiEscapedValues.join('|')})`;
|
|
42
|
44
|
|
|
|
@@ -45,13 +47,13 @@ const SLACK_EMOJI_REGEXP_ARRAY: Array<Array<Object>> = [];
|
|
45
|
47
|
? `(?=(${asciiRegexp}))(:(?!//).)`
|
|
46
|
48
|
: asciiRegexp;
|
|
47
|
49
|
|
|
48
|
|
- ASCII_EMOTICON_REGEXP_ARRAY.push([ new RegExp(formattedAsciiRegexp, 'g'), value ]);
|
|
|
50
|
+ ASCII_EMOTICON_REGEXP_ARRAY.push([ new RegExp(formattedAsciiRegexp, 'g'), value as string ]);
|
|
49
|
51
|
}
|
|
50
|
52
|
|
|
51
|
53
|
// Add slack-type emojis
|
|
52
|
54
|
const emojiRegexp = `\\B(${escapeRegexp(`:${key}:`)})\\B`;
|
|
53
|
55
|
|
|
54
|
|
- SLACK_EMOJI_REGEXP_ARRAY.push([ new RegExp(emojiRegexp, 'g'), value ]);
|
|
|
56
|
+ SLACK_EMOJI_REGEXP_ARRAY.push([ new RegExp(emojiRegexp, 'g'), value as string ]);
|
|
55
|
57
|
}
|
|
56
|
58
|
})();
|
|
57
|
59
|
|
|
|
@@ -79,10 +81,10 @@ export function replaceNonUnicodeEmojis(message: string) {
|
|
79
|
81
|
/**
|
|
80
|
82
|
* Selector for calculating the number of unread chat messages.
|
|
81
|
83
|
*
|
|
82
|
|
- * @param {Object} state - The redux state.
|
|
|
84
|
+ * @param {IState} state - The redux state.
|
|
83
|
85
|
* @returns {number} The number of unread messages.
|
|
84
|
86
|
*/
|
|
85
|
|
-export function getUnreadCount(state: Object) {
|
|
|
87
|
+export function getUnreadCount(state: IState) {
|
|
86
|
88
|
const { lastReadMessage, messages } = state['features/chat'];
|
|
87
|
89
|
const messagesCount = messages.length;
|
|
88
|
90
|
|
|
|
@@ -92,6 +94,10 @@ export function getUnreadCount(state: Object) {
|
|
92
|
94
|
|
|
93
|
95
|
let reactionMessages = 0;
|
|
94
|
96
|
|
|
|
97
|
+ if (!lastReadMessage) {
|
|
|
98
|
+ return 0;
|
|
|
99
|
+ }
|
|
|
100
|
+
|
|
95
|
101
|
if (navigator.product === 'ReactNative') {
|
|
96
|
102
|
// React native stores the messages in a reversed order.
|
|
97
|
103
|
const lastReadIndex = messages.indexOf(lastReadMessage);
|
|
|
@@ -119,10 +125,10 @@ export function getUnreadCount(state: Object) {
|
|
119
|
125
|
/**
|
|
120
|
126
|
* Selector for calculating the number of unread chat messages.
|
|
121
|
127
|
*
|
|
122
|
|
- * @param {Object} state - The redux state.
|
|
|
128
|
+ * @param {IState} state - The redux state.
|
|
123
|
129
|
* @returns {number} The number of unread messages.
|
|
124
|
130
|
*/
|
|
125
|
|
-export function getUnreadMessagesCount(state: Object) {
|
|
|
131
|
+export function getUnreadMessagesCount(state: IState) {
|
|
126
|
132
|
const { nbUnreadMessages } = state['features/chat'];
|
|
127
|
133
|
|
|
128
|
134
|
return nbUnreadMessages;
|
|
|
@@ -131,10 +137,10 @@ export function getUnreadMessagesCount(state: Object) {
|
|
131
|
137
|
/**
|
|
132
|
138
|
* Get whether the chat smileys are disabled or not.
|
|
133
|
139
|
*
|
|
134
|
|
- * @param {Object} state - The redux state.
|
|
|
140
|
+ * @param {IState} state - The redux state.
|
|
135
|
141
|
* @returns {boolean} The disabled flag.
|
|
136
|
142
|
*/
|
|
137
|
|
-export function areSmileysDisabled(state: Object) {
|
|
|
143
|
+export function areSmileysDisabled(state: IState) {
|
|
138
|
144
|
const disableChatSmileys = state['features/base/config']?.disableChatSmileys === true;
|
|
139
|
145
|
|
|
140
|
146
|
return disableChatSmileys;
|