Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Converting files from app/livechat folder from JS to TS #25658

Merged
merged 5 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/meteor/app/livechat/lib/Assets.js

This file was deleted.

4 changes: 4 additions & 0 deletions apps/meteor/app/livechat/lib/Assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const addServerUrlToIndex = (file: string): string => {
const rootUrl = window.__meteor_runtime_config__.ROOT_URL.replace(/\/$/, '');
return file.replace('<body>', `<body><script> SERVER_URL = '${rootUrl}'; </script>`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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) {
data(message: IOmnichannelSystemMessage) {
if (!message.navigation || !message.navigation.page) {
return;
}
Expand All @@ -23,7 +24,7 @@ MessageTypes.registerType({
id: 'livechat_transfer_history',
system: true,
message: 'New_chat_transfer',
data(message) {
data(message: IOmnichannelSystemMessage) {
if (!message.transferData) {
return;
}
Expand All @@ -33,20 +34,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,
}),
Expand All @@ -61,21 +61,21 @@ MessageTypes.registerType({
id: 'livechat_transcript_history',
system: true,
message: 'Livechat_chat_transcript_sent',
data(message) {
data(message: IOmnichannelSystemMessage) {
if (!message.requestData) {
return;
}

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 || '',
}),
};

Expand Down Expand Up @@ -105,13 +105,17 @@ 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) {
if (!message.comment) {
return;
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
}
return {
comment: message.comment,
};
Expand All @@ -122,7 +126,10 @@ MessageTypes.registerType({
id: 'omnichannel_on_hold_chat_resumed',
system: true,
message: 'Omnichannel_on_hold_chat_resumed',
data(message) {
data(message: IOmnichannelSystemMessage) {
if (!message.comment) {
return;
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
}
return {
comment: message.comment,
};
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/ui-utils/lib/MessageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type MessageType = {
/* deprecated */
template?: (message: IMessage) => unknown;
message: TranslationKey;
data?: (message: IMessage) => Record<string, string>;
data?: (message: IMessage) => Record<string, string> | undefined;
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
};
class MessageTypesClass {
private types = new Map<MessageTypesValues, MessageType>();
Expand Down
50 changes: 49 additions & 1 deletion packages/core-typings/src/IMessage/IMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -70,6 +82,7 @@ export type MessageTypesValues =
| 'room-set-read-only'
| 'room-allowed-reacting'
| 'room-disallowed-reacting'
| LivechatMessageTypes
| TeamMessageTypes
| VoipMessageTypesValues
| OmnichannelTypesValues
Expand Down Expand Up @@ -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;
Expand Down