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

This commit is contained in:
Robert Pintilii 2022-09-26 12:54:22 +03:00 committed by GitHub
parent 077afecdba
commit 9c6119606f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 37 deletions

View File

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

View File

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

View File

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

View File

@ -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) {

View File

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