From 08656e3f5daca4a5706692555b30d014c5c51030 Mon Sep 17 00:00:00 2001 From: amolghode1981 <86001342+amolghode1981@users.noreply.github.com> Date: Wed, 1 Jun 2022 20:55:32 +0530 Subject: [PATCH] Chore: Converting files from app/livechat folder from JS to TS (#25658) --- apps/meteor/app/livechat/lib/Assets.js | 2 - apps/meteor/app/livechat/lib/Assets.ts | 4 ++ .../lib/{messageTypes.js => messageTypes.ts} | 56 ++++++++++--------- .../lib/stream/{constants.js => constants.ts} | 0 .../core-typings/src/IMessage/IMessage.ts | 50 ++++++++++++++++- 5 files changed, 83 insertions(+), 29 deletions(-) delete mode 100644 apps/meteor/app/livechat/lib/Assets.js create mode 100644 apps/meteor/app/livechat/lib/Assets.ts rename apps/meteor/app/livechat/lib/{messageTypes.js => messageTypes.ts} (65%) rename apps/meteor/app/livechat/lib/stream/{constants.js => constants.ts} (100%) diff --git a/apps/meteor/app/livechat/lib/Assets.js b/apps/meteor/app/livechat/lib/Assets.js deleted file mode 100644 index 32546c6003be..000000000000 --- a/apps/meteor/app/livechat/lib/Assets.js +++ /dev/null @@ -1,2 +0,0 @@ -export const addServerUrlToIndex = (file) => - file.replace('', ``); diff --git a/apps/meteor/app/livechat/lib/Assets.ts b/apps/meteor/app/livechat/lib/Assets.ts new file mode 100644 index 000000000000..c812cd22a9b3 --- /dev/null +++ b/apps/meteor/app/livechat/lib/Assets.ts @@ -0,0 +1,4 @@ +export const addServerUrlToIndex = (file: string): string => { + const rootUrl = (global as any).__meteor_runtime_config__.ROOT_URL.replace(/\/$/, ''); + return file.replace('', ``); +}; diff --git a/apps/meteor/app/livechat/lib/messageTypes.js b/apps/meteor/app/livechat/lib/messageTypes.ts similarity index 65% rename from apps/meteor/app/livechat/lib/messageTypes.js rename to apps/meteor/app/livechat/lib/messageTypes.ts index 62bf6c8aeaf2..096534d83b9d 100644 --- a/apps/meteor/app/livechat/lib/messageTypes.js +++ b/apps/meteor/app/livechat/lib/messageTypes.ts @@ -2,19 +2,19 @@ import formatDistance from 'date-fns/formatDistance'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import moment from 'moment'; import { escapeHTML } from '@rocket.chat/string-helpers'; +import { IOmnichannelSystemMessage } from '@rocket.chat/core-typings'; -import { MessageTypes } from '../../ui-utils'; +import { MessageTypes } from '../../ui-utils/lib/MessageTypes'; MessageTypes.registerType({ id: 'livechat_navigation_history', system: true, message: 'New_visitor_navigation', - data(message) { - if (!message.navigation || !message.navigation.page) { - return; - } + data(message: IOmnichannelSystemMessage) { return { - history: `${(message.navigation.page.title ? `${message.navigation.page.title} - ` : '') + message.navigation.page.location.href}`, + history: message.navigation + ? `${(message.navigation.page.title ? `${message.navigation.page.title} - ` : '') + message.navigation.page.location.href}` + : '', }; }, }); @@ -23,9 +23,11 @@ MessageTypes.registerType({ id: 'livechat_transfer_history', system: true, message: 'New_chat_transfer', - data(message) { + data(message: IOmnichannelSystemMessage) { if (!message.transferData) { - return; + return { + transfer: '', + }; } const { comment } = message.transferData; @@ -33,20 +35,19 @@ MessageTypes.registerType({ const from = message.transferData.transferredBy && (message.transferData.transferredBy.name || message.transferData.transferredBy.username); const transferTypes = { - agent: () => + agent: (): string => TAPi18n.__(`Livechat_transfer_to_agent${commentLabel}`, { from, - to: - message.transferData.transferredTo && (message.transferData.transferredTo.name || message.transferData.transferredTo.username), + to: message?.transferData?.transferredTo?.name || message?.transferData?.transferredTo?.username || '', ...(comment && { comment }), }), - department: () => + department: (): string => TAPi18n.__(`Livechat_transfer_to_department${commentLabel}`, { from, - to: message.transferData.nextDepartment && message.transferData.nextDepartment.name, + to: message?.transferData?.nextDepartment?.name || '', ...(comment && { comment }), }), - queue: () => + queue: (): string => TAPi18n.__('Livechat_transfer_return_to_the_queue', { from, }), @@ -61,21 +62,23 @@ MessageTypes.registerType({ id: 'livechat_transcript_history', system: true, message: 'Livechat_chat_transcript_sent', - data(message) { + data(message: IOmnichannelSystemMessage) { if (!message.requestData) { - return; + return { + transcript: '', + }; } - const { requestData: { type, visitor = {}, user = {} } = {} } = message; + const { requestData: { type, visitor, user } = { type: 'user' } } = message; const requestTypes = { - visitor: () => + visitor: (): string => TAPi18n.__('Livechat_visitor_transcript_request', { - guest: visitor.name || visitor.username, + guest: visitor?.name || visitor?.username || '', }), - user: () => + user: (): string => TAPi18n.__('Livechat_user_sent_chat_transcript_to_visitor', { - agent: user.name || user.username, - guest: visitor.name || visitor.username, + agent: user?.name || user?.username || '', + guest: visitor?.name || visitor?.username || '', }), }; @@ -105,15 +108,16 @@ MessageTypes.registerType({ } return escapeHTML(message.msg); }, + message: 'room_changed_privacy', }); MessageTypes.registerType({ id: 'omnichannel_placed_chat_on_hold', system: true, message: 'Omnichannel_placed_chat_on_hold', - data(message) { + data(message: IOmnichannelSystemMessage) { return { - comment: message.comment, + comment: message.comment ? message.comment : 'No comment provided', }; }, }); @@ -122,9 +126,9 @@ MessageTypes.registerType({ id: 'omnichannel_on_hold_chat_resumed', system: true, message: 'Omnichannel_on_hold_chat_resumed', - data(message) { + data(message: IOmnichannelSystemMessage) { return { - comment: message.comment, + comment: message.comment ? message.comment : 'No comment provided', }; }, }); diff --git a/apps/meteor/app/livechat/lib/stream/constants.js b/apps/meteor/app/livechat/lib/stream/constants.ts similarity index 100% rename from apps/meteor/app/livechat/lib/stream/constants.js rename to apps/meteor/app/livechat/lib/stream/constants.ts diff --git a/packages/core-typings/src/IMessage/IMessage.ts b/packages/core-typings/src/IMessage/IMessage.ts index f473d4e093a1..4959ae26f23f 100644 --- a/packages/core-typings/src/IMessage/IMessage.ts +++ b/packages/core-typings/src/IMessage/IMessage.ts @@ -7,6 +7,7 @@ import type { IUser } from '../IUser'; import type { IRoom, RoomID } from '../IRoom'; import type { MessageAttachment } from './MessageAttachment/MessageAttachment'; import type { FileProp } from './MessageAttachment/Files/FileProp'; +import type { ILivechatVisitor } from '../ILivechatVisitor'; type MentionType = 'user' | 'team'; @@ -38,7 +39,18 @@ type TeamMessageTypes = | 'user-added-room-to-team' | 'ujt'; -type OmnichannelTypesValues = 'livechat_transfer_history_fallback' | 'livechat-close'; +type LivechatMessageTypes = + | 'livechat_navigation_history' + | 'livechat_transfer_history' + | 'livechat_transcript_history' + | 'livechat_video_call' + | 'livechat_webrtc_video_call'; + +type OmnichannelTypesValues = + | 'livechat_transfer_history_fallback' + | 'livechat-close' + | 'omnichannel_placed_chat_on_hold' + | 'omnichannel_on_hold_chat_resumed'; type OtrSystemMessages = 'user_joined_otr' | 'user_requested_otr_key_refresh' | 'user_key_refreshed_successfully'; @@ -70,6 +82,7 @@ export type MessageTypesValues = | 'room-set-read-only' | 'room-allowed-reacting' | 'room-disallowed-reacting' + | LivechatMessageTypes | TeamMessageTypes | VoipMessageTypesValues | OmnichannelTypesValues @@ -218,6 +231,41 @@ export interface IMessageReactionsNormalized extends IMessage { export const isMessageReactionsNormalized = (message: IMessage): message is IMessageReactionsNormalized => Boolean('reactions' in message && message.reactions && message.reactions[0] && 'names' in message.reactions[0]); +export interface IOmnichannelSystemMessage extends IMessage { + navigation?: { + page: { + title: string; + location: { + href: string; + }; + token?: string; + }; + }; + transferData?: { + comment: string; + transferredBy: { + name?: string; + username: string; + }; + transferredTo: { + name?: string; + username: string; + }; + nextDepartment?: { + _id: string; + name?: string; + }; + scope: 'department' | 'agent' | 'queue'; + }; + requestData?: { + type: 'visitor' | 'user'; + visitor?: ILivechatVisitor; + user?: IUser; + }; + webRtcCallEndTs?: Date; + comment?: string; +} + export type IVoipMessage = IMessage & { voipData: { callDuration?: number;