|
|
@ -1,21 +1,29 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
<div class="newMessageBanner" ref="newMessageBanner">
|
|
|
|
<div class="newMessageBanner" ref="newMessageBanner">
|
|
|
|
<reply-event v-if="replyTo" :event="replyTo" @click.native="resetReplyTo()"/>
|
|
|
|
<reply-event v-if="replyTo" :event="replyTo" @click.native="resetReplyTo()"/>
|
|
|
|
<event-content v-if="attachment" :content="attachment" class="attachment"/>
|
|
|
|
<div v-if="attachment" class="attachment">
|
|
|
|
<form v-on:submit.prevent="sendMessage()">
|
|
|
|
<event-content :content="attachment" class="attachmentContent" :compact="true"/>
|
|
|
|
|
|
|
|
<icon
|
|
|
|
|
|
|
|
title="remove"
|
|
|
|
|
|
|
|
class="remove"
|
|
|
|
|
|
|
|
ic="./sym/ic_close_white.svg"
|
|
|
|
|
|
|
|
@click.native="resetAttachment()"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<textarea
|
|
|
|
<textarea
|
|
|
|
@keyup.enter.exact="sendMessage()"
|
|
|
|
@keyup.enter.exact="onSubmit(event)"
|
|
|
|
@input="resizeMessageBanner(); sendTyping(2000);"
|
|
|
|
@input="resizeMessageBanner(); sendTyping(2000);"
|
|
|
|
v-model="event.content.body"
|
|
|
|
v-model="event.content.body"
|
|
|
|
ref="newMessageInput" class="newMessageInput"
|
|
|
|
ref="newMessageInput" class="newMessageInput"
|
|
|
|
rows="1" placeholder="type a message ..."
|
|
|
|
rows="1" placeholder="type a message ..."
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<icon
|
|
|
|
<icon
|
|
|
|
v-if="event.content.body && !isRecording"
|
|
|
|
v-if="event.content.body && !isRecording || attachment"
|
|
|
|
type="submit"
|
|
|
|
type="submit"
|
|
|
|
title="press enter to submit"
|
|
|
|
title="press enter to submit"
|
|
|
|
class="sendMessageBtn"
|
|
|
|
class="sendMessageBtn"
|
|
|
|
ic="./sym/ic_send_white.svg"
|
|
|
|
ic="./sym/ic_send_white.svg"
|
|
|
|
|
|
|
|
@click.native="onSubmit(event)"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<div v-else class="recorder">
|
|
|
|
<div v-else class="recorder">
|
|
|
|
<icon
|
|
|
|
<icon
|
|
|
@ -37,7 +45,6 @@
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<div class="mediaButtons">
|
|
|
|
<div class="mediaButtons">
|
|
|
|
<icon
|
|
|
|
<icon
|
|
|
|
title="toggle emoji"
|
|
|
|
title="toggle emoji"
|
|
|
@ -53,7 +60,7 @@
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
<input
|
|
|
|
type="file" id="fileInput" ref="fileInput"
|
|
|
|
type="file" id="fileInput" ref="fileInput"
|
|
|
|
@change="setAttachment($refs.fileInput.files[0])"
|
|
|
|
@change="setAttachment({file: $refs.fileInput.files[0]})"
|
|
|
|
>
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<v-emoji-picker
|
|
|
|
<v-emoji-picker
|
|
|
@ -92,16 +99,27 @@ export default {
|
|
|
|
resetReplyTo: Function
|
|
|
|
resetReplyTo: Function
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
sendMessage(){
|
|
|
|
onSubmit(event){
|
|
|
|
let content = this.event.content;
|
|
|
|
console.log(event)
|
|
|
|
if (!content.body.trim()) return;
|
|
|
|
event.content.msgtype==='m.text'?this.sendEvent(event):this.sendMediaEvent(event);
|
|
|
|
matrix.sendEvent(this.event, this.roomId, this.replyTo);
|
|
|
|
},
|
|
|
|
content.body = '';
|
|
|
|
async sendEvent(event){
|
|
|
|
|
|
|
|
if (!event.content.body.trim()) return;
|
|
|
|
|
|
|
|
await matrix.sendEvent(this.event, this.roomId, this.replyTo);
|
|
|
|
|
|
|
|
//await matrix.sendEvent(new Proxy(this.event, this.eventProxy), this.roomId, this.replyTo);
|
|
|
|
|
|
|
|
event.content.body = '';
|
|
|
|
|
|
|
|
this.resetAttachment();
|
|
|
|
this.resetReplyTo();
|
|
|
|
this.resetReplyTo();
|
|
|
|
let id = this.$refs.newMessageInput;
|
|
|
|
let id = this.$refs.newMessageInput;
|
|
|
|
id.style.height = '1.25rem';
|
|
|
|
id.style.height = '1.25rem';
|
|
|
|
this.onResize(id.parentElement.clientHeight);
|
|
|
|
this.onResize(id.parentElement.clientHeight);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
sendMediaEvent(event){
|
|
|
|
|
|
|
|
matrix.client.uploadContent(this.attachment.blob).then(mxc => {
|
|
|
|
|
|
|
|
event.content.url = mxc;
|
|
|
|
|
|
|
|
this.sendEvent(event);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
sendTyping(timeout){
|
|
|
|
sendTyping(timeout){
|
|
|
|
if (this.waitForSendTyping) return;
|
|
|
|
if (this.waitForSendTyping) return;
|
|
|
|
matrix.client.sendTyping(this.roomId, true, timeout+100);
|
|
|
|
matrix.client.sendTyping(this.roomId, true, timeout+100);
|
|
|
@ -133,8 +151,9 @@ export default {
|
|
|
|
stopRecording(){
|
|
|
|
stopRecording(){
|
|
|
|
this.recorder.stop()
|
|
|
|
this.recorder.stop()
|
|
|
|
.then(({blob}) => {
|
|
|
|
.then(({blob}) => {
|
|
|
|
this.recBlob = blob;
|
|
|
|
|
|
|
|
this.isRecording=false;
|
|
|
|
this.isRecording=false;
|
|
|
|
|
|
|
|
blob.name = `Recording-${new Date().toISOString()}.${blob.type.split('/')[1]}`;
|
|
|
|
|
|
|
|
this.setAttachment({blob});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setVoiceMeter(value){
|
|
|
|
setVoiceMeter(value){
|
|
|
@ -142,18 +161,38 @@ export default {
|
|
|
|
this.$refs.voiceMeter.style.height = `calc(3rem + ${value/4}px`;
|
|
|
|
this.$refs.voiceMeter.style.height = `calc(3rem + ${value/4}px`;
|
|
|
|
this.$refs.voiceMeter.style.width = `calc(3rem + ${value/4}px`;
|
|
|
|
this.$refs.voiceMeter.style.width = `calc(3rem + ${value/4}px`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setAttachment(file){
|
|
|
|
async readFile(file){
|
|
|
|
|
|
|
|
return await new Promise(resolve => {
|
|
|
|
let reader = new FileReader();
|
|
|
|
let reader = new FileReader();
|
|
|
|
reader.onerror = console.error;
|
|
|
|
reader.onerror = console.error;
|
|
|
|
reader.onload = event => {
|
|
|
|
reader.onload = async event => {
|
|
|
|
|
|
|
|
resolve(await (await fetch(event.target.result)).blob());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
async setAttachment({blob, file = blob}){
|
|
|
|
this.attachment = {
|
|
|
|
this.attachment = {
|
|
|
|
msgtype: this.getMsgType(file.type),
|
|
|
|
msgtype: this.getMsgType(file.type),
|
|
|
|
mimetype: file.type,
|
|
|
|
mimetype: file.type,
|
|
|
|
url: event.target.result
|
|
|
|
url: window.URL.createObjectURL(file),
|
|
|
|
|
|
|
|
blob: blob || await this.readFile(file),
|
|
|
|
|
|
|
|
file
|
|
|
|
};
|
|
|
|
};
|
|
|
|
this.event.content.body = file.name;
|
|
|
|
this.event.content = {
|
|
|
|
}
|
|
|
|
body: file.name,
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
msgtype: this.attachment.msgtype,
|
|
|
|
|
|
|
|
mimetype: this.attachment.mimetype
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
resetAttachment(){
|
|
|
|
|
|
|
|
if (!this.attachment) return;
|
|
|
|
|
|
|
|
window.URL.revokeObjectURL(this.attachment.file);
|
|
|
|
|
|
|
|
this.event.content = {
|
|
|
|
|
|
|
|
body: this.attachment?this.event.content.body.replace(this.attachment.file.name, ''):'',
|
|
|
|
|
|
|
|
msgtype: 'm.text'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.attachment = undefined;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getMsgType(fileType){
|
|
|
|
getMsgType(fileType){
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -173,9 +212,7 @@ export default {
|
|
|
|
body: '',
|
|
|
|
body: '',
|
|
|
|
msgtype: 'm.text',
|
|
|
|
msgtype: 'm.text',
|
|
|
|
'm.relates_to': {
|
|
|
|
'm.relates_to': {
|
|
|
|
'm.in_reply_to': {
|
|
|
|
'm.in_reply_to': this.replyTo
|
|
|
|
event_id: undefined
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -186,7 +223,14 @@ export default {
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
isRecording: false,
|
|
|
|
isRecording: false,
|
|
|
|
recBlob: undefined,
|
|
|
|
recBlob: undefined,
|
|
|
|
attachment: undefined
|
|
|
|
attachment: undefined,
|
|
|
|
|
|
|
|
eventProxy: {
|
|
|
|
|
|
|
|
set: ()=>{},
|
|
|
|
|
|
|
|
get: (target, key) => {
|
|
|
|
|
|
|
|
if (typeof target[key] === 'object') return new Proxy(target[key], this.eventProxy);
|
|
|
|
|
|
|
|
return target[key];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
updated() {
|
|
|
@ -195,7 +239,7 @@ export default {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.newMessageBanner{
|
|
|
|
.newMessageBanner{
|
|
|
|
position: absolute;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
bottom: 0;
|
|
|
@ -269,6 +313,8 @@ export default {
|
|
|
|
width: 2.5rem;
|
|
|
|
width: 2.5rem;
|
|
|
|
box-shadow: none;
|
|
|
|
box-shadow: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.emojiToggle{
|
|
|
|
|
|
|
|
}
|
|
|
|
.recordBtn{
|
|
|
|
.recordBtn{
|
|
|
|
position: absolute;
|
|
|
|
position: absolute;
|
|
|
|
right: 1rem;
|
|
|
|
right: 1rem;
|
|
|
@ -311,7 +357,23 @@ export default {
|
|
|
|
display: none;
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.attachment{
|
|
|
|
.attachment{
|
|
|
|
max-width: 5rem;
|
|
|
|
top: 0.5rem;
|
|
|
|
|
|
|
|
left: 0.5rem;
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
width: fit-content;
|
|
|
|
|
|
|
|
height: fit-content;
|
|
|
|
|
|
|
|
.attachmentContent{
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
width: fit-content;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.remove{
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
right: -3rem;
|
|
|
|
|
|
|
|
background-color: unset;
|
|
|
|
|
|
|
|
height: 2.5rem;
|
|
|
|
|
|
|
|
width: 2.5rem;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
img{
|
|
|
|
img{
|
|
|
|
max-width: 10rem;
|
|
|
|
max-width: 10rem;
|
|
|
|