Skip to content

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

types(chat): narrow IMessage.messageType using literal union types

Nitin Kumard93b1c21958d
diff --git a/react/features/chat/actionTypes.ts b/react/features/chat/actionTypes.ts
index 1e6d3e562c..3bc8cb601f 100644
--- a/react/features/chat/actionTypes.ts
+++ b/react/features/chat/actionTypes.ts
@@ -6,7 +6,7 @@
* displayName: string
* hasRead: boolean,
* id: string,
- * messageType: string,
+ * messageType: ChatMessageType,
* message: string,
* timestamp: string,
* }
diff --git a/react/features/chat/actions.any.ts b/react/features/chat/actions.any.ts
index dda4bac8cd..5b8800d8c6 100644
--- a/react/features/chat/actions.any.ts
+++ b/react/features/chat/actions.any.ts
@@ -42,7 +42,7 @@ import { ChatTabs } from './constants';
* displayName: string,
* hasRead: boolean,
* message: string,
- * messageType: string,
+ * messageType: ChatMessageType,
* timestamp: string,
* isReaction: boolean
* }}
diff --git a/react/features/chat/constants.ts b/react/features/chat/constants.ts
index f222267531..cb3eac50c4 100644
--- a/react/features/chat/constants.ts
+++ b/react/features/chat/constants.ts
@@ -19,17 +19,17 @@ export const INCOMING_MSG_SOUND_ID = 'INCOMING_MSG_SOUND';
/**
* The {@code messageType} of error (system) messages.
*/
-export const MESSAGE_TYPE_ERROR = 'error';
+export const MESSAGE_TYPE_ERROR = 'error' as const;
/**
* The {@code messageType} of local messages.
*/
-export const MESSAGE_TYPE_LOCAL = 'local';
+export const MESSAGE_TYPE_LOCAL = 'local' as const;
/**
* The {@code messageType} of remote messages.
*/
-export const MESSAGE_TYPE_REMOTE = 'remote';
+export const MESSAGE_TYPE_REMOTE = 'remote' as const;
export const SMALL_WIDTH_THRESHOLD = 580;
diff --git a/react/features/chat/types.ts b/react/features/chat/types.ts
index 6e3a74965c..4a380900c6 100644
--- a/react/features/chat/types.ts
+++ b/react/features/chat/types.ts
@@ -3,9 +3,20 @@ import { WithTranslation } from 'react-i18next';
import { IStore } from '../app/types';
import { IFileMetadata } from '../file-sharing/types';
+import {
+ MESSAGE_TYPE_ERROR,
+ MESSAGE_TYPE_LOCAL,
+ MESSAGE_TYPE_REMOTE
+} from './constants';
+
+export type ChatMessageType =
+ | typeof MESSAGE_TYPE_LOCAL
+ | typeof MESSAGE_TYPE_ERROR
+ | typeof MESSAGE_TYPE_REMOTE;
+
export interface IMessage {
displayName: string;
- error?: Object;
+ error?: unknown;
fileMetadata?: IFileMetadata;
isFromGuest?: boolean;
isFromVisitor?: boolean;
@@ -13,7 +24,7 @@ export interface IMessage {
lobbyChat: boolean;
message: string;
messageId: string;
- messageType: string;
+ messageType: ChatMessageType;
participantId: string;
privateMessage: boolean;
reactions: Map<string, Set<string>>;