2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
|
|
|
<div class="reply-box">
|
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"
|
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
<textarea
|
2019-10-27 05:18:26 +00:00
|
|
|
ref="messageInput"
|
2019-08-14 09:48:44 +00:00
|
|
|
v-model="message"
|
2019-10-27 05:18:26 +00:00
|
|
|
rows="1"
|
2019-08-14 09:48:44 +00:00
|
|
|
class="input"
|
|
|
|
type="text"
|
2019-10-27 05:18:26 +00:00
|
|
|
:placeholder="$t(messagePlaceHolder())"
|
2019-08-14 09:48:44 +00:00
|
|
|
@click="onClick()"
|
|
|
|
@blur="onBlur()"
|
|
|
|
/>
|
2020-03-22 10:24:36 +00:00
|
|
|
<file-upload
|
|
|
|
v-if="!showFileUpload"
|
|
|
|
accept="image/*"
|
|
|
|
@input-file="onFileUpload"
|
|
|
|
>
|
|
|
|
<i
|
|
|
|
v-if="!isUploading.image"
|
|
|
|
class="icon ion-android-attach attachment"
|
|
|
|
/>
|
|
|
|
<woot-spinner v-if="isUploading.image" />
|
|
|
|
</file-upload>
|
2019-10-27 05:18:26 +00:00
|
|
|
<i
|
|
|
|
class="icon ion-happy-outline"
|
|
|
|
:class="{ active: showEmojiPicker }"
|
|
|
|
@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-03-05 20:17:37 +00:00
|
|
|
<a href="#" @click="makeReply">{{
|
|
|
|
$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-03-05 20:17:37 +00:00
|
|
|
<a href="#" @click="makePrivate">{{
|
|
|
|
$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-03-05 20:17:37 +00:00
|
|
|
<a :class="{ 'message-error': message.length > maxLength - 40 }">
|
|
|
|
{{ message.length }} / {{ maxLength }}
|
2019-10-27 05:18:26 +00:00
|
|
|
</a>
|
2019-08-14 09:48:44 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="button send-button"
|
|
|
|
:disabled="disableButton()"
|
2019-10-27 05:18:26 +00:00
|
|
|
:class="{
|
2020-03-05 20:17:37 +00:00
|
|
|
disabled: message.length === 0 || message.length > maxLength,
|
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';
|
|
|
|
|
|
|
|
export default {
|
2020-03-05 20:17:37 +00:00
|
|
|
components: {
|
|
|
|
EmojiInput,
|
|
|
|
CannedResponse,
|
2020-03-22 10:24:36 +00:00
|
|
|
FileUpload,
|
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,
|
2019-08-14 09:48:44 +00:00
|
|
|
showEmojiPicker: false,
|
2020-03-22 10:24:36 +00:00
|
|
|
showFileUpload: false,
|
2019-11-17 08:45:05 +00:00
|
|
|
showCannedResponsesList: false,
|
2020-03-22 10:24:36 +00:00
|
|
|
isUploading: {
|
|
|
|
audio: false,
|
|
|
|
video: false,
|
|
|
|
image: false,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
},
|
2019-11-17 08:45:05 +00:00
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
currentChat: 'getSelectedChat',
|
|
|
|
}),
|
|
|
|
channelType() {
|
|
|
|
const {
|
|
|
|
meta: {
|
|
|
|
sender: { channel },
|
|
|
|
},
|
|
|
|
} = this.currentChat;
|
|
|
|
return channel;
|
|
|
|
},
|
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() {
|
|
|
|
if (this.channelType === 'Channel::FacebookPage') {
|
|
|
|
return 640;
|
|
|
|
}
|
|
|
|
if (this.channelType === 'Channel::TwitterProfile') {
|
|
|
|
if (this.conversationType === 'tweet') {
|
|
|
|
return 280;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 10000;
|
|
|
|
},
|
|
|
|
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');
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
message(val) {
|
2019-10-27 07:44:36 +00:00
|
|
|
if (this.isPrivate) {
|
2019-08-14 09:48:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const isSlashCommand = val[0] === '/';
|
2019-12-16 12:53:14 +00:00
|
|
|
const hasNextWord = val.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;
|
2019-08-14 09:48:44 +00:00
|
|
|
if (val.length > 1) {
|
|
|
|
const searchKey = val.substr(1, val.length);
|
2019-10-27 05:18:26 +00:00
|
|
|
this.$store.dispatch('getCannedResponse', {
|
2019-08-14 09:48:44 +00:00
|
|
|
searchKey,
|
|
|
|
});
|
|
|
|
} 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) {
|
2019-10-27 05:18:26 +00:00
|
|
|
if (this.isEscape(e)) {
|
|
|
|
this.hideEmojiPicker();
|
|
|
|
this.hideCannedResponse();
|
2019-11-17 08:45:05 +00:00
|
|
|
} else if (this.isEnter(e)) {
|
2019-10-27 05:18:26 +00:00
|
|
|
if (!e.shiftKey) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.sendMessage();
|
|
|
|
}
|
|
|
|
}
|
2019-11-17 08:45:05 +00:00
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
isEnter(e) {
|
|
|
|
return e.keyCode === 13;
|
|
|
|
},
|
|
|
|
isEscape(e) {
|
2019-10-27 05:18:26 +00:00
|
|
|
return e.keyCode === 27; // ESCAPE
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
async sendMessage() {
|
2019-11-17 08:45:05 +00:00
|
|
|
const isMessageEmpty = !this.message.replace(/\n/g, '').length;
|
2020-03-22 10:24:36 +00:00
|
|
|
if (isMessageEmpty) return;
|
|
|
|
|
2019-11-17 08:45:05 +00:00
|
|
|
if (!this.showCannedResponsesList) {
|
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,
|
|
|
|
message: this.message,
|
|
|
|
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.clearMessage();
|
|
|
|
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
|
|
|
},
|
|
|
|
makePrivate() {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.isPrivate = true;
|
2019-08-14 09:48:44 +00:00
|
|
|
this.$refs.messageInput.focus();
|
|
|
|
},
|
|
|
|
makeReply() {
|
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() {
|
|
|
|
this.toggleTyping('off');
|
|
|
|
},
|
|
|
|
onClick() {
|
|
|
|
this.markSeen();
|
|
|
|
this.toggleTyping('on');
|
|
|
|
},
|
|
|
|
markSeen() {
|
2019-11-19 18:34:32 +00:00
|
|
|
if (this.channelType === 'Channel::FacebookPage') {
|
2019-11-17 08:45:05 +00:00
|
|
|
this.$store.dispatch('markSeen', {
|
|
|
|
inboxId: this.currentChat.inbox_id,
|
|
|
|
contactId: this.currentChat.meta.sender.id,
|
|
|
|
});
|
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
|
2019-10-27 13:31:59 +00:00
|
|
|
toggleTyping(status) {
|
2019-11-19 18:34:32 +00:00
|
|
|
if (this.channelType === 'Channel::FacebookPage') {
|
2019-11-17 08:45:05 +00:00
|
|
|
this.$store.dispatch('toggleTyping', {
|
|
|
|
status,
|
|
|
|
inboxId: this.currentChat.inbox_id,
|
|
|
|
contactId: this.currentChat.meta.sender.id,
|
|
|
|
});
|
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
disableButton() {
|
|
|
|
const messageHasOnlyNewLines = !this.message.replace(/\n/g, '').length;
|
2019-10-27 05:18:26 +00:00
|
|
|
return (
|
|
|
|
this.message.length === 0 ||
|
|
|
|
this.message.length > 640 ||
|
|
|
|
messageHasOnlyNewLines
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
messagePlaceHolder() {
|
2019-10-27 05:18:26 +00:00
|
|
|
const placeHolder = this.isPrivate
|
|
|
|
? 'CONVERSATION.FOOTER.PRIVATE_MSG_INPUT'
|
|
|
|
: 'CONVERSATION.FOOTER.MSG_INPUT';
|
2019-08-14 09:48:44 +00:00
|
|
|
return placeHolder;
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
|
|
|
|
onFileUpload(file) {
|
|
|
|
this.isUploading.image = true;
|
|
|
|
this.$store
|
|
|
|
.dispatch('sendAttachment', [
|
|
|
|
this.currentChat.id,
|
|
|
|
{
|
|
|
|
file_type: file.type,
|
|
|
|
file: file.file,
|
|
|
|
},
|
|
|
|
])
|
|
|
|
.then(() => {
|
|
|
|
this.isUploading.image = false;
|
|
|
|
this.$emit('scrollToMessage');
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isUploading.image = false;
|
|
|
|
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>
|