2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2020-07-04 08:20:44 +00:00
|
|
|
<div class="reply-box" :class="replyBoxClass">
|
2019-10-27 05:18:26 +00:00
|
|
|
<div class="reply-box__top" :class="{ 'is-private': isPrivate }">
|
2019-08-14 09:48:44 +00:00
|
|
|
<canned-response
|
2019-11-17 08:45:05 +00:00
|
|
|
v-if="showCannedResponsesList"
|
2019-08-14 09:48:44 +00:00
|
|
|
v-on-clickaway="hideCannedResponse"
|
|
|
|
data-dropdown-menu
|
|
|
|
:on-keyenter="replaceText"
|
|
|
|
:on-click="replaceText"
|
|
|
|
/>
|
2019-10-27 05:18:26 +00:00
|
|
|
<emoji-input
|
|
|
|
v-if="showEmojiPicker"
|
|
|
|
v-on-clickaway="hideEmojiPicker"
|
|
|
|
:on-click="emojiOnClick"
|
|
|
|
/>
|
2020-06-18 09:47:45 +00:00
|
|
|
<resizable-text-area
|
2019-10-27 05:18:26 +00:00
|
|
|
ref="messageInput"
|
2020-07-20 12:09:36 +00:00
|
|
|
v-model="message"
|
2019-08-14 09:48:44 +00:00
|
|
|
class="input"
|
2020-07-16 19:02:32 +00:00
|
|
|
:placeholder="messagePlaceHolder"
|
2020-06-18 09:47:45 +00:00
|
|
|
:min-height="4"
|
2020-05-04 17:37:56 +00:00
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
2019-08-14 09:48:44 +00:00
|
|
|
/>
|
2020-03-22 10:24:36 +00:00
|
|
|
<file-upload
|
2020-04-02 06:58:38 +00:00
|
|
|
v-if="showFileUpload"
|
|
|
|
:size="4096 * 4096"
|
2020-07-16 19:02:32 +00:00
|
|
|
accept="image/*, application/pdf, audio/mpeg, video/mp4, audio/ogg"
|
2020-03-22 10:24:36 +00:00
|
|
|
@input-file="onFileUpload"
|
|
|
|
>
|
2020-07-16 19:02:32 +00:00
|
|
|
<i v-if="!isUploading" class="icon ion-android-attach attachment" />
|
|
|
|
<woot-spinner v-if="isUploading" />
|
2020-03-22 10:24:36 +00:00
|
|
|
</file-upload>
|
2019-10-27 05:18:26 +00:00
|
|
|
<i
|
|
|
|
class="icon ion-happy-outline"
|
|
|
|
:class="{ active: showEmojiPicker }"
|
2020-07-16 19:02:32 +00:00
|
|
|
@click="toggleEmojiPicker"
|
2019-12-16 12:53:14 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
</div>
|
|
|
|
|
2019-10-27 05:18:26 +00:00
|
|
|
<div class="reply-box__bottom">
|
2019-08-14 09:48:44 +00:00
|
|
|
<ul class="tabs">
|
2019-10-27 05:18:26 +00:00
|
|
|
<li class="tabs-title" :class="{ 'is-active': !isPrivate }">
|
2020-07-16 19:02:32 +00:00
|
|
|
<a href="#" @click="setReplyMode">{{
|
2020-03-05 20:17:37 +00:00
|
|
|
$t('CONVERSATION.REPLYBOX.REPLY')
|
|
|
|
}}</a>
|
2019-08-14 09:48:44 +00:00
|
|
|
</li>
|
2019-10-27 05:18:26 +00:00
|
|
|
<li class="tabs-title is-private" :class="{ 'is-active': isPrivate }">
|
2020-07-16 19:02:32 +00:00
|
|
|
<a href="#" @click="setPrivateReplyMode">{{
|
2020-03-05 20:17:37 +00:00
|
|
|
$t('CONVERSATION.REPLYBOX.PRIVATE_NOTE')
|
|
|
|
}}</a>
|
2019-08-14 09:48:44 +00:00
|
|
|
</li>
|
2019-10-27 05:18:26 +00:00
|
|
|
<li v-if="message.length" class="tabs-title message-length">
|
2020-07-16 19:02:32 +00:00
|
|
|
<a :class="{ 'message-error': isMessageLengthReachingThreshold }">{{
|
|
|
|
characterCountIndicator
|
|
|
|
}}</a>
|
2019-08-14 09:48:44 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="button send-button"
|
2020-07-16 19:02:32 +00:00
|
|
|
:disabled="isReplyButtonDisabled"
|
2019-10-27 05:18:26 +00:00
|
|
|
:class="{
|
2020-07-16 19:02:32 +00:00
|
|
|
disabled: isReplyButtonDisabled,
|
2019-10-27 05:18:26 +00:00
|
|
|
warning: isPrivate,
|
|
|
|
}"
|
|
|
|
@click="sendMessage"
|
2019-08-14 09:48:44 +00:00
|
|
|
>
|
2020-03-05 20:17:37 +00:00
|
|
|
{{ replyButtonLabel }}
|
2019-10-27 05:18:26 +00:00
|
|
|
<i
|
|
|
|
class="icon"
|
|
|
|
:class="{
|
|
|
|
'ion-android-send': !isPrivate,
|
|
|
|
'ion-android-lock': isPrivate,
|
|
|
|
}"
|
2019-12-16 12:53:14 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
/* eslint no-console: 0 */
|
|
|
|
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import emojione from 'emojione';
|
|
|
|
import { mixin as clickaway } from 'vue-clickaway';
|
2020-03-22 10:24:36 +00:00
|
|
|
import FileUpload from 'vue-upload-component';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
import EmojiInput from '../emoji/EmojiInput';
|
|
|
|
import CannedResponse from './CannedResponse';
|
2020-06-18 09:47:45 +00:00
|
|
|
import ResizableTextArea from 'shared/components/ResizableTextArea';
|
2020-07-16 19:02:32 +00:00
|
|
|
import {
|
|
|
|
isEscape,
|
|
|
|
isEnter,
|
|
|
|
hasPressedShift,
|
|
|
|
} from 'shared/helpers/KeyboardHelpers';
|
|
|
|
import { MESSAGE_MAX_LENGTH } from 'shared/helpers/MessageTypeHelper';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
2020-03-05 20:17:37 +00:00
|
|
|
components: {
|
|
|
|
EmojiInput,
|
|
|
|
CannedResponse,
|
2020-03-22 10:24:36 +00:00
|
|
|
FileUpload,
|
2020-06-18 09:47:45 +00:00
|
|
|
ResizableTextArea,
|
2020-03-05 20:17:37 +00:00
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
mixins: [clickaway],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
message: '',
|
2019-10-27 07:44:36 +00:00
|
|
|
isPrivate: false,
|
2020-07-04 08:20:44 +00:00
|
|
|
isFocused: false,
|
2019-08-14 09:48:44 +00:00
|
|
|
showEmojiPicker: false,
|
2019-11-17 08:45:05 +00:00
|
|
|
showCannedResponsesList: false,
|
2020-07-16 19:02:32 +00:00
|
|
|
isUploading: false,
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
},
|
2019-11-17 08:45:05 +00:00
|
|
|
computed: {
|
2020-07-16 19:02:32 +00:00
|
|
|
...mapGetters({ currentChat: 'getSelectedChat' }),
|
|
|
|
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() {
|
|
|
|
return this.message.length > this.maxLength - 40;
|
|
|
|
},
|
|
|
|
characterCountIndicator() {
|
|
|
|
return `${this.message.length} / ${this.maxLength}`;
|
|
|
|
},
|
|
|
|
isReplyButtonDisabled() {
|
2020-07-20 12:09:36 +00:00
|
|
|
const isMessageEmpty = !this.message.trim().replace(/\n/g, '').length;
|
2020-07-16 19:02:32 +00:00
|
|
|
return (
|
|
|
|
isMessageEmpty ||
|
|
|
|
this.message.length === 0 ||
|
|
|
|
this.message.length > this.maxLength
|
|
|
|
);
|
|
|
|
},
|
2019-11-17 08:45:05 +00:00
|
|
|
channelType() {
|
2020-07-16 19:02:32 +00:00
|
|
|
return this.inbox.channel_type;
|
2019-11-17 08:45:05 +00:00
|
|
|
},
|
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;
|
|
|
|
}
|
|
|
|
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') {
|
2020-07-16 19:02:32 +00:00
|
|
|
return MESSAGE_MAX_LENGTH.TWEET;
|
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
|
|
|
isATwitterInbox() {
|
|
|
|
return this.channelType === 'Channel::TwitterProfile';
|
|
|
|
},
|
|
|
|
isAFacebookInbox() {
|
|
|
|
return this.channelType === 'Channel::FacebookPage';
|
|
|
|
},
|
|
|
|
isAWebWidgetInbox() {
|
2020-07-04 14:16:17 +00:00
|
|
|
return this.channelType === 'Channel::WebWidget';
|
2020-04-02 06:58:38 +00:00
|
|
|
},
|
2020-07-16 19:02:32 +00:00
|
|
|
isATwilioSMSChannel() {
|
|
|
|
const { phone_number: phoneNumber = '' } = this.inbox;
|
|
|
|
return (
|
|
|
|
this.channelType === 'Channel::TwilioSms' &&
|
|
|
|
!phoneNumber.startsWith('whatsapp')
|
|
|
|
);
|
|
|
|
},
|
|
|
|
isATwilioWhatsappChannel() {
|
|
|
|
const { phone_number: phoneNumber = '' } = this.inbox;
|
|
|
|
return (
|
|
|
|
this.channelType === 'Channel::TwilioSms' &&
|
|
|
|
phoneNumber.startsWith('whatsapp')
|
|
|
|
);
|
|
|
|
},
|
|
|
|
showFileUpload() {
|
|
|
|
return (
|
|
|
|
this.isAWebWidgetInbox ||
|
|
|
|
this.isAFacebookInbox ||
|
|
|
|
this.isATwilioWhatsappChannel
|
|
|
|
);
|
|
|
|
},
|
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 {
|
|
|
|
'is-focused': this.isFocused,
|
|
|
|
};
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2020-07-16 19:02:32 +00:00
|
|
|
message(updatedMessage) {
|
2019-10-27 07:44:36 +00:00
|
|
|
if (this.isPrivate) {
|
2019-08-14 09:48:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-16 19:02:32 +00:00
|
|
|
const isSlashCommand = updatedMessage[0] === '/';
|
|
|
|
const hasNextWord = updatedMessage.includes(' ');
|
2019-08-14 09:48:44 +00:00
|
|
|
const isShortCodeActive = isSlashCommand && !hasNextWord;
|
|
|
|
if (isShortCodeActive) {
|
2019-11-17 08:45:05 +00:00
|
|
|
this.showCannedResponsesList = true;
|
2020-07-16 19:02:32 +00:00
|
|
|
if (updatedMessage.length > 1) {
|
|
|
|
const searchKey = updatedMessage.substr(1, updatedMessage.length);
|
|
|
|
this.$store.dispatch('getCannedResponse', { searchKey });
|
2019-08-14 09:48:44 +00:00
|
|
|
} else {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.$store.dispatch('getCannedResponse');
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-17 08:45:05 +00:00
|
|
|
this.showCannedResponsesList = false;
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2019-10-27 05:18:26 +00:00
|
|
|
mounted() {
|
2019-11-17 08:45:05 +00:00
|
|
|
document.addEventListener('keydown', this.handleKeyEvents);
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
document.removeEventListener('keydown', this.handleKeyEvents);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleKeyEvents(e) {
|
2020-07-16 19:02:32 +00:00
|
|
|
if (isEscape(e)) {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.hideEmojiPicker();
|
|
|
|
this.hideCannedResponse();
|
2020-07-16 19:02:32 +00:00
|
|
|
} else if (isEnter(e)) {
|
|
|
|
if (!hasPressedShift(e)) {
|
2019-10-27 05:18:26 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.sendMessage();
|
|
|
|
}
|
|
|
|
}
|
2019-11-17 08:45:05 +00:00
|
|
|
},
|
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;
|
|
|
|
}
|
2020-07-02 06:28:02 +00:00
|
|
|
const newMessage = this.message;
|
2019-11-17 08:45:05 +00:00
|
|
|
if (!this.showCannedResponsesList) {
|
2020-07-02 06:28:02 +00:00
|
|
|
this.clearMessage();
|
2020-03-22 10:24:36 +00:00
|
|
|
try {
|
|
|
|
await this.$store.dispatch('sendMessage', {
|
2019-10-27 13:31:59 +00:00
|
|
|
conversationId: this.currentChat.id,
|
2020-07-02 06:28:02 +00:00
|
|
|
message: newMessage,
|
2019-10-27 13:31:59 +00:00
|
|
|
private: this.isPrivate,
|
2019-10-27 05:18:26 +00:00
|
|
|
});
|
2020-03-22 10:24:36 +00:00
|
|
|
this.$emit('scrollToMessage');
|
|
|
|
} catch (error) {
|
|
|
|
// Error
|
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
this.hideEmojiPicker();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
replaceText(message) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.message = message;
|
2019-11-17 08:45:05 +00:00
|
|
|
}, 100);
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2020-07-16 19:02:32 +00:00
|
|
|
setPrivateReplyMode() {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.isPrivate = true;
|
2019-08-14 09:48:44 +00:00
|
|
|
this.$refs.messageInput.focus();
|
|
|
|
},
|
2020-07-16 19:02:32 +00:00
|
|
|
setReplyMode() {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.isPrivate = false;
|
2019-08-14 09:48:44 +00:00
|
|
|
this.$refs.messageInput.focus();
|
|
|
|
},
|
|
|
|
emojiOnClick(emoji) {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.message = emojione.shortnameToUnicode(
|
|
|
|
`${this.message}${emoji.shortname} `
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
clearMessage() {
|
|
|
|
this.message = '';
|
|
|
|
},
|
|
|
|
toggleEmojiPicker() {
|
|
|
|
this.showEmojiPicker = !this.showEmojiPicker;
|
|
|
|
},
|
|
|
|
hideEmojiPicker() {
|
|
|
|
if (this.showEmojiPicker) {
|
|
|
|
this.toggleEmojiPicker();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hideCannedResponse() {
|
2019-11-17 08:45:05 +00:00
|
|
|
this.showCannedResponsesList = false;
|
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
|
|
|
this.toggleTyping('off');
|
|
|
|
},
|
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
|
|
|
this.toggleTyping('on');
|
|
|
|
},
|
2019-10-27 13:31:59 +00:00
|
|
|
toggleTyping(status) {
|
2020-07-16 19:02:32 +00:00
|
|
|
if (this.isAWebWidgetInbox && !this.isPrivate) {
|
2020-05-04 17:37:56 +00:00
|
|
|
const conversationId = this.currentChat.id;
|
2020-06-14 08:37:52 +00:00
|
|
|
this.$store.dispatch('conversationTypingStatus/toggleTyping', {
|
2019-11-17 08:45:05 +00:00
|
|
|
status,
|
2020-05-04 17:37:56 +00:00
|
|
|
conversationId,
|
2019-11-17 08:45:05 +00:00
|
|
|
});
|
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
onFileUpload(file) {
|
2020-04-29 20:11:13 +00:00
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-16 19:02:32 +00:00
|
|
|
this.isUploading = true;
|
2020-03-22 10:24:36 +00:00
|
|
|
this.$store
|
2020-04-02 06:58:38 +00:00
|
|
|
.dispatch('sendAttachment', [this.currentChat.id, { file: file.file }])
|
2020-03-22 10:24:36 +00:00
|
|
|
.then(() => {
|
2020-07-16 19:02:32 +00:00
|
|
|
this.isUploading = false;
|
2020-03-22 10:24:36 +00:00
|
|
|
this.$emit('scrollToMessage');
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2020-07-16 19:02:32 +00:00
|
|
|
this.isUploading = false;
|
2020-03-22 10:24:36 +00:00
|
|
|
this.$emit('scrollToMessage');
|
|
|
|
});
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2019-10-27 05:18:26 +00:00
|
|
|
.send-button {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
</style>
|