From 9c6119606fc521e04ae9b7b6859f23c89a42d191 Mon Sep 17 00:00:00 2001 From: Robert Pintilii Date: Mon, 26 Sep 2022 12:54:22 +0300 Subject: [PATCH] ref(chat) Convert some files to TS (#12238) --- react/features/base/conference/reducer.ts | 2 ++ .../chat/{actions.any.js => actions.any.ts} | 25 +++++++------- .../{actions.native.js => actions.native.ts} | 2 -- .../chat/{actions.web.js => actions.web.ts} | 14 ++++---- .../chat/{functions.js => functions.ts} | 34 +++++++++++-------- .../features/chat/{smileys.js => smileys.ts} | 0 react/features/chat/{sounds.js => sounds.ts} | 0 7 files changed, 40 insertions(+), 37 deletions(-) rename react/features/chat/{actions.any.js => actions.any.ts} (89%) rename react/features/chat/{actions.native.js => actions.native.ts} (97%) rename react/features/chat/{actions.web.js => actions.web.ts} (81%) rename react/features/chat/{functions.js => functions.ts} (82%) rename react/features/chat/{smileys.js => smileys.ts} (100%) rename react/features/chat/{sounds.js => sounds.ts} (100%) diff --git a/react/features/base/conference/reducer.ts b/react/features/base/conference/reducer.ts index 835b1a7e8..0acd20113 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 697a7b69b..15d3485d0 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, 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, 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 8b9d0a657..b803e755f 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 9bfd42f4c..e0ea8d66a 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, 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 6a0e0b0e2..4b5d9ae05 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> = []; +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> = []; * on web too once we drop support for browsers that don't support * unicode emoji rendering. */ -const SLACK_EMOJI_REGEXP_ARRAY: Array> = []; +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> = []; 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> = []; ? `(?=(${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