show m.audio, m.image, m.video, m.file / add replyEvent.vue

dev
adb 4 years ago
parent dfaa87f5e7
commit 64d52b071d

@ -1,22 +1,40 @@
<template> <template>
<div class="event"> <div class="event">
<div v-if="event.content.msgtype==='m.text'" :class="type==='send'?'messageSend':'messageReceive'" class="message"> <div v-if="event.type==='m.room.message'" :class="type==='send'?'messageSend':'messageReceive'" class="message">
<div v-if="replyEvent" class="reply"> <reply-event :event="replyEvent"/>
<span class="username">{{calcUserName(replyEvent.sender)}}</span><br>
<span v-html="replyEvent.type==='m.room.message'?parseMessage(replyEvent.content.body):'unkown event'"></span> <div v-if="event.content.msgtype==='m.text'" v-html="parseMessage(event.content.body)"/>
<div v-else-if="event.content.msgtype==='m.notice'" class="notice" v-html="parseMessage(event.content.body)"/>
<div v-else-if="event.content.msgtype==='m.image'" class="image">
<img :src="getMediaUrl(event.content.url)" :alt="event.content.body"/><br>
{{event.content.body}}
</div> </div>
<div v-html="parseMessage(event.content.body)"></div> <div v-else-if="event.content.msgtype==='m.file'" class="file">
<div class="time">{{getTime(event.origin_server_ts)}}</div> file: <a :href="getMediaUrl(event.content.url)">
{{event.content.filename || getMediaUrl(event.content.url)}}
</a><br>{{event.content.body}}
</div> </div>
<div v-else-if="event.content.msgtype==='m.notice'" class="notice"> <div v-else-if="event.content.msgtype==='m.audio'" class="audio">
<audio controls>
<source :src="getMediaUrl(event.content.url)" :type="event.content.mimetype">
your browser doesn't support audio
</audio><br>
{{event.content.body}} {{event.content.body}}
<span class="time">{{getTime(event.origin_server_ts)}}</span>
</div> </div>
<div v-else-if="event.type==='m.room.member'" class="info"> <div v-else-if="event.content.msgtype==='m.video'" class="video">
{{membershipEvents[event.content.membership](event)}} <video controls>
<span class="time">{{getTime(event.origin_server_ts)}}</span> <source :src="getMediaUrl(event.content.url)" :type="event.content.mimetype">
your browser doesn't support video
</video><br>
{{event.content.body}}
</div> </div>
<div v-else class="info">unknown event <div v-else class="italic">unsupported message type {{event.content.msgtype}}</div>
<div class="time">{{getTime(event.origin_server_ts)}}</div>
</div>
<div v-else class="info">
<span v-if="event.type==='m.room.member'">{{membershipEvents[event.content.membership](event)}}</span>
<span v-else>unsupported event</span>
<span class="time"> {{getTime(event.origin_server_ts)}}</span> <span class="time"> {{getTime(event.origin_server_ts)}}</span>
</div> </div>
</div> </div>
@ -27,9 +45,12 @@ import {matrix} from '@/main';
import {calcUserName} from '@/lib/matrixUtils'; import {calcUserName} from '@/lib/matrixUtils';
import {parseMessage} from '@/lib/eventUtils'; import {parseMessage} from '@/lib/eventUtils';
import {getTime} from '@/lib/getTimeStrings'; import {getTime} from '@/lib/getTimeStrings';
import {getMediaUrl} from '@/lib/getMxc';
import ReplyEvent from '@/components/replyEvent';
export default { export default {
name: 'message', name: 'message',
components: {ReplyEvent},
props: { props: {
type: String, type: String,
event: Object, event: Object,
@ -44,13 +65,11 @@ export default {
return content['m.relates_to'] return content['m.relates_to']
&& content['m.relates_to']['m.in_reply_to'] && content['m.relates_to']['m.in_reply_to']
&& content['m.relates_to']['m.in_reply_to'].event_id && content['m.relates_to']['m.in_reply_to'].event_id
},
calcMembershipEvents(){
}, },
calcUserName, calcUserName,
parseMessage, parseMessage,
getTime getTime,
getMediaUrl
}, },
data(){ data(){
return{ return{
@ -91,7 +110,7 @@ export default {
width: max-content; width: max-content;
min-width: 2rem; min-width: 2rem;
max-width: calc(100% - 5rem); max-width: calc(100% - 5rem);
padding: 0.7rem 1rem 0.45rem 1rem; padding: 0.8rem 1rem 0.45rem 1rem;
background-color: #42a7b9; background-color: #42a7b9;
border-radius: 1rem 1rem 0 1rem; border-radius: 1rem 1rem 0 1rem;
text-align: left; text-align: left;
@ -112,6 +131,30 @@ export default {
font-size: 0.7rem; font-size: 0.7rem;
text-align: right; text-align: right;
} }
.notice{
font-style: italic;
}
.image{
width: 100%;
img{
width: 100%;
height: auto;
max-height: 35rem;
border-radius: 0.5rem;
}
}
.video{
width: 100%;
video{
width: 100%;
height: auto;
max-height: 35rem;
border-radius: 0.5rem;
}
}
.italic{
font-style: italic;
}
} }
.messageReceive{ .messageReceive{
background-color: #424141; background-color: #424141;

@ -1,9 +1,6 @@
<template> <template>
<div class="newMessageBanner" ref="newMessageBanner"> <div class="newMessageBanner" ref="newMessageBanner">
<div class="reply" v-if="replyTo" @click="resetReplyTo"> <reply-event v-if="replyTo" :event="replyTo" @click.native="resetReplyTo()"/>
<span class="username">{{calcUserName(replyTo.sender)}}</span><br>
{{parseMessage(replyTo.content.body)}}
</div>
<form v-on:submit.prevent="sendMessage()"> <form v-on:submit.prevent="sendMessage()">
<textarea <textarea
@keyup.enter.exact="sendMessage()" @keyup.enter.exact="sendMessage()"
@ -27,10 +24,12 @@ import icon from '@/components/icon.vue';
import {matrix} from '@/main.js'; import {matrix} from '@/main.js';
import {parseMessage} from '@/lib/eventUtils'; import {parseMessage} from '@/lib/eventUtils';
import {calcUserName} from '@/lib/matrixUtils'; import {calcUserName} from '@/lib/matrixUtils';
import ReplyEvent from '@/components/replyEvent';
export default { export default {
name: 'newMessage', name: 'newMessage',
components: { components: {
ReplyEvent,
icon icon
}, },
props: { props: {

@ -0,0 +1,44 @@
<template>
<div class="reply">
<span class="username">{{calcUserName(event.sender)}}</span><br>
<span v-if="event.type==='m.room.message'">
<span v-if="event.content.msgtype==='m.text'" v-html="parseMessage(event.content.body).substr(0,200)"/>
<span v-else-if="event.content.msgtype==='m.notice'" class="italic" v-html="parseMessage(event.content.body).substr(0,200)"/>
<span v-else>
<span class="italic">{{event.content.msgtype}}</span><br>
<span>{{event.content.body}}</span>
</span>
</span>
<span v-else>unsupported event</span>
</div>
</template>
<script>
import {calcUserName} from '@/lib/matrixUtils';
import {parseMessage} from '@/lib/eventUtils';
export default {
name: 'replyEvent',
props:{
event: Object
},
methods:{
calcUserName,
parseMessage
}
}
</script>
<style scoped lang="scss">
.reply{
border-left: 2px solid #fff;
padding-left: 0.5rem;
margin-bottom: 0.5rem;
.username{
font-weight: bold;
}
}
.italic{
font-style: italic;
}
</style>
Loading…
Cancel
Save