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-10-27 05:18:26 +00:00
|
|
|
v-if="showCannedModal"
|
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()"
|
|
|
|
></i>
|
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,
|
|
|
|
}"
|
|
|
|
></i>
|
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,
|
|
|
|
showCannedModal: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: mapGetters({
|
|
|
|
currentChat: 'getSelectedChat',
|
|
|
|
}),
|
|
|
|
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] === '/';
|
|
|
|
const hasNextWord = val.indexOf(' ') > -1;
|
|
|
|
const isShortCodeActive = isSlashCommand && !hasNextWord;
|
|
|
|
if (isShortCodeActive) {
|
|
|
|
this.showCannedModal = true;
|
|
|
|
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 {
|
|
|
|
this.showCannedModal = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2019-10-27 05:18:26 +00:00
|
|
|
mounted() {
|
|
|
|
/* eslint-disable no-confusing-arrow */
|
|
|
|
document.addEventListener('keydown', e => {
|
|
|
|
if (this.isEscape(e)) {
|
|
|
|
this.hideEmojiPicker();
|
|
|
|
this.hideCannedResponse();
|
|
|
|
}
|
|
|
|
if (this.isEnter(e)) {
|
|
|
|
if (!e.shiftKey) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.sendMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
methods: {
|
|
|
|
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() {
|
|
|
|
const messageHasOnlyNewLines = !this.message.replace(/\n/g, '').length;
|
|
|
|
if (messageHasOnlyNewLines) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.message.length !== 0 && !this.showCannedModal) {
|
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;
|
|
|
|
}, 200);
|
|
|
|
},
|
|
|
|
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() {
|
|
|
|
this.showCannedModal = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onBlur() {
|
|
|
|
this.toggleTyping('off');
|
|
|
|
},
|
|
|
|
onClick() {
|
|
|
|
this.markSeen();
|
|
|
|
this.toggleTyping('on');
|
|
|
|
},
|
|
|
|
markSeen() {
|
|
|
|
this.$store.dispatch('markSeen', {
|
|
|
|
inboxId: this.currentChat.inbox_id,
|
2019-10-27 13:31:59 +00:00
|
|
|
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-08-14 09:48:44 +00:00
|
|
|
this.$store.dispatch('toggleTyping', {
|
2019-10-27 13:31:59 +00:00
|
|
|
status,
|
2019-08-14 09:48:44 +00:00
|
|
|
inboxId: this.currentChat.inbox_id,
|
2019-10-27 13:31:59 +00:00
|
|
|
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>
|