Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

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

Robert Pintilii9c6119606fc5
diff --git a/react/features/base/conference/reducer.ts b/react/features/base/conference/reducer.ts
index 835b1a7e83..0acd20113f 100644
--- a/react/features/base/conference/reducer.ts
+++ b/react/features/base/conference/reducer.ts
@@ -50,11 +50,13 @@ export interface IJitsiConference {
isLobbySupported: Function;
kickParticipant: Function;
muteParticipant: Function;
+ myLobbyUserId: Function;
on: Function;
removeTrack: Function;
replaceTrack: Function;
sendCommand: Function;
sendEndpointMessage: Function;
+ sendLobbyMessage: Function;
sessionId: string;
setDisplayName: Function;
setLocalParticipantProperty: Function;
diff --git a/react/features/chat/actions.any.js b/react/features/chat/actions.any.ts
similarity index 89%
rename from react/features/chat/actions.any.js
rename to react/features/chat/actions.any.ts
index 697a7b69bc..15d3485d0a 100644
--- a/react/features/chat/actions.any.js
+++ b/react/features/chat/actions.any.ts
@@ -1,8 +1,7 @@
-// @flow
-import { type Dispatch } from 'redux';
-
-import { getCurrentConference } from '../base/conference';
-import { getLocalParticipant } from '../base/participants';
+import { IStore } from '../app/types';
+import { getCurrentConference } from '../base/conference/functions';
+import { getLocalParticipant } from '../base/participants/functions';
+import { Participant } from '../base/participants/types';
import { LOBBY_CHAT_INITIALIZED } from '../lobby/constants';
import {
@@ -104,7 +103,7 @@ export function closeChat() {
* message: string
* }}
*/
-export function sendMessage(message: string, ignorePrivacy: boolean = false) {
+export function sendMessage(message: string, ignorePrivacy = false) {
return {
type: SEND_MESSAGE,
ignorePrivacy,
@@ -149,8 +148,8 @@ export function setIsPollsTabFocused(isPollsTabFocused: boolean) {
*
* @returns {Function}
*/
-export function onLobbyChatInitialized(lobbyChatInitializedInfo: Object) {
- return async (dispatch: Dispatch<any>, getState: Function) => {
+export function onLobbyChatInitialized(lobbyChatInitializedInfo: { attendee: Participant; moderator: Participant; }) {
+ return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const state = getState();
const conference = getCurrentConference(state);
@@ -200,7 +199,7 @@ export function setLobbyChatActiveState(value: boolean) {
*
* @returns {Object}
*/
-export function removeLobbyChatParticipant(removeLobbyChatMessages: ?boolean) {
+export function removeLobbyChatParticipant(removeLobbyChatMessages?: boolean) {
return {
type: REMOVE_LOBBY_CHAT_PARTICIPANT,
removeLobbyChatMessages
@@ -216,7 +215,7 @@ export function removeLobbyChatParticipant(removeLobbyChatMessages: ?boolean) {
* @returns {Object}
*/
export function handleLobbyChatInitialized(participantId: string) {
- return async (dispatch: Dispatch<any>, getState: Function) => {
+ return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
if (!participantId) {
return;
}
@@ -225,7 +224,7 @@ export function handleLobbyChatInitialized(participantId: string) {
const { knockingParticipants } = state['features/lobby'];
const { lobbyMessageRecipient } = state['features/chat'];
const me = getLocalParticipant(state);
- const lobbyLocalId = conference.myLobbyUserId();
+ const lobbyLocalId = conference?.myLobbyUserId();
if (lobbyMessageRecipient && lobbyMessageRecipient.id === participantId) {
@@ -255,9 +254,9 @@ export function handleLobbyChatInitialized(participantId: string) {
attendee };
// notify attendee privately.
- conference.sendLobbyMessage(payload, attendee.id);
+ conference?.sendLobbyMessage(payload, attendee.id);
// notify other moderators.
- return conference.sendLobbyMessage(payload);
+ return conference?.sendLobbyMessage(payload);
};
}
diff --git a/react/features/chat/actions.native.js b/react/features/chat/actions.native.ts
similarity index 97%
rename from react/features/chat/actions.native.js
rename to react/features/chat/actions.native.ts
index 8b9d0a657b..b803e755f3 100644
--- a/react/features/chat/actions.native.js
+++ b/react/features/chat/actions.native.ts
@@ -1,5 +1,3 @@
-// @flow
-
import { OPEN_CHAT } from './actionTypes';
export * from './actions.any';
diff --git a/react/features/chat/actions.web.js b/react/features/chat/actions.web.ts
similarity index 81%
rename from react/features/chat/actions.web.js
rename to react/features/chat/actions.web.ts
index 9bfd42f4c1..e0ea8d66a1 100644
--- a/react/features/chat/actions.web.js
+++ b/react/features/chat/actions.web.ts
@@ -1,8 +1,6 @@
-// @flow
-
-import type { Dispatch } from 'redux';
-
+// @ts-ignore
import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
+import { IStore } from '../app/types';
import { getParticipantById } from '../base/participants/functions';
import { OPEN_CHAT } from './actionTypes';
@@ -19,8 +17,8 @@ export * from './actions.any';
* type: OPEN_CHAT
* }}
*/
-export function openChat(participant: Object) {
- return function(dispatch: (Object) => Object) {
+export function openChat(participant?: Object) {
+ return function(dispatch: IStore['dispatch']) {
dispatch({
participant,
type: OPEN_CHAT
@@ -38,7 +36,7 @@ export function openChat(participant: Object) {
* }}
*/
export function openChatById(id: string) {
- return function(dispatch: (Object) => Object, getState: Function) {
+ return function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
const participant = getParticipantById(getState(), id);
return dispatch({
@@ -55,7 +53,7 @@ export function openChatById(id: string) {
* @returns {Function}
*/
export function toggleChat() {
- return (dispatch: Dispatch<any>, getState: Function) => {
+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const isOpen = getState()['features/chat'].isOpen;
if (isOpen) {
diff --git a/react/features/chat/functions.js b/react/features/chat/functions.ts
similarity index 82%
rename from react/features/chat/functions.js
rename to react/features/chat/functions.ts
index 6a0e0b0e25..4b5d9ae058 100644
--- a/react/features/chat/functions.js
+++ b/react/features/chat/functions.ts
@@ -1,9 +1,11 @@
-// @flow
-
+// @ts-ignore
import aliases from 'react-emoji-render/data/aliases';
+// eslint-disable-next-line lines-around-comment
+// @ts-ignore
import emojiAsciiAliases from 'react-emoji-render/data/asciiAliases';
-import { escapeRegexp } from '../base/util';
+import { IState } from '../app/types';
+import { escapeRegexp } from '../base/util/helpers';
/**
* An ASCII emoticon regexp array to find and replace old-style ASCII
@@ -15,7 +17,7 @@ import { escapeRegexp } from '../base/util';
* on web too once we drop support for browsers that don't support
* unicode emoji rendering.
*/
-const ASCII_EMOTICON_REGEXP_ARRAY: Array<Array<Object>> = [];
+const ASCII_EMOTICON_REGEXP_ARRAY: Array<[RegExp, string]> = [];
/**
* An emoji regexp array to find and replace alias emoticons
@@ -27,7 +29,7 @@ const ASCII_EMOTICON_REGEXP_ARRAY: Array<Array<Object>> = [];
* on web too once we drop support for browsers that don't support
* unicode emoji rendering.
*/
-const SLACK_EMOJI_REGEXP_ARRAY: Array<Array<Object>> = [];
+const SLACK_EMOJI_REGEXP_ARRAY: Array<[RegExp, string]> = [];
(function() {
for (const [ key, value ] of Object.entries(aliases)) {
@@ -36,7 +38,7 @@ const SLACK_EMOJI_REGEXP_ARRAY: Array<Array<Object>> = [];
const asciiEmoticons = emojiAsciiAliases[key];
if (asciiEmoticons) {
- const asciiEscapedValues = asciiEmoticons.map(v => escapeRegexp(v));
+ const asciiEscapedValues = asciiEmoticons.map((v: string) => escapeRegexp(v));
const asciiRegexp = `(${asciiEscapedValues.join('|')})`;
@@ -45,13 +47,13 @@ const SLACK_EMOJI_REGEXP_ARRAY: Array<Array<Object>> = [];
? `(?=(${asciiRegexp}))(:(?!//).)`
: asciiRegexp;
- ASCII_EMOTICON_REGEXP_ARRAY.push([ new RegExp(formattedAsciiRegexp, 'g'), value ]);
+ ASCII_EMOTICON_REGEXP_ARRAY.push([ new RegExp(formattedAsciiRegexp, 'g'), value as string ]);
}
// Add slack-type emojis
const emojiRegexp = `\\B(${escapeRegexp(`:${key}:`)})\\B`;
- SLACK_EMOJI_REGEXP_ARRAY.push([ new RegExp(emojiRegexp, 'g'), value ]);
+ SLACK_EMOJI_REGEXP_ARRAY.push([ new RegExp(emojiRegexp, 'g'), value as string ]);
}
})();
@@ -79,10 +81,10 @@ export function replaceNonUnicodeEmojis(message: string) {
/**
* Selector for calculating the number of unread chat messages.
*
- * @param {Object} state - The redux state.
+ * @param {IState} state - The redux state.
* @returns {number} The number of unread messages.
*/
-export function getUnreadCount(state: Object) {
+export function getUnreadCount(state: IState) {
const { lastReadMessage, messages } = state['features/chat'];
const messagesCount = messages.length;
@@ -92,6 +94,10 @@ export function getUnreadCount(state: Object) {
let reactionMessages = 0;
+ if (!lastReadMessage) {
+ return 0;
+ }
+
if (navigator.product === 'ReactNative') {
// React native stores the messages in a reversed order.
const lastReadIndex = messages.indexOf(lastReadMessage);
@@ -119,10 +125,10 @@ export function getUnreadCount(state: Object) {
/**
* Selector for calculating the number of unread chat messages.
*
- * @param {Object} state - The redux state.
+ * @param {IState} state - The redux state.
* @returns {number} The number of unread messages.
*/
-export function getUnreadMessagesCount(state: Object) {
+export function getUnreadMessagesCount(state: IState) {
const { nbUnreadMessages } = state['features/chat'];
return nbUnreadMessages;
@@ -131,10 +137,10 @@ export function getUnreadMessagesCount(state: Object) {
/**
* Get whether the chat smileys are disabled or not.
*
- * @param {Object} state - The redux state.
+ * @param {IState} state - The redux state.
* @returns {boolean} The disabled flag.
*/
-export function areSmileysDisabled(state: Object) {
+export function areSmileysDisabled(state: IState) {
const disableChatSmileys = state['features/base/config']?.disableChatSmileys === true;
return disableChatSmileys;
diff --git a/react/features/chat/smileys.js b/react/features/chat/smileys.ts
similarity index 100%
rename from react/features/chat/smileys.js
rename to react/features/chat/smileys.ts
diff --git a/react/features/chat/sounds.js b/react/features/chat/sounds.ts
similarity index 100%
rename from react/features/chat/sounds.js
rename to react/features/chat/sounds.ts