2022-05-03 14:27:20 +00:00
|
|
|
/* eslint-disable complexity */
|
2022-02-01 13:39:09 +00:00
|
|
|
import { TMessageModel } from '../../definitions/IMessage';
|
2019-05-20 20:43:50 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { DISCUSSION } from './constants';
|
|
|
|
|
2022-04-14 20:30:41 +00:00
|
|
|
export const formatMessageCount = (count?: number, type?: string): string | null => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const discussion = type === DISCUSSION;
|
|
|
|
let text = discussion ? I18n.t('No_messages_yet') : null;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!count) {
|
|
|
|
return text;
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
if (count === 1) {
|
2021-09-13 20:41:05 +00:00
|
|
|
text = `${count} ${discussion ? I18n.t('message') : I18n.t('reply')}`;
|
2019-05-20 20:43:50 +00:00
|
|
|
} else if (count > 1 && count < 1000) {
|
2021-09-13 20:41:05 +00:00
|
|
|
text = `${count} ${discussion ? I18n.t('messages') : I18n.t('replies')}`;
|
2019-05-20 20:43:50 +00:00
|
|
|
} else if (count > 999) {
|
2021-09-13 20:41:05 +00:00
|
|
|
text = `+999 ${discussion ? I18n.t('messages') : I18n.t('replies')}`;
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const BUTTON_HIT_SLOP = {
|
2021-09-13 20:41:05 +00:00
|
|
|
top: 4,
|
|
|
|
right: 4,
|
|
|
|
bottom: 4,
|
|
|
|
left: 4
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const SYSTEM_MESSAGES = [
|
|
|
|
'r',
|
|
|
|
'au',
|
|
|
|
'ru',
|
|
|
|
'ul',
|
2022-01-17 14:31:15 +00:00
|
|
|
'ult',
|
2019-05-20 20:43:50 +00:00
|
|
|
'uj',
|
2022-01-17 14:31:15 +00:00
|
|
|
'ujt',
|
2019-05-20 20:43:50 +00:00
|
|
|
'ut',
|
|
|
|
'rm',
|
|
|
|
'user-muted',
|
|
|
|
'user-unmuted',
|
|
|
|
'message_pinned',
|
|
|
|
'subscription-role-added',
|
|
|
|
'subscription-role-removed',
|
|
|
|
'room_changed_description',
|
|
|
|
'room_changed_announcement',
|
|
|
|
'room_changed_topic',
|
|
|
|
'room_changed_privacy',
|
2020-10-30 13:51:04 +00:00
|
|
|
'room_changed_avatar',
|
2019-05-20 20:43:50 +00:00
|
|
|
'message_snippeted',
|
2021-02-24 16:33:39 +00:00
|
|
|
'thread-created',
|
|
|
|
'room_e2e_enabled',
|
2022-02-23 20:31:14 +00:00
|
|
|
'room_e2e_disabled',
|
|
|
|
'removed-user-from-team',
|
|
|
|
'added-user-to-team',
|
|
|
|
'user-added-room-to-team',
|
|
|
|
'user-converted-to-team',
|
|
|
|
'user-converted-to-channel',
|
|
|
|
'user-deleted-room-from-team',
|
2022-04-20 20:53:11 +00:00
|
|
|
'user-removed-room-from-team',
|
2022-05-03 14:27:20 +00:00
|
|
|
'room-disallowed-reacting',
|
|
|
|
'room-allowed-reacting',
|
|
|
|
'room-set-read-only',
|
|
|
|
'room-removed-read-only',
|
2022-04-20 20:53:11 +00:00
|
|
|
'omnichannel_placed_chat_on_hold',
|
|
|
|
'omnichannel_on_hold_chat_resumed'
|
2019-05-20 20:43:50 +00:00
|
|
|
];
|
|
|
|
|
2022-05-03 14:27:20 +00:00
|
|
|
export const IGNORED_LIVECHAT_SYSTEM_MESSAGES = [
|
|
|
|
'livechat_navigation_history',
|
|
|
|
'livechat_transcript_history',
|
|
|
|
'livechat_transfer_history',
|
|
|
|
'command',
|
|
|
|
'livechat-close',
|
|
|
|
'livechat-started',
|
|
|
|
'livechat_video_call',
|
|
|
|
'livechat_webrtc_video_call'
|
|
|
|
];
|
|
|
|
|
2020-12-01 19:26:03 +00:00
|
|
|
export const SYSTEM_MESSAGE_TYPES = {
|
|
|
|
MESSAGE_REMOVED: 'rm',
|
|
|
|
MESSAGE_PINNED: 'message_pinned',
|
|
|
|
MESSAGE_SNIPPETED: 'message_snippeted',
|
|
|
|
USER_JOINED_CHANNEL: 'uj',
|
2022-01-17 14:31:15 +00:00
|
|
|
USER_JOINED_TEAM: 'ujt',
|
2020-12-01 19:26:03 +00:00
|
|
|
USER_JOINED_DISCUSSION: 'ut',
|
2022-01-17 14:31:15 +00:00
|
|
|
USER_LEFT_CHANNEL: 'ul',
|
2022-02-23 20:31:14 +00:00
|
|
|
USER_LEFT_TEAM: 'ult',
|
|
|
|
REMOVED_USER_FROM_TEAM: 'removed-user-from-team',
|
|
|
|
ADDED_USER_TO_TEAM: 'added-user-to-team',
|
|
|
|
ADDED_ROOM_TO_TEAM: 'user-added-room-to-team',
|
|
|
|
CONVERTED_TO_TEAM: 'user-converted-to-team',
|
|
|
|
CONVERTED_TO_CHANNEL: 'user-converted-to-channel',
|
|
|
|
DELETED_ROOM_FROM_TEAM: 'user-deleted-room-from-team',
|
2022-04-20 20:53:11 +00:00
|
|
|
REMOVED_ROOM_FROM_TEAM: 'user-removed-room-from-team',
|
|
|
|
OMNICHANNEL_PLACED_CHAT_ON_HOLD: 'omnichannel_placed_chat_on_hold',
|
2022-05-03 14:27:20 +00:00
|
|
|
OMNICHANNEL_ON_HOLD_CHAT_RESUMED: 'omnichannel_on_hold_chat_resumed',
|
|
|
|
LIVECHAT_NAVIGATION_HISTORY: 'livechat_navigation_history',
|
|
|
|
LIVECHAT_TRANSCRIPT_HISTORY: 'livechat_transcript_history',
|
|
|
|
COMMAND: 'command',
|
|
|
|
LIVECHAT_STARTED: 'livechat-started',
|
|
|
|
LIVECHAT_CLOSE: 'livechat-close',
|
|
|
|
LIVECHAT_VIDEO_CALL: 'livechat_video_call',
|
|
|
|
LIVECHAT_WEBRTC_VIDEO_CALL: 'livechat_webrtc_video_call',
|
|
|
|
LIVECHAT_TRANSFER_HISTORY: 'livechat_transfer_history'
|
2020-12-01 19:26:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME = [
|
|
|
|
SYSTEM_MESSAGE_TYPES.MESSAGE_REMOVED,
|
|
|
|
SYSTEM_MESSAGE_TYPES.MESSAGE_PINNED,
|
|
|
|
SYSTEM_MESSAGE_TYPES.MESSAGE_SNIPPETED,
|
|
|
|
SYSTEM_MESSAGE_TYPES.USER_JOINED_CHANNEL,
|
2022-01-17 14:31:15 +00:00
|
|
|
SYSTEM_MESSAGE_TYPES.USER_JOINED_TEAM,
|
2020-12-01 19:26:03 +00:00
|
|
|
SYSTEM_MESSAGE_TYPES.USER_JOINED_DISCUSSION,
|
2022-01-17 14:31:15 +00:00
|
|
|
SYSTEM_MESSAGE_TYPES.USER_LEFT_CHANNEL,
|
2022-02-23 20:31:14 +00:00
|
|
|
SYSTEM_MESSAGE_TYPES.USER_LEFT_TEAM,
|
|
|
|
SYSTEM_MESSAGE_TYPES.REMOVED_USER_FROM_TEAM,
|
|
|
|
SYSTEM_MESSAGE_TYPES.ADDED_USER_TO_TEAM,
|
|
|
|
SYSTEM_MESSAGE_TYPES.ADDED_ROOM_TO_TEAM,
|
|
|
|
SYSTEM_MESSAGE_TYPES.CONVERTED_TO_TEAM,
|
|
|
|
SYSTEM_MESSAGE_TYPES.CONVERTED_TO_CHANNEL,
|
|
|
|
SYSTEM_MESSAGE_TYPES.DELETED_ROOM_FROM_TEAM,
|
2022-05-03 14:27:20 +00:00
|
|
|
SYSTEM_MESSAGE_TYPES.REMOVED_ROOM_FROM_TEAM,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_NAVIGATION_HISTORY,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_TRANSCRIPT_HISTORY,
|
|
|
|
SYSTEM_MESSAGE_TYPES.COMMAND,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_STARTED,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_CLOSE,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_VIDEO_CALL,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_WEBRTC_VIDEO_CALL,
|
|
|
|
SYSTEM_MESSAGE_TYPES.LIVECHAT_TRANSFER_HISTORY
|
2020-12-01 19:26:03 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
type TInfoMessage = {
|
|
|
|
type: string;
|
|
|
|
role: string;
|
|
|
|
msg: string;
|
|
|
|
author: { username: string };
|
2022-04-20 20:53:11 +00:00
|
|
|
comment?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2022-02-23 20:31:14 +00:00
|
|
|
|
2022-04-20 20:53:11 +00:00
|
|
|
export const getInfoMessage = ({ type, role, msg, author, comment }: TInfoMessage): string => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { username } = author;
|
2022-05-03 14:27:20 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
if (type === 'rm') {
|
|
|
|
return I18n.t('Message_removed');
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'uj') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Has_joined_the_channel');
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
2022-01-17 14:31:15 +00:00
|
|
|
if (type === 'ujt') {
|
|
|
|
return I18n.t('Has_joined_the_team');
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
if (type === 'ut') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Has_joined_the_conversation');
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'r') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Room_name_changed', { name: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'message_pinned') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Message_pinned');
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'jitsi_call_started') {
|
2019-09-18 17:32:12 +00:00
|
|
|
return I18n.t('Started_call', { userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'ul') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Has_left_the_channel');
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
2022-01-17 14:31:15 +00:00
|
|
|
if (type === 'ult') {
|
|
|
|
return I18n.t('Has_left_the_team');
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
if (type === 'ru') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('User_removed_by', { userRemoved: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'au') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('User_added_by', { userAdded: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'user-muted') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('User_muted_by', { userMuted: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'user-unmuted') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('User_unmuted_by', { userUnmuted: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'subscription-role-added') {
|
|
|
|
return `${msg} was set ${role} by ${username}`;
|
|
|
|
}
|
|
|
|
if (type === 'subscription-role-removed') {
|
|
|
|
return `${msg} is no longer ${role} by ${username}`;
|
|
|
|
}
|
|
|
|
if (type === 'room_changed_description') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Room_changed_description', { description: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'room_changed_announcement') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Room_changed_announcement', { announcement: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'room_changed_topic') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Room_changed_topic', { topic: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'room_changed_privacy') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Room_changed_privacy', { type: msg, userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'room_changed_avatar') {
|
2020-10-30 13:51:04 +00:00
|
|
|
return I18n.t('Room_changed_avatar', { userBy: username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'message_snippeted') {
|
2019-05-20 20:43:50 +00:00
|
|
|
return I18n.t('Created_snippet');
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'room_e2e_disabled') {
|
2021-02-24 16:33:39 +00:00
|
|
|
return I18n.t('This_room_encryption_has_been_disabled_by__username_', { username });
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
if (type === 'room_e2e_enabled') {
|
2021-02-24 16:33:39 +00:00
|
|
|
return I18n.t('This_room_encryption_has_been_enabled_by__username_', { username });
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2022-02-23 20:31:14 +00:00
|
|
|
if (type === 'removed-user-from-team') {
|
2022-03-21 20:25:40 +00:00
|
|
|
return I18n.t('Removed__username__from_team', { user_removed: msg });
|
2022-02-23 20:31:14 +00:00
|
|
|
}
|
|
|
|
if (type === 'added-user-to-team') {
|
2022-03-21 20:25:40 +00:00
|
|
|
return I18n.t('Added__username__to_team', { user_added: msg });
|
2022-02-23 20:31:14 +00:00
|
|
|
}
|
|
|
|
if (type === 'user-added-room-to-team') {
|
|
|
|
return I18n.t('added__roomName__to_team', { roomName: msg });
|
|
|
|
}
|
|
|
|
if (type === 'user-converted-to-team') {
|
|
|
|
return I18n.t('Converted__roomName__to_team', { roomName: msg });
|
|
|
|
}
|
|
|
|
if (type === 'user-converted-to-channel') {
|
|
|
|
return I18n.t('Converted__roomName__to_channel', { roomName: msg });
|
|
|
|
}
|
|
|
|
if (type === 'user-deleted-room-from-team') {
|
|
|
|
return I18n.t('Deleted__roomName__', { roomName: msg });
|
|
|
|
}
|
|
|
|
if (type === 'user-removed-room-from-team') {
|
|
|
|
return I18n.t('Removed__roomName__from_this_team', { roomName: msg });
|
|
|
|
}
|
2022-05-03 14:27:20 +00:00
|
|
|
if (type === 'room-disallowed-reacting') {
|
|
|
|
return I18n.t('Room_disallowed_reacting', { userBy: username });
|
|
|
|
}
|
|
|
|
if (type === 'room-allowed-reacting') {
|
|
|
|
return I18n.t('Room_allowed_reacting', { userBy: username });
|
|
|
|
}
|
|
|
|
if (type === 'room-set-read-only') {
|
|
|
|
return I18n.t('Room_set_read_only', { userBy: username });
|
|
|
|
}
|
|
|
|
if (type === 'room-removed-read-only') {
|
|
|
|
return I18n.t('Room_removed_read_only', { userBy: username });
|
|
|
|
}
|
2022-04-20 20:53:11 +00:00
|
|
|
if (type === 'omnichannel_placed_chat_on_hold') {
|
|
|
|
return I18n.t('Omnichannel_placed_chat_on_hold', { comment });
|
|
|
|
}
|
|
|
|
if (type === 'omnichannel_on_hold_chat_resumed') {
|
|
|
|
return I18n.t('Omnichannel_on_hold_chat_resumed', { comment });
|
|
|
|
}
|
2022-05-03 14:27:20 +00:00
|
|
|
if (type === 'command') {
|
|
|
|
return I18n.t('Livechat_transfer_return_to_the_queue');
|
|
|
|
}
|
|
|
|
if (type === 'livechat-started') {
|
|
|
|
return I18n.t('Chat_started');
|
|
|
|
}
|
|
|
|
if (type === 'livechat-close') {
|
|
|
|
return I18n.t('Conversation_closed');
|
|
|
|
}
|
|
|
|
if (type === 'livechat_transfer_history') {
|
|
|
|
return I18n.t('New_chat_transfer', { agent: username });
|
|
|
|
}
|
|
|
|
return I18n.t('Unsupported_system_message');
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
|
2022-02-01 13:39:09 +00:00
|
|
|
export const getMessageTranslation = (message: TMessageModel, autoTranslateLanguage: string) => {
|
2019-06-28 17:02:30 +00:00
|
|
|
if (!autoTranslateLanguage) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const { translations } = message;
|
|
|
|
if (translations) {
|
2021-09-13 20:41:05 +00:00
|
|
|
const translation = translations.find((trans: any) => trans.language === autoTranslateLanguage);
|
2019-06-28 17:02:30 +00:00
|
|
|
return translation && translation.value;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|