Просмотр исходного кода

ref(chat) Convert some files to TS (#12238)

factor2
Robert Pintilii 3 лет назад
Родитель
Сommit
9c6119606f
Аккаунт пользователя с таким Email не найден

+ 2
- 0
react/features/base/conference/reducer.ts Просмотреть файл

@@ -50,11 +50,13 @@ export interface IJitsiConference {
50 50
     isLobbySupported: Function;
51 51
     kickParticipant: Function;
52 52
     muteParticipant: Function;
53
+    myLobbyUserId: Function;
53 54
     on: Function;
54 55
     removeTrack: Function;
55 56
     replaceTrack: Function;
56 57
     sendCommand: Function;
57 58
     sendEndpointMessage: Function;
59
+    sendLobbyMessage: Function;
58 60
     sessionId: string;
59 61
     setDisplayName: Function;
60 62
     setLocalParticipantProperty: Function;

react/features/chat/actions.any.js → react/features/chat/actions.any.ts Просмотреть файл

@@ -1,8 +1,7 @@
1
-// @flow
2
-import { type Dispatch } from 'redux';
3
-
4
-import { getCurrentConference } from '../base/conference';
5
-import { getLocalParticipant } from '../base/participants';
1
+import { IStore } from '../app/types';
2
+import { getCurrentConference } from '../base/conference/functions';
3
+import { getLocalParticipant } from '../base/participants/functions';
4
+import { Participant } from '../base/participants/types';
6 5
 import { LOBBY_CHAT_INITIALIZED } from '../lobby/constants';
7 6
 
8 7
 import {
@@ -104,7 +103,7 @@ export function closeChat() {
104 103
  *     message: string
105 104
  * }}
106 105
  */
107
-export function sendMessage(message: string, ignorePrivacy: boolean = false) {
106
+export function sendMessage(message: string, ignorePrivacy = false) {
108 107
     return {
109 108
         type: SEND_MESSAGE,
110 109
         ignorePrivacy,
@@ -149,8 +148,8 @@ export function setIsPollsTabFocused(isPollsTabFocused: boolean) {
149 148
  *
150 149
  * @returns {Function}
151 150
  */
152
-export function onLobbyChatInitialized(lobbyChatInitializedInfo: Object) {
153
-    return async (dispatch: Dispatch<any>, getState: Function) => {
151
+export function onLobbyChatInitialized(lobbyChatInitializedInfo: { attendee: Participant; moderator: Participant; }) {
152
+    return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
154 153
         const state = getState();
155 154
         const conference = getCurrentConference(state);
156 155
 
@@ -200,7 +199,7 @@ export function setLobbyChatActiveState(value: boolean) {
200 199
  *
201 200
  * @returns {Object}
202 201
  */
203
-export function removeLobbyChatParticipant(removeLobbyChatMessages: ?boolean) {
202
+export function removeLobbyChatParticipant(removeLobbyChatMessages?: boolean) {
204 203
     return {
205 204
         type: REMOVE_LOBBY_CHAT_PARTICIPANT,
206 205
         removeLobbyChatMessages
@@ -216,7 +215,7 @@ export function removeLobbyChatParticipant(removeLobbyChatMessages: ?boolean) {
216 215
  * @returns {Object}
217 216
  */
218 217
 export function handleLobbyChatInitialized(participantId: string) {
219
-    return async (dispatch: Dispatch<any>, getState: Function) => {
218
+    return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
220 219
         if (!participantId) {
221 220
             return;
222 221
         }
@@ -225,7 +224,7 @@ export function handleLobbyChatInitialized(participantId: string) {
225 224
         const { knockingParticipants } = state['features/lobby'];
226 225
         const { lobbyMessageRecipient } = state['features/chat'];
227 226
         const me = getLocalParticipant(state);
228
-        const lobbyLocalId = conference.myLobbyUserId();
227
+        const lobbyLocalId = conference?.myLobbyUserId();
229 228
 
230 229
 
231 230
         if (lobbyMessageRecipient && lobbyMessageRecipient.id === participantId) {
@@ -255,9 +254,9 @@ export function handleLobbyChatInitialized(participantId: string) {
255 254
             attendee };
256 255
 
257 256
         // notify attendee privately.
258
-        conference.sendLobbyMessage(payload, attendee.id);
257
+        conference?.sendLobbyMessage(payload, attendee.id);
259 258
 
260 259
         // notify other moderators.
261
-        return conference.sendLobbyMessage(payload);
260
+        return conference?.sendLobbyMessage(payload);
262 261
     };
263 262
 }

react/features/chat/actions.native.js → react/features/chat/actions.native.ts Просмотреть файл

@@ -1,5 +1,3 @@
1
-// @flow
2
-
3 1
 import { OPEN_CHAT } from './actionTypes';
4 2
 
5 3
 export * from './actions.any';

react/features/chat/actions.web.js → react/features/chat/actions.web.ts Просмотреть файл

@@ -1,8 +1,6 @@
1
-// @flow
2
-
3
-import type { Dispatch } from 'redux';
4
-
1
+// @ts-ignore
5 2
 import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
3
+import { IStore } from '../app/types';
6 4
 import { getParticipantById } from '../base/participants/functions';
7 5
 
8 6
 import { OPEN_CHAT } from './actionTypes';
@@ -19,8 +17,8 @@ export * from './actions.any';
19 17
  *     type: OPEN_CHAT
20 18
  * }}
21 19
  */
22
-export function openChat(participant: Object) {
23
-    return function(dispatch: (Object) => Object) {
20
+export function openChat(participant?: Object) {
21
+    return function(dispatch: IStore['dispatch']) {
24 22
         dispatch({
25 23
             participant,
26 24
             type: OPEN_CHAT
@@ -38,7 +36,7 @@ export function openChat(participant: Object) {
38 36
  * }}
39 37
  */
40 38
 export function openChatById(id: string) {
41
-    return function(dispatch: (Object) => Object, getState: Function) {
39
+    return function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
42 40
         const participant = getParticipantById(getState(), id);
43 41
 
44 42
         return dispatch({
@@ -55,7 +53,7 @@ export function openChatById(id: string) {
55 53
  * @returns {Function}
56 54
  */
57 55
 export function toggleChat() {
58
-    return (dispatch: Dispatch<any>, getState: Function) => {
56
+    return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
59 57
         const isOpen = getState()['features/chat'].isOpen;
60 58
 
61 59
         if (isOpen) {

react/features/chat/functions.js → react/features/chat/functions.ts Просмотреть файл

@@ -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;

react/features/chat/smileys.js → react/features/chat/smileys.ts Просмотреть файл


react/features/chat/sounds.js → react/features/chat/sounds.ts Просмотреть файл


Загрузка…
Отмена
Сохранить