2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2021-01-13 12:36:25 +00:00
|
|
|
<div class="reply-box" :class="replyBoxClass">
|
2022-02-07 06:57:20 +00:00
|
|
|
<banner
|
|
|
|
v-if="showSelfAssignBanner"
|
|
|
|
color-scheme="secondary"
|
|
|
|
:banner-message="$t('CONVERSATION.NOT_ASSIGNED_TO_YOU')"
|
|
|
|
:has-action-button="true"
|
|
|
|
:action-button-label="$t('CONVERSATION.ASSIGN_TO_ME')"
|
|
|
|
@click="onClickSelfAssign"
|
|
|
|
/>
|
2021-01-13 13:46:45 +00:00
|
|
|
<reply-top-panel
|
|
|
|
:mode="replyType"
|
|
|
|
:set-reply-mode="setReplyMode"
|
|
|
|
:is-message-length-reaching-threshold="isMessageLengthReachingThreshold"
|
|
|
|
:characters-remaining="charactersRemaining"
|
2021-09-01 13:42:22 +00:00
|
|
|
:popout-reply-box="popoutReplyBox"
|
|
|
|
@click="$emit('click')"
|
2021-01-13 13:46:45 +00:00
|
|
|
/>
|
2021-01-13 12:36:25 +00:00
|
|
|
<div class="reply-box__top">
|
|
|
|
<canned-response
|
2021-01-26 18:34:11 +00:00
|
|
|
v-if="showMentions && hasSlashCommand"
|
|
|
|
v-on-clickaway="hideMentions"
|
|
|
|
:search-key="mentionSearchKey"
|
2021-01-23 08:37:01 +00:00
|
|
|
@click="replaceText"
|
2021-01-13 12:36:25 +00:00
|
|
|
/>
|
|
|
|
<emoji-input
|
|
|
|
v-if="showEmojiPicker"
|
|
|
|
v-on-clickaway="hideEmojiPicker"
|
|
|
|
:on-click="emojiOnClick"
|
|
|
|
/>
|
2021-10-11 07:30:48 +00:00
|
|
|
<reply-email-head
|
|
|
|
v-if="showReplyHead"
|
2021-12-07 18:14:32 +00:00
|
|
|
:cc-emails.sync="ccEmails"
|
|
|
|
:bcc-emails.sync="bccEmails"
|
2021-10-11 07:30:48 +00:00
|
|
|
/>
|
2021-01-13 12:36:25 +00:00
|
|
|
<resizable-text-area
|
2021-01-26 18:34:11 +00:00
|
|
|
v-if="!showRichContentEditor"
|
2021-01-13 12:36:25 +00:00
|
|
|
ref="messageInput"
|
|
|
|
v-model="message"
|
|
|
|
class="input"
|
|
|
|
:placeholder="messagePlaceHolder"
|
|
|
|
:min-height="4"
|
|
|
|
@typing-off="onTypingOff"
|
|
|
|
@typing-on="onTypingOn"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
/>
|
2021-01-18 05:50:19 +00:00
|
|
|
<woot-message-editor
|
|
|
|
v-else
|
|
|
|
v-model="message"
|
|
|
|
class="input"
|
2021-01-26 18:34:11 +00:00
|
|
|
:is-private="isOnPrivateNote"
|
2021-01-18 05:50:19 +00:00
|
|
|
:placeholder="messagePlaceHolder"
|
|
|
|
:min-height="4"
|
|
|
|
@typing-off="onTypingOff"
|
|
|
|
@typing-on="onTypingOn"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
2021-01-26 18:34:11 +00:00
|
|
|
@toggle-user-mention="toggleUserMention"
|
2021-06-02 04:50:40 +00:00
|
|
|
@toggle-canned-menu="toggleCannedMenu"
|
2021-01-18 05:50:19 +00:00
|
|
|
/>
|
2021-01-13 12:36:25 +00:00
|
|
|
</div>
|
2021-11-02 04:35:49 +00:00
|
|
|
<div v-if="hasAttachments" class="attachment-preview-box" @paste="onPaste">
|
2021-01-06 12:26:29 +00:00
|
|
|
<attachment-preview
|
|
|
|
:attachments="attachedFiles"
|
|
|
|
:remove-attachment="removeAttachment"
|
2019-12-16 12:53:14 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
</div>
|
2021-01-13 12:36:25 +00:00
|
|
|
<reply-bottom-panel
|
|
|
|
:mode="replyType"
|
|
|
|
:send-button-text="replyButtonLabel"
|
2022-01-27 10:27:22 +00:00
|
|
|
:on-direct-file-upload="onDirectFileUpload"
|
2021-01-13 12:36:25 +00:00
|
|
|
:show-file-upload="showFileUpload"
|
|
|
|
:toggle-emoji-picker="toggleEmojiPicker"
|
|
|
|
:show-emoji-picker="showEmojiPicker"
|
|
|
|
:on-send="sendMessage"
|
|
|
|
:is-send-disabled="isReplyButtonDisabled"
|
2021-01-18 05:50:19 +00:00
|
|
|
:set-format-mode="setFormatMode"
|
2021-01-26 18:34:11 +00:00
|
|
|
:is-on-private-note="isOnPrivateNote"
|
|
|
|
:is-format-mode="showRichContentEditor"
|
2021-01-18 05:50:19 +00:00
|
|
|
:enable-rich-editor="isRichEditorEnabled"
|
2021-01-19 13:58:40 +00:00
|
|
|
:enter-to-send-enabled="enterToSendEnabled"
|
2022-01-25 02:46:58 +00:00
|
|
|
:enable-multiple-file-upload="enableMultipleFileUpload"
|
2021-01-19 13:58:40 +00:00
|
|
|
@toggleEnterToSend="toggleEnterToSend"
|
2021-01-13 12:36:25 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import { mixin as clickaway } from 'vue-clickaway';
|
2021-04-15 16:58:19 +00:00
|
|
|
import alertMixin from 'shared/mixins/alertMixin';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-09-13 17:19:01 +00:00
|
|
|
import EmojiInput from 'shared/components/emoji/EmojiInput';
|
2019-08-14 09:48:44 +00:00
|
|
|
import CannedResponse from './CannedResponse';
|
2020-06-18 09:47:45 +00:00
|
|
|
import ResizableTextArea from 'shared/components/ResizableTextArea';
|
2021-01-06 12:26:29 +00:00
|
|
|
import AttachmentPreview from 'dashboard/components/widgets/AttachmentsPreview';
|
2021-01-13 12:36:25 +00:00
|
|
|
import ReplyTopPanel from 'dashboard/components/widgets/WootWriter/ReplyTopPanel';
|
2021-10-11 07:30:48 +00:00
|
|
|
import ReplyEmailHead from './ReplyEmailHead';
|
2021-01-13 12:36:25 +00:00
|
|
|
import ReplyBottomPanel from 'dashboard/components/widgets/WootWriter/ReplyBottomPanel';
|
2022-02-07 06:57:20 +00:00
|
|
|
import Banner from 'dashboard/components/ui/Banner.vue';
|
2021-01-13 12:36:25 +00:00
|
|
|
import { REPLY_EDITOR_MODES } from 'dashboard/components/widgets/WootWriter/constants';
|
2021-01-18 05:50:19 +00:00
|
|
|
import WootMessageEditor from 'dashboard/components/widgets/WootWriter/Editor';
|
2021-04-15 16:58:19 +00:00
|
|
|
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
|
|
|
|
import { MAXIMUM_FILE_UPLOAD_SIZE } from 'shared/constants/messages';
|
2021-11-30 05:15:36 +00:00
|
|
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
2021-04-15 16:58:19 +00:00
|
|
|
|
2020-07-16 19:02:32 +00:00
|
|
|
import {
|
|
|
|
isEscape,
|
|
|
|
isEnter,
|
|
|
|
hasPressedShift,
|
2022-01-27 12:27:33 +00:00
|
|
|
hasPressedCommandPlusKKey,
|
2020-07-16 19:02:32 +00:00
|
|
|
} from 'shared/helpers/KeyboardHelpers';
|
|
|
|
import { MESSAGE_MAX_LENGTH } from 'shared/helpers/MessageTypeHelper';
|
2020-08-05 12:16:17 +00:00
|
|
|
import inboxMixin from 'shared/mixins/inboxMixin';
|
2021-02-07 07:24:32 +00:00
|
|
|
import uiSettingsMixin from 'dashboard/mixins/uiSettings';
|
2022-01-27 10:27:22 +00:00
|
|
|
import { DirectUpload } from 'activestorage';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
2020-03-05 20:17:37 +00:00
|
|
|
components: {
|
|
|
|
EmojiInput,
|
|
|
|
CannedResponse,
|
2020-06-18 09:47:45 +00:00
|
|
|
ResizableTextArea,
|
2021-01-06 12:26:29 +00:00
|
|
|
AttachmentPreview,
|
2021-01-13 12:36:25 +00:00
|
|
|
ReplyTopPanel,
|
2021-10-11 07:30:48 +00:00
|
|
|
ReplyEmailHead,
|
2021-01-13 12:36:25 +00:00
|
|
|
ReplyBottomPanel,
|
2021-01-18 05:50:19 +00:00
|
|
|
WootMessageEditor,
|
2022-02-07 06:57:20 +00:00
|
|
|
Banner,
|
2020-03-05 20:17:37 +00:00
|
|
|
},
|
2021-09-15 14:45:06 +00:00
|
|
|
mixins: [clickaway, inboxMixin, uiSettingsMixin, alertMixin],
|
2020-08-11 04:27:42 +00:00
|
|
|
props: {
|
2021-08-02 10:37:30 +00:00
|
|
|
selectedTweet: {
|
|
|
|
type: [Object, String],
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
isATweet: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2020-08-11 04:27:42 +00:00
|
|
|
},
|
2021-09-01 13:42:22 +00:00
|
|
|
popoutReplyBox: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-08-11 04:27:42 +00:00
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
message: '',
|
2020-07-04 08:20:44 +00:00
|
|
|
isFocused: false,
|
2019-08-14 09:48:44 +00:00
|
|
|
showEmojiPicker: false,
|
2021-01-26 18:34:11 +00:00
|
|
|
showMentions: false,
|
2021-01-06 12:26:29 +00:00
|
|
|
attachedFiles: [],
|
2021-01-13 12:36:25 +00:00
|
|
|
isUploading: false,
|
|
|
|
replyType: REPLY_EDITOR_MODES.REPLY,
|
2021-01-26 18:34:11 +00:00
|
|
|
mentionSearchKey: '',
|
|
|
|
hasUserMention: false,
|
|
|
|
hasSlashCommand: false,
|
2021-12-07 18:14:32 +00:00
|
|
|
bccEmails: '',
|
|
|
|
ccEmails: '',
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
},
|
2019-11-17 08:45:05 +00:00
|
|
|
computed: {
|
2022-02-07 06:57:20 +00:00
|
|
|
...mapGetters({
|
|
|
|
currentChat: 'getSelectedChat',
|
|
|
|
currentUser: 'getCurrentUser',
|
|
|
|
}),
|
|
|
|
|
2021-01-26 18:34:11 +00:00
|
|
|
showRichContentEditor() {
|
2021-04-16 13:33:46 +00:00
|
|
|
if (this.isOnPrivateNote) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isRichEditorEnabled) {
|
|
|
|
const {
|
|
|
|
display_rich_content_editor: displayRichContentEditor,
|
|
|
|
} = this.uiSettings;
|
|
|
|
|
|
|
|
return displayRichContentEditor;
|
|
|
|
}
|
|
|
|
return false;
|
2021-01-26 18:34:11 +00:00
|
|
|
},
|
2022-02-07 06:57:20 +00:00
|
|
|
assignedAgent: {
|
|
|
|
get() {
|
|
|
|
return this.currentChat.meta.assignee;
|
|
|
|
},
|
|
|
|
set(agent) {
|
|
|
|
const agentId = agent ? agent.id : 0;
|
|
|
|
this.$store.dispatch('setCurrentChatAssignee', agent);
|
|
|
|
this.$store
|
|
|
|
.dispatch('assignAgent', {
|
|
|
|
conversationId: this.currentChat.id,
|
|
|
|
agentId,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.showAlert(this.$t('CONVERSATION.CHANGE_AGENT'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showSelfAssignBanner() {
|
|
|
|
if (this.message !== '' && !this.isOnPrivateNote) {
|
|
|
|
if (!this.assignedAgent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (this.assignedAgent.id !== this.currentUser.id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2021-01-19 13:58:40 +00:00
|
|
|
enterToSendEnabled() {
|
|
|
|
return !!this.uiSettings.enter_to_send_enabled;
|
|
|
|
},
|
2020-07-25 17:24:45 +00:00
|
|
|
isPrivate() {
|
2021-10-05 18:05:06 +00:00
|
|
|
if (this.currentChat.can_reply || this.isAWhatsappChannel) {
|
2021-01-26 18:34:11 +00:00
|
|
|
return this.isOnPrivateNote;
|
2020-07-25 17:24:45 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2020-07-16 19:02:32 +00:00
|
|
|
inboxId() {
|
|
|
|
return this.currentChat.inbox_id;
|
|
|
|
},
|
|
|
|
inbox() {
|
|
|
|
return this.$store.getters['inboxes/getInbox'](this.inboxId);
|
|
|
|
},
|
|
|
|
messagePlaceHolder() {
|
|
|
|
return this.isPrivate
|
|
|
|
? this.$t('CONVERSATION.FOOTER.PRIVATE_MSG_INPUT')
|
|
|
|
: this.$t('CONVERSATION.FOOTER.MSG_INPUT');
|
|
|
|
},
|
|
|
|
isMessageLengthReachingThreshold() {
|
2021-01-13 13:46:45 +00:00
|
|
|
return this.message.length > this.maxLength - 50;
|
2020-07-16 19:02:32 +00:00
|
|
|
},
|
2021-01-13 13:46:45 +00:00
|
|
|
charactersRemaining() {
|
|
|
|
return this.maxLength - this.message.length;
|
2020-07-16 19:02:32 +00:00
|
|
|
},
|
|
|
|
isReplyButtonDisabled() {
|
2022-01-13 18:54:00 +00:00
|
|
|
if (this.isATweet && !this.inReplyTo && !this.isOnPrivateNote) {
|
2021-08-02 10:37:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-01-06 12:26:29 +00:00
|
|
|
|
|
|
|
if (this.hasAttachments) return false;
|
2021-08-02 10:37:30 +00:00
|
|
|
|
2020-07-16 19:02:32 +00:00
|
|
|
return (
|
2021-08-02 10:37:30 +00:00
|
|
|
this.isMessageEmpty ||
|
2020-07-16 19:02:32 +00:00
|
|
|
this.message.length === 0 ||
|
|
|
|
this.message.length > this.maxLength
|
|
|
|
);
|
|
|
|
},
|
2020-03-05 20:17:37 +00:00
|
|
|
conversationType() {
|
2020-03-09 04:30:11 +00:00
|
|
|
const { additional_attributes: additionalAttributes } = this.currentChat;
|
|
|
|
const type = additionalAttributes ? additionalAttributes.type : '';
|
|
|
|
return type || '';
|
2020-03-05 20:17:37 +00:00
|
|
|
},
|
|
|
|
maxLength() {
|
2020-07-16 19:02:32 +00:00
|
|
|
if (this.isPrivate) {
|
|
|
|
return MESSAGE_MAX_LENGTH.GENERAL;
|
|
|
|
}
|
|
|
|
if (this.isAFacebookInbox) {
|
|
|
|
return MESSAGE_MAX_LENGTH.FACEBOOK;
|
|
|
|
}
|
2021-10-05 18:05:06 +00:00
|
|
|
if (this.isAWhatsappChannel) {
|
2021-05-04 14:01:00 +00:00
|
|
|
return MESSAGE_MAX_LENGTH.TWILIO_WHATSAPP;
|
|
|
|
}
|
2020-07-16 19:02:32 +00:00
|
|
|
if (this.isATwilioSMSChannel) {
|
|
|
|
return MESSAGE_MAX_LENGTH.TWILIO_SMS;
|
2020-03-05 20:17:37 +00:00
|
|
|
}
|
2020-07-16 19:02:32 +00:00
|
|
|
if (this.isATwitterInbox) {
|
2020-03-05 20:17:37 +00:00
|
|
|
if (this.conversationType === 'tweet') {
|
2021-08-02 10:37:30 +00:00
|
|
|
return MESSAGE_MAX_LENGTH.TWEET - this.replyToUserLength - 2;
|
2020-03-05 20:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-16 19:02:32 +00:00
|
|
|
return MESSAGE_MAX_LENGTH.GENERAL;
|
2020-03-05 20:17:37 +00:00
|
|
|
},
|
2020-07-16 19:02:32 +00:00
|
|
|
showFileUpload() {
|
|
|
|
return (
|
|
|
|
this.isAWebWidgetInbox ||
|
|
|
|
this.isAFacebookInbox ||
|
2021-11-11 07:33:48 +00:00
|
|
|
this.isAWhatsappChannel ||
|
2021-08-31 13:36:12 +00:00
|
|
|
this.isAPIInbox ||
|
2021-09-06 18:35:14 +00:00
|
|
|
this.isAnEmailChannel ||
|
2021-09-30 20:15:29 +00:00
|
|
|
this.isATwilioSMSChannel ||
|
|
|
|
this.isATelegramChannel
|
2020-07-16 19:02:32 +00:00
|
|
|
);
|
|
|
|
},
|
2020-03-05 20:17:37 +00:00
|
|
|
replyButtonLabel() {
|
|
|
|
if (this.isPrivate) {
|
|
|
|
return this.$t('CONVERSATION.REPLYBOX.CREATE');
|
|
|
|
}
|
|
|
|
if (this.conversationType === 'tweet') {
|
|
|
|
return this.$t('CONVERSATION.REPLYBOX.TWEET');
|
|
|
|
}
|
|
|
|
return this.$t('CONVERSATION.REPLYBOX.SEND');
|
|
|
|
},
|
2020-07-04 08:20:44 +00:00
|
|
|
replyBoxClass() {
|
|
|
|
return {
|
2021-01-13 12:36:25 +00:00
|
|
|
'is-private': this.isPrivate,
|
2021-01-06 12:26:29 +00:00
|
|
|
'is-focused': this.isFocused || this.hasAttachments,
|
2020-07-04 08:20:44 +00:00
|
|
|
};
|
|
|
|
},
|
2021-01-06 12:26:29 +00:00
|
|
|
hasAttachments() {
|
|
|
|
return this.attachedFiles.length;
|
|
|
|
},
|
2021-01-18 05:50:19 +00:00
|
|
|
isRichEditorEnabled() {
|
2021-04-16 13:33:46 +00:00
|
|
|
return this.isAWebWidgetInbox || this.isAnEmailChannel;
|
2021-01-18 05:50:19 +00:00
|
|
|
},
|
2021-01-26 18:34:11 +00:00
|
|
|
isOnPrivateNote() {
|
|
|
|
return this.replyType === REPLY_EDITOR_MODES.NOTE;
|
|
|
|
},
|
2021-08-02 10:37:30 +00:00
|
|
|
inReplyTo() {
|
|
|
|
const selectedTweet = this.selectedTweet || {};
|
|
|
|
return selectedTweet.id;
|
|
|
|
},
|
|
|
|
replyToUserLength() {
|
|
|
|
const selectedTweet = this.selectedTweet || {};
|
|
|
|
const {
|
|
|
|
sender: {
|
|
|
|
additional_attributes: { screen_name: screenName = '' } = {},
|
|
|
|
} = {},
|
|
|
|
} = selectedTweet;
|
|
|
|
return screenName ? screenName.length : 0;
|
|
|
|
},
|
2021-07-27 02:08:27 +00:00
|
|
|
isMessageEmpty() {
|
2021-08-02 10:37:30 +00:00
|
|
|
if (!this.message) {
|
|
|
|
return true;
|
2021-07-27 02:08:27 +00:00
|
|
|
}
|
|
|
|
return !this.message.trim().replace(/\n/g, '').length;
|
|
|
|
},
|
2021-10-14 07:25:46 +00:00
|
|
|
showReplyHead() {
|
|
|
|
return !this.isOnPrivateNote && this.isAnEmailChannel;
|
2021-10-11 07:30:48 +00:00
|
|
|
},
|
2022-01-25 02:46:58 +00:00
|
|
|
enableMultipleFileUpload() {
|
|
|
|
return this.isAnEmailChannel || this.isAWebWidgetInbox || this.isAPIInbox;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2020-07-25 17:24:45 +00:00
|
|
|
currentChat(conversation) {
|
2021-01-13 12:36:25 +00:00
|
|
|
const { can_reply: canReply } = conversation;
|
2021-01-26 18:34:11 +00:00
|
|
|
if (this.isOnPrivateNote) {
|
2021-01-19 13:58:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-05 18:05:06 +00:00
|
|
|
if (canReply || this.isAWhatsappChannel) {
|
2021-01-13 12:36:25 +00:00
|
|
|
this.replyType = REPLY_EDITOR_MODES.REPLY;
|
2020-07-25 17:24:45 +00:00
|
|
|
} else {
|
2021-01-13 12:36:25 +00:00
|
|
|
this.replyType = REPLY_EDITOR_MODES.NOTE;
|
2020-07-25 17:24:45 +00:00
|
|
|
}
|
|
|
|
},
|
2020-07-16 19:02:32 +00:00
|
|
|
message(updatedMessage) {
|
2021-06-02 04:50:40 +00:00
|
|
|
this.hasSlashCommand =
|
|
|
|
updatedMessage[0] === '/' && !this.showRichContentEditor;
|
2020-07-16 19:02:32 +00:00
|
|
|
const hasNextWord = updatedMessage.includes(' ');
|
2021-01-26 18:34:11 +00:00
|
|
|
const isShortCodeActive = this.hasSlashCommand && !hasNextWord;
|
2019-08-14 09:48:44 +00:00
|
|
|
if (isShortCodeActive) {
|
2021-01-26 18:34:11 +00:00
|
|
|
this.mentionSearchKey = updatedMessage.substr(1, updatedMessage.length);
|
|
|
|
this.showMentions = true;
|
2019-08-14 09:48:44 +00:00
|
|
|
} else {
|
2021-01-26 18:34:11 +00:00
|
|
|
this.mentionSearchKey = '';
|
|
|
|
this.showMentions = false;
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-09-15 14:45:06 +00:00
|
|
|
|
|
|
|
mounted() {
|
|
|
|
// Donot use the keyboard listener mixin here as the events here are supposed to be
|
|
|
|
// working even if input/textarea is focussed.
|
|
|
|
document.addEventListener('keydown', this.handleKeyEvents);
|
2021-11-02 04:35:49 +00:00
|
|
|
document.addEventListener('paste', this.onPaste);
|
2021-09-15 14:45:06 +00:00
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
document.removeEventListener('keydown', this.handleKeyEvents);
|
2021-11-02 04:35:49 +00:00
|
|
|
document.removeEventListener('paste', this.onPaste);
|
2021-09-15 14:45:06 +00:00
|
|
|
},
|
2019-11-17 08:45:05 +00:00
|
|
|
methods: {
|
2021-11-02 04:35:49 +00:00
|
|
|
onPaste(e) {
|
|
|
|
const data = e.clipboardData.files;
|
|
|
|
if (!data.length || !data[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const file = data[0];
|
|
|
|
const { name, type, size } = file;
|
|
|
|
this.onFileUpload({ name, type, size, file });
|
|
|
|
},
|
2021-01-26 18:34:11 +00:00
|
|
|
toggleUserMention(currentMentionState) {
|
|
|
|
this.hasUserMention = currentMentionState;
|
|
|
|
},
|
2021-06-02 04:50:40 +00:00
|
|
|
toggleCannedMenu(value) {
|
|
|
|
this.showCannedMenu = value;
|
|
|
|
},
|
2019-11-17 08:45:05 +00:00
|
|
|
handleKeyEvents(e) {
|
2020-07-16 19:02:32 +00:00
|
|
|
if (isEscape(e)) {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.hideEmojiPicker();
|
2021-01-26 18:34:11 +00:00
|
|
|
this.hideMentions();
|
2020-07-16 19:02:32 +00:00
|
|
|
} else if (isEnter(e)) {
|
2021-01-19 13:58:40 +00:00
|
|
|
const hasSendOnEnterEnabled =
|
2021-01-26 18:34:11 +00:00
|
|
|
(this.showRichContentEditor &&
|
|
|
|
this.enterToSendEnabled &&
|
2021-06-02 04:50:40 +00:00
|
|
|
!this.hasUserMention &&
|
|
|
|
!this.showCannedMenu) ||
|
2021-01-26 18:34:11 +00:00
|
|
|
!this.showRichContentEditor;
|
2021-01-18 05:50:19 +00:00
|
|
|
const shouldSendMessage =
|
2021-01-19 13:58:40 +00:00
|
|
|
hasSendOnEnterEnabled && !hasPressedShift(e) && this.isFocused;
|
2021-01-18 05:50:19 +00:00
|
|
|
if (shouldSendMessage) {
|
2019-10-27 05:18:26 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.sendMessage();
|
|
|
|
}
|
2022-01-27 12:27:33 +00:00
|
|
|
} else if (hasPressedCommandPlusKKey(e)) {
|
|
|
|
this.openCommandBar();
|
2019-10-27 05:18:26 +00:00
|
|
|
}
|
2019-11-17 08:45:05 +00:00
|
|
|
},
|
2022-01-27 12:27:33 +00:00
|
|
|
openCommandBar() {
|
|
|
|
const ninja = document.querySelector('ninja-keys');
|
|
|
|
ninja.open();
|
|
|
|
},
|
2021-01-19 13:58:40 +00:00
|
|
|
toggleEnterToSend(enterToSendEnabled) {
|
2021-02-07 07:24:32 +00:00
|
|
|
this.updateUISettings({ enter_to_send_enabled: enterToSendEnabled });
|
2021-01-19 13:58:40 +00:00
|
|
|
},
|
2022-02-07 06:57:20 +00:00
|
|
|
onClickSelfAssign() {
|
|
|
|
const {
|
|
|
|
account_id,
|
|
|
|
availability_status,
|
|
|
|
available_name,
|
|
|
|
email,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
role,
|
|
|
|
avatar_url,
|
|
|
|
} = this.currentUser;
|
|
|
|
const selfAssign = {
|
|
|
|
account_id,
|
|
|
|
availability_status,
|
|
|
|
available_name,
|
|
|
|
email,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
role,
|
|
|
|
thumbnail: avatar_url,
|
|
|
|
};
|
|
|
|
this.assignedAgent = selfAssign;
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
async sendMessage() {
|
2020-07-16 19:02:32 +00:00
|
|
|
if (this.isReplyButtonDisabled) {
|
2020-05-17 18:14:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-26 18:34:11 +00:00
|
|
|
if (!this.showMentions) {
|
2021-01-06 12:26:29 +00:00
|
|
|
const newMessage = this.message;
|
|
|
|
const messagePayload = this.getMessagePayload(newMessage);
|
2020-07-02 06:28:02 +00:00
|
|
|
this.clearMessage();
|
2020-03-22 10:24:36 +00:00
|
|
|
try {
|
2021-12-20 18:37:33 +00:00
|
|
|
await this.$store.dispatch(
|
|
|
|
'createPendingMessageAndSend',
|
|
|
|
messagePayload
|
|
|
|
);
|
2021-11-30 05:15:36 +00:00
|
|
|
this.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE);
|
2020-03-22 10:24:36 +00:00
|
|
|
} catch (error) {
|
2021-09-29 07:30:08 +00:00
|
|
|
const errorMessage =
|
|
|
|
error?.response?.data?.error ||
|
|
|
|
this.$t('CONVERSATION.MESSAGE_ERROR');
|
|
|
|
this.showAlert(errorMessage);
|
2020-03-22 10:24:36 +00:00
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
this.hideEmojiPicker();
|
2021-12-13 07:07:21 +00:00
|
|
|
this.$emit('update:popoutReplyBox', false);
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
replaceText(message) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.message = message;
|
2019-11-17 08:45:05 +00:00
|
|
|
}, 100);
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2021-01-13 12:36:25 +00:00
|
|
|
setReplyMode(mode = REPLY_EDITOR_MODES.REPLY) {
|
|
|
|
const { can_reply: canReply } = this.currentChat;
|
|
|
|
|
2021-10-05 18:05:06 +00:00
|
|
|
if (canReply || this.isAWhatsappChannel) this.replyType = mode;
|
2021-02-07 07:24:32 +00:00
|
|
|
if (this.showRichContentEditor) {
|
2021-08-09 07:38:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-07 07:24:32 +00:00
|
|
|
this.$nextTick(() => this.$refs.messageInput.focus());
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
emojiOnClick(emoji) {
|
2020-09-13 17:19:01 +00:00
|
|
|
this.message = `${this.message}${emoji} `;
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
clearMessage() {
|
|
|
|
this.message = '';
|
2021-01-06 12:26:29 +00:00
|
|
|
this.attachedFiles = [];
|
2021-12-07 18:14:32 +00:00
|
|
|
this.ccEmails = '';
|
|
|
|
this.bccEmails = '';
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
toggleEmojiPicker() {
|
|
|
|
this.showEmojiPicker = !this.showEmojiPicker;
|
|
|
|
},
|
|
|
|
hideEmojiPicker() {
|
|
|
|
if (this.showEmojiPicker) {
|
|
|
|
this.toggleEmojiPicker();
|
|
|
|
}
|
|
|
|
},
|
2021-01-26 18:34:11 +00:00
|
|
|
hideMentions() {
|
|
|
|
this.showMentions = false;
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2020-11-26 18:47:55 +00:00
|
|
|
onTypingOn() {
|
|
|
|
this.toggleTyping('on');
|
|
|
|
},
|
|
|
|
onTypingOff() {
|
|
|
|
this.toggleTyping('off');
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
onBlur() {
|
2020-07-04 08:20:44 +00:00
|
|
|
this.isFocused = false;
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2020-05-04 17:37:56 +00:00
|
|
|
onFocus() {
|
2020-07-04 08:20:44 +00:00
|
|
|
this.isFocused = true;
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2019-10-27 13:31:59 +00:00
|
|
|
toggleTyping(status) {
|
2021-08-23 16:04:23 +00:00
|
|
|
const conversationId = this.currentChat.id;
|
2021-11-01 08:20:07 +00:00
|
|
|
const isPrivate = this.isPrivate;
|
2021-08-23 16:04:23 +00:00
|
|
|
this.$store.dispatch('conversationTypingStatus/toggleTyping', {
|
|
|
|
status,
|
|
|
|
conversationId,
|
2021-11-01 08:20:07 +00:00
|
|
|
isPrivate,
|
2021-08-23 16:04:23 +00:00
|
|
|
});
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2022-01-27 10:27:22 +00:00
|
|
|
onDirectFileUpload(file) {
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (checkFileSizeLimit(file, MAXIMUM_FILE_UPLOAD_SIZE)) {
|
2022-02-01 06:55:51 +00:00
|
|
|
const upload = new DirectUpload(
|
|
|
|
file.file,
|
|
|
|
'/rails/active_storage/direct_uploads',
|
|
|
|
null,
|
|
|
|
file.file.name
|
|
|
|
);
|
2022-01-27 10:27:22 +00:00
|
|
|
upload.create((error, blob) => {
|
|
|
|
if (error) {
|
2022-02-01 06:55:51 +00:00
|
|
|
this.showAlert(error);
|
2022-01-27 10:27:22 +00:00
|
|
|
} else {
|
|
|
|
this.attachedFiles.push({
|
|
|
|
currentChatId: this.currentChat.id,
|
|
|
|
resource: blob,
|
|
|
|
isPrivate: this.isPrivate,
|
|
|
|
thumb: null,
|
|
|
|
blobSignedId: blob.signed_id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.showAlert(
|
|
|
|
this.$t('CONVERSATION.FILE_SIZE_LIMIT', {
|
|
|
|
MAXIMUM_FILE_UPLOAD_SIZE,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
onFileUpload(file) {
|
2020-04-29 20:11:13 +00:00
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-15 16:58:19 +00:00
|
|
|
if (checkFileSizeLimit(file, MAXIMUM_FILE_UPLOAD_SIZE)) {
|
|
|
|
this.attachedFiles = [];
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsDataURL(file.file);
|
|
|
|
reader.onloadend = () => {
|
|
|
|
this.attachedFiles.push({
|
|
|
|
currentChatId: this.currentChat.id,
|
|
|
|
resource: file,
|
|
|
|
isPrivate: this.isPrivate,
|
|
|
|
thumb: reader.result,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.showAlert(
|
|
|
|
this.$t('CONVERSATION.FILE_SIZE_LIMIT', {
|
|
|
|
MAXIMUM_FILE_UPLOAD_SIZE,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2021-01-06 12:26:29 +00:00
|
|
|
},
|
|
|
|
removeAttachment(itemIndex) {
|
|
|
|
this.attachedFiles = this.attachedFiles.filter(
|
|
|
|
(item, index) => itemIndex !== index
|
|
|
|
);
|
|
|
|
},
|
|
|
|
getMessagePayload(message) {
|
|
|
|
const messagePayload = {
|
|
|
|
conversationId: this.currentChat.id,
|
|
|
|
message,
|
|
|
|
private: this.isPrivate,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.inReplyTo) {
|
|
|
|
messagePayload.contentAttributes = { in_reply_to: this.inReplyTo };
|
|
|
|
}
|
|
|
|
|
2022-01-25 02:46:58 +00:00
|
|
|
if (this.attachedFiles && this.attachedFiles.length) {
|
|
|
|
messagePayload.files = [];
|
|
|
|
this.attachedFiles.forEach(attachment => {
|
2022-01-27 10:27:22 +00:00
|
|
|
messagePayload.files.push(attachment.blobSignedId);
|
2022-01-25 02:46:58 +00:00
|
|
|
});
|
2021-01-06 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 07:25:46 +00:00
|
|
|
if (this.ccEmails) {
|
2021-10-11 07:30:48 +00:00
|
|
|
messagePayload.ccEmails = this.ccEmails;
|
|
|
|
}
|
|
|
|
|
2021-10-14 07:25:46 +00:00
|
|
|
if (this.bccEmails) {
|
2021-10-11 07:30:48 +00:00
|
|
|
messagePayload.bccEmails = this.bccEmails;
|
|
|
|
}
|
|
|
|
|
2021-01-06 12:26:29 +00:00
|
|
|
return messagePayload;
|
2020-03-22 10:24:36 +00:00
|
|
|
},
|
2021-01-18 05:50:19 +00:00
|
|
|
setFormatMode(value) {
|
2021-02-07 07:24:32 +00:00
|
|
|
this.updateUISettings({ display_rich_content_editor: value });
|
2021-01-18 05:50:19 +00:00
|
|
|
},
|
2021-10-11 07:30:48 +00:00
|
|
|
setCcEmails(value) {
|
|
|
|
this.bccEmails = value.bccEmails;
|
2021-10-14 07:25:46 +00:00
|
|
|
this.ccEmails = value.ccEmails;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2021-01-13 12:36:25 +00:00
|
|
|
<style lang="scss" scoped>
|
2019-10-27 05:18:26 +00:00
|
|
|
.send-button {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
2021-01-13 12:36:25 +00:00
|
|
|
|
2021-01-06 12:26:29 +00:00
|
|
|
.attachment-preview-box {
|
2021-01-13 12:36:25 +00:00
|
|
|
padding: 0 var(--space-normal);
|
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reply-box {
|
|
|
|
border-top: 1px solid var(--color-border);
|
|
|
|
background: white;
|
|
|
|
|
|
|
|
&.is-private {
|
|
|
|
background: var(--y-50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.send-button {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reply-box__top {
|
|
|
|
padding: 0 var(--space-normal);
|
|
|
|
border-top: 1px solid var(--color-border);
|
|
|
|
margin-top: -1px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.emoji-dialog {
|
|
|
|
top: unset;
|
|
|
|
bottom: 12px;
|
|
|
|
left: -320px;
|
|
|
|
right: unset;
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
right: -16px;
|
|
|
|
bottom: 10px;
|
|
|
|
transform: rotate(270deg);
|
|
|
|
filter: drop-shadow(0px 4px 4px rgba(0, 0, 0, 0.08));
|
|
|
|
}
|
2021-01-06 12:26:29 +00:00
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
</style>
|