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()"
|
|
|
|
/>
|
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 }">
|
|
|
|
<a href="#" @click="makeReply">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 }">
|
2019-08-14 09:48:44 +00:00
|
|
|
<a href="#" @click="makePrivate">Private Note</a>
|
|
|
|
</li>
|
2019-10-27 05:18:26 +00:00
|
|
|
<li v-if="message.length" class="tabs-title message-length">
|
|
|
|
<a :class="{ 'message-error': message.length > 620 }">
|
|
|
|
{{ message.length }} / 640
|
|
|
|
</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="{
|
|
|
|
disabled: message.length === 0 || message.length > 640,
|
|
|
|
warning: isPrivate,
|
|
|
|
}"
|
|
|
|
@click="sendMessage"
|
2019-08-14 09:48:44 +00:00
|
|
|
>
|
2019-10-27 05:18:26 +00:00
|
|
|
{{
|
|
|
|
isPrivate
|
|
|
|
? $t('CONVERSATION.REPLYBOX.CREATE')
|
|
|
|
: $t('CONVERSATION.REPLYBOX.SEND')
|
|
|
|
}}
|
|
|
|
<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';
|
|
|
|
|
|
|
|
import EmojiInput from '../emoji/EmojiInput';
|
|
|
|
import CannedResponse from './CannedResponse';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
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,
|
2019-11-17 08:45:05 +00:00
|
|
|
showCannedResponsesList: 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;
|
|
|
|
},
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
components: {
|
|
|
|
EmojiInput,
|
|
|
|
CannedResponse,
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
|
|
|
sendMessage() {
|
2019-11-17 08:45:05 +00:00
|
|
|
const isMessageEmpty = !this.message.replace(/\n/g, '').length;
|
|
|
|
if (isMessageEmpty) {
|
2019-08-14 09:48:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-17 08:45:05 +00:00
|
|
|
if (!this.showCannedResponsesList) {
|
2019-10-27 05:18:26 +00:00
|
|
|
this.$store
|
2019-10-27 13:31:59 +00:00
|
|
|
.dispatch('sendMessage', {
|
|
|
|
conversationId: this.currentChat.id,
|
|
|
|
message: this.message,
|
|
|
|
private: this.isPrivate,
|
|
|
|
})
|
2019-10-27 05:18:26 +00:00
|
|
|
.then(() => {
|
|
|
|
this.$emit('scrollToMessage');
|
|
|
|
});
|
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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</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>
|