UNPKG

@cometchat/chat-uikit-angular

Version:

Ready-to-use Chat UI Components for Angular (JavaScript/Web)

1,013 lines (1,007 loc) 1.41 MB
import { ConversationUtils, CometChatMentionsFormatter, CometChatUIKitLoginListener, UserMentionStyle, CometChatUrlsFormatter, CallingDetailsUtils, ExtensionsDataSource as ExtensionsDataSource$1, CollaborativeDocumentConstants, ExtensionsId, CollaborativeWhiteboardConstants, PollsConstants, CometChatUIKitUtility, CometChatSoundManager, SmartRepliesConfiguration, StickersConstants, StickersConfiguration, CometChatUIKitSharedSettings, CometChatUIKitCalls, StorageUtils, InteractiveMessageUtils, OutgoingCallStyle, OutgoingCallConfiguration, CallScreenConfiguration, CallButtonsStyle, IncomingCallStyle, UsersStyle, AddMembersStyle, MessageHeaderStyle, ListStyle, BannedMembersStyle, MessageReceiptUtils, ConversationsStyle, MessageInformationStyle, ReactionsConfiguration, MessageInformationConfiguration, MessageTranslationConstants, MessageTranslationStyle, CalendarStyle, TimeSlotStyle, SchedulerBubbleStyle, ReactionsStyle, FormBubbleStyle, CardBubbleStyle, LinkPreviewConstants, ThumbnailGenerationConstants, MessageListStyle, LinkPreviewStyle, SmartRepliesConstants, ReactionListStyle, ReactionListConfiguration, ReactionInfoStyle, ReactionInfoConfiguration, GroupMemberUtils, GroupMembersStyle, UserMemberWrapperConfiguration, MessageComposerStyle, MessageListConfiguration, MessageComposerConfiguration, ThreadedMessagesStyle, TransferOwnershipStyle, AddMembersConfiguration, BannedMembersConfiguration, GroupMembersConfiguration, TransferOwnershipConfiguration, DetailsUtils, DetailsStyle, MessageHeaderConfiguration, ThreadedMessagesConfiguration, DetailsConfiguration, MessagesStyle, GroupsStyle, UsersConfiguration, GroupsConfiguration, ContactsStyle, TabItemStyle, MessagesConfiguration, ConversationsConfiguration, ContactsConfiguration, WithMessagesStyle, CreateGroupConfiguration, JoinGroupConfiguration, CallLogsStyle, CallLogParticipantsStyle, CallLogRecordingsStyle, CallLogHistoryStyle, CallButtonsConfiguration, CallLogParticipantsConfiguration, CallLogHistoryConfiguration, CallLogRecordingsConfiguration, CallLogDetailsStyle, CallLogDetailsConfiguration, CallLogsConfiguration, WithDetailsStyle } from '@cometchat/uikit-shared'; export * from '@cometchat/uikit-shared'; import { CometChatMessageOption, CometChatUIKitConstants, localize, fontHelper, CometChatMessageTemplate, CometChatMessageComposerAction, MentionsTargetElement, MessageBubbleAlignment, CometChatTheme, CometChatMessageEvents, MessageStatus, CometChatUIEvents, ChatSdkEventInitializer, CometChatLocalize, CallWorkflow, CometChatCallEvents, IconButtonAlignment, TitleAlignment, States, DatePatterns, SelectionMode, UserPresencePlacement, CometChatUserEvents, CometChatGroupEvents, CometChatConversationEvents, MessageListAlignment, Receipts, TimestampAlignment, DocumentIconAlignment, Placement, UserMemberListType, AuxiliaryButtonAlignment, PreviewMessageMode, TabAlignment, TabsVisibility, CometChatCallDetailsTemplate, CometChatCallDetailsOption } from '@cometchat/uikit-resources'; export * from '@cometchat/uikit-resources'; import { CallscreenStyle, AvatarStyle, ListItemStyle, ConfirmDialogStyle, DateStyle, ReceiptStyle, BadgeStyle, MenuListStyle, QuickViewStyle, InputStyle, LabelStyle, RadioButtonStyle, CheckboxStyle, DropdownStyle, SingleSelectStyle, ChangeScopeStyle, MediaRecorderStyle, CreateGroupStyle, JoinGroupStyle } from '@cometchat/uikit-elements'; export { ActionSheetStyle, AvatarStyle, BackdropStyle, BadgeStyle, ButtonGroupStyle, CallscreenStyle, CardStyle, ChangeScopeStyle, CheckboxStyle, CometChatActionItem, CometChatActionSheet, CometChatAudioBubble, CometChatAvatar, CometChatBackdrop, CometChatBadge, CometChatButton, CometChatButtonGroup, CometChatCallscreenWrapper, CometChatCard, CometChatChangeScope, CometChatCheckbox, CometChatConfirmDialog, CometChatContextMenu, CometChatCreateGroup, CometChatDate, CometChatDivider, CometChatDocumentBubble, CometChatDraggable, CometChatDropdown, CometChatEmoji, CometChatEmojiKeyboard, CometChatFileBubble, CometChatFullScreenViewer, CometChatIcon, CometChatIconButton, CometChatImageBubble, CometChatInput, CometChatJoinGroup, CometChatLabel, CometChatListItem, CometChatLiveReaction, CometChatLoader, CometChatMediaRecorder, CometChatMenuList, CometChatMessageInput, CometChatModal, CometChatPanel, CometChatPopover, CometChatPreview, CometChatQuickView, CometChatRadioButton, CometChatReceipt, CometChatSearchInput, CometChatSingleSelect, CometChatStatusIndicator, CometChatTextBubble, CometChatTextInput, CometChatVideoBubble, ConfirmDialogStyle, ContextMenuStyle, CreateGroupStyle, DateStyle, DocumentBubbleStyle, DropdownStyle, EmojiKeyboardStyle, Emojis, FileBubbleStyle, FullScreenViewerStyle, IconStyle, ImageBubbleStyle, InputStyle, JoinGroupStyle, LabelStyle, ListItemStyle, LoaderStyle, MediaRecorderStyle, MenuListStyle, MessageInputStyle, ModalStyle, PanelStyle, PopoverStyle, PreviewStyle, QuickViewStyle, RadioButtonStyle, ReceiptStyle, SearchInputStyle, SingleSelectStyle, TextBubbleStyle, TextInputStyle, auxiliaryButtonAlignmentEnum, layoutType } from '@cometchat/uikit-elements'; import { CometChat } from '@cometchat/chat-sdk-javascript'; import * as i0 from '@angular/core'; import { Injectable, Component, ViewChild, Input, ChangeDetectionStrategy, NgModule, CUSTOM_ELEMENTS_SCHEMA, ViewChildren, EventEmitter, Output } from '@angular/core'; import * as i3 from '@angular/common'; import { CommonModule, DatePipe } from '@angular/common'; import { FormsModule } from '@angular/forms'; import * as i2 from '@angular/platform-browser'; class MessageUtils { /** * Creates an option to edit message. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getEditOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.editMessage, title: localize("EDIT"), iconURL: "assets/editicon.svg", onClick: null, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Creates an option to react to a message. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getReactionOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.reactToMessage, title: localize("REACT"), iconURL: "assets/addreaction.svg", onClick: undefined, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Creates an option to get info about a message. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getMessageInfoOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.messageInformation, title: localize("INFO"), iconURL: "assets/Info.svg", onClick: null, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Creates an option to send a private message. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getMessagePrivatelyOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.sendMessagePrivately, title: localize("MESSAGE_PRIVATELY"), iconURL: "assets/message-privately.svg", onClick: null, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Creates an option to delete a message. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getDeleteOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.deleteMessage, title: localize("DELETE"), iconURL: "assets/deleteicon.svg", onClick: null, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Creates an option to reply to a message in a thread. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getReplyInThreadOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.replyInThread, title: localize("REPLY"), iconURL: "assets/threadicon.svg", onClick: null, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Creates an option to copy a message. * @param {CometChatTheme} theme - The theme object. * @return {CometChatMessageOption} - Returns a new message option. */ getCopyOption(theme) { return new CometChatMessageOption({ id: CometChatUIKitConstants.MessageOption.copyMessage, title: localize("COPY"), iconURL: "assets/Copy.svg", onClick: null, iconTint: theme.palette.getAccent600(), backgroundColor: "transparent", titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent600(), }); } /** * Checks if a message is sent by current logged in user. * @param {CometChat.User} loggedInUser - The current logged in user. * @param {CometChat.BaseMessage} message - The message to check. * @return {boolean} - Returns true if message is sent by current logged in user, otherwise false. */ isSentByMe(loggedInUser, message) { return loggedInUser.getUid() === message.getSender().getUid(); } /** * Fetches options for text messages. * @param {CometChat.User} loggedInUser - The current logged in user. * @param {CometChat.BaseMessage} messageObject - The message object. * @param {CometChatTheme} theme - The theme object. * @param {CometChat.Group} group - The group object. * @return {Array<CometChatMessageOption>} - Returns an array of message options. */ getTextMessageOptions(loggedInUser, messageObject, theme, group) { let isSentByMe = this.isSentByMe(loggedInUser, messageObject); let isParticipant = false; if (group?.getScope() == CometChatUIKitConstants.groupMemberScope.participant) { isParticipant = true; } let messageOptionList = []; messageOptionList.push(this.getReactionOption(theme)); if (!messageObject.getParentMessageId()) { messageOptionList.push(this.getReplyInThreadOption(theme)); } messageOptionList.push(this.getCopyOption(theme)); if (isSentByMe || (!isParticipant && group)) { messageOptionList.push(this.getEditOption(theme)); } if (isSentByMe) { messageOptionList.push(this.getMessageInfoOption(theme)); } if (isSentByMe || (!isParticipant && group)) messageOptionList.push(this.getDeleteOption(theme)); if (group && !isSentByMe) { messageOptionList.push(this.getMessagePrivatelyOption(theme)); } return messageOptionList; } /** * Fetches options for image messages. * @param {CometChat.User} loggedInUser - The current logged in user. * @param {CometChat.BaseMessage} messageObject - The message object. * @param {CometChatTheme} theme - The theme object. * @param {CometChat.Group} group - The group object. * @return {Array<CometChatMessageOption>} - Returns an array of message options. */ getImageMessageOptions(loggedInUser, messageObject, theme, group) { let messageOptionList = []; messageOptionList = ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); return messageOptionList; } /** * Fetches options for video messages. * @param {CometChat.User} loggedInUser - The current logged in user. * @param {CometChat.BaseMessage} messageObject - The message object. * @param {CometChatTheme} theme - The theme object. * @param {CometChat.Group} group - (Optional) The group object. * @return {Array<CometChatMessageOption>} - Returns an array of message options. */ getVideoMessageOptions(loggedInUser, messageObject, theme, group) { let messageOptionList = []; messageOptionList = ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); return messageOptionList; } /** * Fetches options for audio messages. * @param {CometChat.User} loggedInUser - The current logged in user. * @param {CometChat.BaseMessage} messageObject - The message object. * @param {CometChatTheme} theme - The theme object. * @param {CometChat.Group} group - (Optional) The group object. * @return {Array<CometChatMessageOption>} - Returns an array of message options. */ getAudioMessageOptions(loggedInUser, messageObject, theme, group) { let messageOptionList = []; messageOptionList = ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); return messageOptionList; } /** * Fetches options for file messages. * @param {CometChat.User} loggedInUser - The current logged in user. * @param {CometChat.BaseMessage} messageObject - The message object. * @param {CometChatTheme} theme - The theme object. * @param {CometChat.Group} group - (Optional) The group object. * @return {Array<CometChatMessageOption>} - Returns an array of message options. */ getFileMessageOptions(loggedInUser, messageObject, theme, group) { let messageOptionList = []; messageOptionList = ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); return messageOptionList; } getBottomView(_messageObject, _alignment) { return null; } getSchedulerMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.scheduler, category: CometChatUIKitConstants.MessageCategory.interactive, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getTextMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.text, category: CometChatUIKitConstants.MessageCategory.message, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getAudioMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.audio, category: CometChatUIKitConstants.MessageCategory.message, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getVideoMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.video, category: CometChatUIKitConstants.MessageCategory.message, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getImageMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.image, category: CometChatUIKitConstants.MessageCategory.message, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getGroupActionTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.groupMember, category: CometChatUIKitConstants.MessageCategory.action, }); } getFileMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.file, category: CometChatUIKitConstants.MessageCategory.message, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getFormMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.form, category: CometChatUIKitConstants.MessageCategory.interactive, options: ChatConfigurator.getDataSource().getMessageOptions, }); } getCardMessageTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.card, category: CometChatUIKitConstants.MessageCategory.interactive, options: ChatConfigurator.getDataSource().getMessageOptions, }); } /** * Function to check if a user's status should be visible * @param {CometChat.User | CometChat.GroupMember} user - The user whose status visibility is to be checked. * @return {boolean} - Returns `true` if the user's status should be hidden (blocked or offline), `false` otherwise. */ getUserStatusVisibility(user) { let userBlockedFlag = false; if (user) { if (user.getBlockedByMe() || user.getHasBlockedMe() || user.getStatus() === CometChatUIKitConstants.userStatusType.offline) { userBlockedFlag = true; } } return userBlockedFlag; } getAllMessageTemplates() { return [ ChatConfigurator.getDataSource().getTextMessageTemplate(), ChatConfigurator.getDataSource().getImageMessageTemplate(), ChatConfigurator.getDataSource().getVideoMessageTemplate(), ChatConfigurator.getDataSource().getAudioMessageTemplate(), ChatConfigurator.getDataSource().getFileMessageTemplate(), ChatConfigurator.getDataSource().getGroupActionTemplate(), ChatConfigurator.getDataSource().getFormMessageTemplate(), ChatConfigurator.getDataSource().getCardMessageTemplate(), ChatConfigurator.getDataSource().getSchedulerMessageTemplate(), ]; } getMessageTemplate(messageType, messageCategory) { let _template = null; if (messageCategory != CometChatUIKitConstants.MessageCategory.call) { switch (messageType) { case CometChatUIKitConstants.MessageTypes.text: _template = ChatConfigurator.getDataSource().getTextMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.image: _template = ChatConfigurator.getDataSource().getImageMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.video: _template = ChatConfigurator.getDataSource().getVideoMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.groupMember: _template = ChatConfigurator.getDataSource().getGroupActionTemplate(); break; case CometChatUIKitConstants.MessageTypes.file: _template = ChatConfigurator.getDataSource().getFileMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.audio: _template = ChatConfigurator.getDataSource().getAudioMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.form: _template = ChatConfigurator.getDataSource().getFormMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.card: _template = ChatConfigurator.getDataSource().getCardMessageTemplate(); break; case CometChatUIKitConstants.MessageTypes.scheduler: _template = ChatConfigurator.getDataSource().getSchedulerMessageTemplate(); break; } } return _template; } getMessageOptions(loggedInUser, messageObject, theme, group) { let _optionList = []; if (messageObject.getCategory() == CometChatUIKitConstants.MessageCategory.message) { switch (messageObject.getType()) { case CometChatUIKitConstants.MessageTypes.text: _optionList = ChatConfigurator.getDataSource().getTextMessageOptions(loggedInUser, messageObject, theme, group); break; case CometChatUIKitConstants.MessageTypes.image: _optionList = ChatConfigurator.getDataSource().getImageMessageOptions(loggedInUser, messageObject, theme, group); break; case CometChatUIKitConstants.MessageTypes.video: _optionList = ChatConfigurator.getDataSource().getVideoMessageOptions(loggedInUser, messageObject, theme, group); break; case CometChatUIKitConstants.MessageTypes.groupMember: _optionList = []; break; case CometChatUIKitConstants.MessageTypes.file: _optionList = ChatConfigurator.getDataSource().getFileMessageOptions(loggedInUser, messageObject, theme, group); break; case CometChatUIKitConstants.MessageTypes.audio: _optionList = ChatConfigurator.getDataSource().getAudioMessageOptions(loggedInUser, messageObject, theme, group); break; } } else if (messageObject.getCategory() == CometChatUIKitConstants.MessageCategory.custom || messageObject.getCategory() == CometChatUIKitConstants.MessageCategory.interactive) { _optionList = ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); } return _optionList; } getCommonOptions(loggedInUser, messageObject, theme, group) { let isSentByMe = this.isSentByMe(loggedInUser, messageObject); let isParticipant = false; if (group?.getScope() == CometChatUIKitConstants.groupMemberScope.participant) isParticipant = true; let messageOptionList = []; messageOptionList.push(this.getReactionOption(theme)); if (!messageObject?.getParentMessageId()) { messageOptionList.push(this.getReplyInThreadOption(theme)); } if (isSentByMe) { messageOptionList.push(this.getMessageInfoOption(theme)); } if (isSentByMe || (!isParticipant && group)) messageOptionList.push(this.getDeleteOption(theme)); if (group && !isSentByMe) { messageOptionList.push(this.getMessagePrivatelyOption(theme)); } return messageOptionList; } getAllMessageTypes() { return [ CometChatUIKitConstants.MessageTypes.text, CometChatUIKitConstants.MessageTypes.image, CometChatUIKitConstants.MessageTypes.audio, CometChatUIKitConstants.MessageTypes.video, CometChatUIKitConstants.MessageTypes.file, CometChatUIKitConstants.MessageTypes.groupMember, CometChatUIKitConstants.MessageTypes.form, CometChatUIKitConstants.MessageTypes.card, CometChatUIKitConstants.MessageTypes.scheduler, ]; } addList() { return "<Message Utils>"; } getAllMessageCategories() { return [ CometChatUIKitConstants.MessageCategory.message, CometChatUIKitConstants.MessageCategory.action, CometChatUIKitConstants.MessageCategory.interactive, ]; } getAuxiliaryOptions(id, user, group) { return null; } getId() { return "messageUtils"; } getActionMessage(message) { try { if (message instanceof CometChat.Action) { const action = message.getAction(); const actionBy = message.getActionBy(); const actionOn = message.getActionOn(); const byString = actionBy.getName(); const forString = action === CometChatUIKitConstants.groupMemberAction.JOINED || action === CometChatUIKitConstants.groupMemberAction.LEFT ? "" : actionOn.getName(); switch (action) { case CometChatUIKitConstants.groupMemberAction.ADDED: return `${byString} ${localize("ADDED")} ${forString}`; case CometChatUIKitConstants.groupMemberAction.JOINED: return `${byString} ${localize("JOINED")}`; case CometChatUIKitConstants.groupMemberAction.LEFT: return `${byString} ${localize("LEFT")}`; case CometChatUIKitConstants.groupMemberAction.KICKED: return `${byString} ${localize("KICKED")} ${forString}`; case CometChatUIKitConstants.groupMemberAction.BANNED: return `${byString} ${localize("BANNED")} ${forString}`; case CometChatUIKitConstants.groupMemberAction.UNBANNED: return `${byString} ${localize("UNBANNED")} ${forString}`; case CometChatUIKitConstants.groupMemberAction.SCOPE_CHANGE: return `${byString} ${localize("MADE")} ${forString} ${message.getNewScope()}`; default: return ""; } } else { return ""; } } catch (e) { return ""; } } imageAttachmentOption(theme) { return new CometChatMessageComposerAction({ id: CometChatUIKitConstants.MessageTypes.image, title: localize("ATTACH_IMAGE"), iconURL: "assets/photolibrary.svg", onClick: null, iconTint: theme.palette.getAccent700(), titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent700(), borderRadius: "8px", background: theme.palette.getAccent100(), }); } videoAttachmentOption(theme) { return new CometChatMessageComposerAction({ id: CometChatUIKitConstants.MessageTypes.video, title: localize("ATTACH_VIDEO"), iconURL: "assets/video.svg", onClick: null, iconTint: theme.palette.getAccent700(), titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent700(), borderRadius: "8px", background: theme.palette.getAccent100(), }); } audioAttachmentOption(theme) { return new CometChatMessageComposerAction({ id: CometChatUIKitConstants.MessageTypes.audio, title: localize("ATTACH_AUDIO"), iconURL: "assets/audio-file.svg", onClick: null, iconTint: theme.palette.getAccent700(), titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent700(), borderRadius: "8px", background: theme.palette.getAccent100(), }); } fileAttachmentOption(theme) { return new CometChatMessageComposerAction({ id: CometChatUIKitConstants.MessageTypes.file, title: localize("ATTACH_FILE"), iconURL: "assets/attachment-file.svg", onClick: null, iconTint: theme.palette.getAccent700(), titleFont: fontHelper(theme.typography.subtitle1), titleColor: theme.palette.getAccent700(), borderRadius: "8px", background: theme.palette.getAccent100(), }); } getAttachmentOptions(theme, user, group, id) { let actions = [ this.imageAttachmentOption(theme), this.videoAttachmentOption(theme), this.audioAttachmentOption(theme), this.fileAttachmentOption(theme), ]; return actions; } getLastConversationMessage(conversation, loggedInUser, additionalConfigurations) { let config = { ...additionalConfigurations, textFormatters: additionalConfigurations?.textFormatters && additionalConfigurations?.textFormatters.length ? [...additionalConfigurations.textFormatters] : [this.getMentionsTextFormatter({ theme: additionalConfigurations.theme, disableMentions: additionalConfigurations.disableMentions })], }; let message = ConversationUtils.getLastConversationMessage(conversation, loggedInUser, config); let messageObject = conversation?.getLastMessage(); if (messageObject) { let textFormatters = config.textFormatters; if (config && !config.disableMentions) { let mentionsTextFormatter; for (let i = 0; i < textFormatters.length; i++) { if (textFormatters[i] instanceof CometChatMentionsFormatter) { mentionsTextFormatter = textFormatters[i]; mentionsTextFormatter.setMessage(messageObject); if (messageObject.getMentionedUsers().length) { mentionsTextFormatter.setCometChatUserGroupMembers(messageObject.getMentionedUsers()); } mentionsTextFormatter.setLoggedInUser(CometChatUIKitLoginListener.getLoggedInUser()); } if (mentionsTextFormatter) { break; } } if (!mentionsTextFormatter) { mentionsTextFormatter = ChatConfigurator.getDataSource().getMentionsTextFormatter({ messageObject, ...config, alignment: null, theme: additionalConfigurations.theme, }); textFormatters.push(mentionsTextFormatter); } } if (messageObject && messageObject instanceof CometChat.TextMessage) { for (let i = 0; i < textFormatters.length; i++) { message = textFormatters[i].getFormattedText(message, { mentionsTargetElement: MentionsTargetElement.conversation }); } } } return message; } /** * Adds styled @ for every mention in the text by matching uid * * @param {CometChat.TextMessage} message * @param {string} subtitle * @returns {void} */ getMentionsFormattedText(message, subtitle, mentionsFormatterParams) { const regex = /<@uid:(.*?)>/g; let messageText = message.getText(); let messageTextTmp = subtitle; let match = regex.exec(messageText); let cometChatUsers = []; let mentionedUsers = message.getMentionedUsers(); while (match !== null) { let user; for (let i = 0; i < mentionedUsers.length; i++) { if (match[1] == mentionedUsers[i].getUid()) { user = mentionedUsers[i]; } } if (user) { cometChatUsers.push(user); } match = regex.exec(messageText); } let mentionsFormatter = this.getMentionsTextFormatter(mentionsFormatterParams); mentionsFormatter.setClasses(["cc-mentions"]); mentionsFormatter.setCometChatUserGroupMembers(cometChatUsers); messageTextTmp = mentionsFormatter.getFormattedText(messageTextTmp, mentionsFormatterParams); return messageTextTmp; } getAIOptions(theme, id) { return []; } getAllTextFormatters(formatterParams) { let formatters = []; const mentionsFormatter = formatterParams.disableMentions ? null : ChatConfigurator.getDataSource().getMentionsTextFormatter(formatterParams); const urlTextFormatter = ChatConfigurator.getDataSource().getUrlTextFormatter(formatterParams); if (mentionsFormatter) { formatters.push(mentionsFormatter); } if (urlTextFormatter) { formatters.push(urlTextFormatter); } return formatters; } getMentionsTextFormatter(params) { let mentionsTextFormatter = new CometChatMentionsFormatter(); if (params && params.theme) { mentionsTextFormatter.setComposerMentionStyle(new UserMentionStyle({ loggedInUserTextFont: fontHelper(params.theme.typography.text2), loggedInUserTextColor: params.theme.palette.getPrimary(), loggedInUserTextBackground: "", mentionTextFont: fontHelper(params.theme.typography.text2), mentionTextColor: params.theme.palette.getPrimary(), mentionTextBackground: "", })); mentionsTextFormatter.setConversationMentionStyle(new UserMentionStyle({ loggedInUserTextFont: fontHelper(params.theme.typography.text3), loggedInUserTextColor: params.theme.palette.getPrimary(), loggedInUserTextBackground: "", mentionTextFont: fontHelper(params.theme.typography.text3), mentionTextColor: params.theme.palette.getPrimary(), mentionTextBackground: "", })); mentionsTextFormatter.setRightBubbleMentionStyle(new UserMentionStyle({ loggedInUserTextFont: fontHelper(params.theme.typography.text3), loggedInUserTextColor: params.theme.palette.getTertiary(), loggedInUserTextBackground: "", mentionTextFont: fontHelper(params.theme.typography.text3), mentionTextColor: params.theme.palette.getTertiary(), mentionTextBackground: "", })); mentionsTextFormatter.setLeftBubbleMentionStyle(new UserMentionStyle({ loggedInUserTextFont: fontHelper(params.theme.typography.text3), loggedInUserTextColor: params.theme.palette.getPrimary(), loggedInUserTextBackground: "", mentionTextFont: fontHelper(params.theme.typography.text3), mentionTextColor: params.theme.palette.getPrimary(), mentionTextBackground: "", })); } return mentionsTextFormatter; } getUrlTextFormatter(params = {}) { let urlTextFormatter = new CometChatUrlsFormatter([ /(https?:\/\/[^\s]+)/g, ]); if (params.alignment == MessageBubbleAlignment.left) { urlTextFormatter.setStyle({ formattedTextColor: params.theme.palette.getPrimary(), formattedTextFont: fontHelper(params.theme.typography.text3), }); } else { urlTextFormatter.setStyle({ formattedTextColor: params.theme.palette.getTertiary(), formattedTextFont: fontHelper(params.theme.typography.text3), }); } return urlTextFormatter; } } class ChatConfigurator { static init(initialSource) { this.dataSource = initialSource ?? new MessageUtils(); if (!initialSource) { this.names = []; } this.names.push(this.dataSource.getId()); } static enable(callback) { let oldSource = this.dataSource; let newSource = callback(oldSource); if (!this.names.find((nm) => nm == newSource.getId())) { this.dataSource = newSource; this.names.push(this.dataSource.getId()); } } static getDataSource() { return this.dataSource; } } ChatConfigurator.names = ["message utils"]; class DataSourceDecorator { constructor(dataSource) { this.dataSource = dataSource; } getTextMessageOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getTextMessageOptions(loggedInUser, messageObject, theme, group); } getImageMessageOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getImageMessageOptions(loggedInUser, messageObject, theme, group); } getVideoMessageOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getVideoMessageOptions(loggedInUser, messageObject, theme, group); } getAudioMessageOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getAudioMessageOptions(loggedInUser, messageObject, theme, group); } getFileMessageOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getFileMessageOptions(loggedInUser, messageObject, theme, group); } getTextMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getTextMessageTemplate(); } getImageMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getImageMessageTemplate(); } getVideoMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getVideoMessageTemplate(); } getAudioMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getAudioMessageTemplate(); } getFileMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getFileMessageTemplate(); } getFormMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getFormMessageTemplate(); } getCardMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getCardMessageTemplate(); } getGroupActionTemplate() { return (this.dataSource ?? new MessageUtils()).getGroupActionTemplate(); } getSchedulerMessageTemplate() { return (this.dataSource ?? new MessageUtils()).getSchedulerMessageTemplate(); } getAllMessageTemplates() { return (this.dataSource ?? new MessageUtils()).getAllMessageTemplates(); } getMessageTemplate(messageType, messageCategory) { return (this.dataSource ?? new MessageUtils()).getMessageTemplate(messageType, messageCategory); } getMessageOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getMessageOptions(loggedInUser, messageObject, theme, group); } getCommonOptions(loggedInUser, messageObject, theme, group) { return (this.dataSource ?? new MessageUtils()).getCommonOptions(loggedInUser, messageObject, theme, group); } getDeleteOption(theme) { return (this.dataSource ?? new MessageUtils()).getDeleteOption(theme); } getReplyInThreadOption(theme) { return (this.dataSource ?? new MessageUtils()).getReplyInThreadOption(theme); } getEditOption(theme) { return (this.dataSource ?? new MessageUtils()).getEditOption(theme); } getAttachmentOptions(theme = new CometChatTheme({}), user, group, id) { return (this.dataSource ?? new MessageUtils()).getAttachmentOptions(theme, user, group, id); } getAllMessageTypes() { return (this.dataSource ?? new MessageUtils()).getAllMessageTypes(); } getAllMessageCategories() { return (this.dataSource ?? new MessageUtils()).getAllMessageCategories(); } getAuxiliaryOptions(id, user, group) { return (this.dataSource ?? new MessageUtils()).getAuxiliaryOptions(id, user, group); } getId() { return (this.dataSource ?? new MessageUtils()).getId(); } getLastConversationMessage(conversation, loggedInUser, additionalParams) { return (this.dataSource ?? new MessageUtils()).getLastConversationMessage(conversation, loggedInUser, additionalParams); } getAIOptions(theme, id, aiOptionsStyles) { return (this.dataSource ?? new MessageUtils()).getAIOptions(theme, id, aiOptionsStyles); } getAllTextFormatters(formatterParams) { let formatters = []; const mentionsFormatter = formatterParams.disableMentions ? null : (this.dataSource ?? new MessageUtils()).getMentionsTextFormatter(formatterParams); const urlTextFormatter = (this.dataSource ?? new MessageUtils()).getUrlTextFormatter(formatterParams); if (mentionsFormatter) { formatters.push(mentionsFormatter); } if (urlTextFormatter) { formatters.push(urlTextFormatter); } return formatters; } getMentionsTextFormatter(formatterParams) { return (this.dataSource ?? new MessageUtils()).getMentionsTextFormatter(formatterParams); } getUrlTextFormatter(formatterParams) { return (this.dataSource ?? new MessageUtils()).getUrlTextFormatter(formatterParams); } getMentionsFormattedText(message, subtitle, mentionsFormatterParams) { return (this.dataSource ?? new MessageUtils()).getMentionsFormattedText(message, subtitle, mentionsFormatterParams); } } class CallingExtensionDecorator extends DataSourceDecorator { constructor(dataSource) { super(dataSource); this.onLogout(); } // end active call when user logs out onLogout() { var listenerID = "logout_listener"; CometChat.addLoginListener(listenerID, new CometChat.LoginListener({ logoutSuccess: () => { let call = CometChat.getActiveCall(); if (call) { CometChat.endCall(call.getSessionId()); } else { return; } }, logoutFailure: (error) => { console.log("LoginListener :: logoutFailure", error); }, })); } getAllMessageTypes() { const types = super.getAllMessageTypes(); if (!types.includes(CometChatUIKitConstants.calls.meeting)) { types.push(CometChatUIKitConstants.calls.meeting); } if (!types.includes(CometChatUIKitConstants.MessageTypes.audio)) { types.push(CometChatUIKitConstants.MessageTypes.audio); } if (!types.includes(CometChatUIKitConstants.MessageTypes.video)) { types.push(CometChatUIKitConstants.MessageTypes.video); } return types; } getId() { return "calling"; } getAllMessageCategories() { const categories = super.getAllMessageCategories(); if (!categories.includes(CometChatUIKitConstants.MessageCategory.call)) { categories.push(CometChatUIKitConstants.MessageCategory.call); } if (!categories.includes(CometChatUIKitConstants.MessageCategory.custom)) { categories.push(CometChatUIKitConstants.MessageCategory.custom); } return categories; } checkIfTemplateTypeExist(template, type) { return template.some((obj) => obj.type === type); } checkIfTemplateCategoryExist(template, category) { return template.some((obj) => obj.category === category); } getAllMessageTemplates() { const templates = super.getAllMessageTemplates(); if (!this.checkIfTemplateTypeExist(templates, CometChatUIKitConstants.calls.meeting)) { templates.push(this.getDirectCallTemplate()); } if (!this.checkIfTemplateCategoryExist(templates, CometChatUIKitConstants.MessageCategory.call)) { templates.push(...this.getDefaultCallTemplate()); } return templates; } getDirectCallTemplate() { return new CometChatMessageTemplate({ type: CometChatUIKitConstants.calls.meeting, category: CometChatUIKitConstants.MessageCategory.custom, options: (loggedInUser, messageObject, theme, group) => { return ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); }, }); } getDefaultCallTemplate() { let templates = [ new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.audio, category: CometChatUIKitConstants.MessageCategory.call, }), new CometChatMessageTemplate({ type: CometChatUIKitConstants.MessageTypes.video, category: CometChatUIKitConstants.MessageCategory.call, }), ]; return templates; } getLastConversationMessage(conversation, loggedInUser, additionalParams) { let actionMessage = ""; if (conversation.getLastMessage() && conversation.getLastMessage().category == CometChatUIKitConstants.MessageCategory.call) { let call = conversation.getLastMessage(); actionMessage = CallingDetailsUtils.getCallStatus(call, loggedInUser); } else if (conversation?.getLastMessage() && conversation.getLastMessage().type == CometChatUIKitConstants.calls.meeting) { let message = conversation.getLastMessage(); if (!message.getSender() || message?.getSender()?.getUid() == loggedInUser.getUid()) { actionMessage = localize("YOU_INITIATED_GROUP_CALL"); } else { actionMessage = `${message.getSender().getName()} ${localize("INITIATED_GROUP_CALL")}`; } let messageObject = conversation.getLastMessage(); if (messageObject && messageObject.getMentionedUsers().length && messageObject instanceof CometChat.TextMessage && additionalParams && !additionalParams.disableMentions) { actionMessage = this.getMentionsFormattedText(messageObject, actionMessage, additionalParams); } } else { actionMessage = super.getLastConversationMessage(conversation, loggedInUser, additionalParams); } return actionMessage; } } class CallingExtension extends ExtensionsDataSource$1 { getExtensionId() { return ''; } addExtension() { } enable() { ChatConfigurator.enable((dataSource) => new CallingExtensionDecorator(dataSource)); } } class CollaborativeDocumentExtensionDecorator extends DataSourceDecorator { constructor(dataSource) { super(dataSource); } getAllMessageTypes() { const types = super.getAllMessageTypes(); if (!types.includes(CollaborativeDocumentConstants.extension_document)) { types.push(CollaborativeDocumentConstants.extension_document); } return types; } getId() { return "collaborativedocument"; } getAllMessageCategories() { const categories = super.getAllMessageCategories(); if (!categories.includes(CometChatUIKitConstants.MessageCategory.custom)) { categories.push(CometChatUIKitConstants.MessageCategory.custom); } return categories; } checkIfTemplateExist(template, type) { return template.some((obj) => obj.type === type); } getAllMessageTemplates() { const templates = super.getAllMessageTemplates(); if (!this.checkIfTemplateExist(templates, CollaborativeDocumentConstants.extension_document)) { templates.push(this.getDocumentTemplate()); } return templates; } getDocumentTemplate() { return new CometChatMessageTemplate({ type: CollaborativeDocumentConstants.extension_document, category: CometChatUIKitConstants.MessageCategory.custom, options: (loggedInUser, messageObject, theme, group) => { return ChatConfigurator.getDataSource().getCommonOptions(loggedInUser, messageObject, theme, group); }, }); } getAttachmentOptions(theme = new CometChatTheme({}), user, group, id) { if (!id?.parentMessageId) { let receiverType = user ? CometChatUIKitConstants.MessageReceiverType.user : CometChatUIKitConstants.MessageReceiverType.group; let receiverId = user ? user.getUid() : group?.getGuid(); const messageComposerActions = super.getAttachmentOptions(theme, user, group, id); let newAction = new CometChatMessageComposerAction({ id: CollaborativeDocumentConstants.document, title: localize("COLLABORATIVE_DOCUMENT"), iconURL: "assets/collaborativedocument.svg", iconTint: theme.palette.getAccent700(), titl