parse reply events

add-admin-interface
adb 4 years ago
parent b2691f0c85
commit 5d0e96a675

@ -1,18 +1,25 @@
<template> <template>
<div :class="type==='send'?'messageSend':'messageReceive'" class="message"> <div :class="type==='send'?'messageSend':'messageReceive'" class="message">
<div v-html="solveTextLinks(msg.replace(/</g, '&lt') <div v-if="replyEvent" class="reply">
.replace(/>/g, '&gt'))"></div> {{replyEvent.sender}}<br>
{{replyEvent.type==='m.room.message'?replyEvent.content.body:'unkown event'}}
</div>
<div v-html="parseMessage(msg)"></div>
<div class="time">{{time}}</div> <div class="time">{{time}}</div>
</div> </div>
</template> </template>
<script> <script>
import {matrix} from "@/main";
export default { export default {
name: "message", name: "message",
props: { props: {
msg: String, msg: String,
time: String, time: String,
type: String type: String,
content: Object,
roomId: String
}, },
methods:{ methods:{
solveTextLinks(text){ solveTextLinks(text){
@ -26,7 +33,33 @@ export default {
return `${space}<a href="${hyperlink}" target="_blank">${url}</a>`; return `${space}<a href="${hyperlink}" target="_blank">${url}</a>`;
} }
) )
},
async getReplyEvent(content) {
let replyId = this.getReplyId(content);
if (replyId === undefined) return undefined;
await matrix.client.fetchRoomEvent(this.roomId, replyId).then((res) => {
this.replyEvent = res;
});
},
getReplyId(content){
if(!content['m.relates_to']) return undefined;
return content['m.relates_to']['m.in_reply_to'].event_id || undefined;
},
parseMessage(msg){
return this.solveTextLinks(
msg.replace(/>.*\n/gm, '').trim()
.replace(/</g, '&lt')
.replace(/>/g, '&gt')
);
}
},
data(){
return{
replyEvent: undefined
} }
},
created() {
this.getReplyEvent(this.content);
} }
} }
</script> </script>
@ -61,4 +94,9 @@ export default {
font-size: 0.7rem; font-size: 0.7rem;
text-align: right; text-align: right;
} }
.reply{
border-left: 2px solid #fff;
padding-left: 0.5rem;
margin-bottom: 0.5rem;
}
</style> </style>

@ -30,9 +30,12 @@
:key="event.origin_server_ts" :key="event.origin_server_ts"
:title="`${group[0].sender} at ${getTime(event.origin_server_ts)}`" :title="`${group[0].sender} at ${getTime(event.origin_server_ts)}`"
> >
<message v-if="event.content.msgtype==='m.text'" <message
:type="event.sender === user?'send':'receive'" v-if="event.content.msgtype==='m.text'"
:msg=event.content.body :time=getTime(event.origin_server_ts) :type="event.sender === user?'send':'receive'"
:msg=event.content.body :time=getTime(event.origin_server_ts)
:content="event.content"
:roomId="roomId"
/> />
<div v-else-if="event.type==='m.room.member'" class="info"> <div v-else-if="event.type==='m.room.member'" class="info">
{{membershipEvents[event.content.membership]}} {{membershipEvents[event.content.membership]}}
@ -52,6 +55,7 @@ import userThumbnail from "@/components/userThumbnail";
import {matrix} from "@/main"; import {matrix} from "@/main";
import splitArray from "@/lib/splitArray"; import splitArray from "@/lib/splitArray";
import {getDate, getTime} from "@/lib/getTimeStrings"; import {getDate, getTime} from "@/lib/getTimeStrings";
import sdk from "matrix-js-sdk"
export default { export default {
name: 'eventGroup', name: 'eventGroup',
@ -62,12 +66,25 @@ export default {
props: { props: {
timeline: Array, timeline: Array,
user: String, user: String,
groupTimeline: Boolean groupTimeline: Boolean,
roomId: String
}, },
methods: { methods: {
getUser(userId) { getUser(userId) {
return matrix.client.getUser(userId); return matrix.client.getUser(userId);
}, },
getReplyId(event){
if(!event.content['m.relates_to']) return undefined;
if(!event.content['m.relates_to']['m.in_reply_to']) return undefined;
return event.content['m.relates_to']['m.in_reply_to'].event_id || undefined;
},
async getReplyEvent(event, callback){
let replyId = this.getReplyId(event);
if (replyId === undefined) return undefined;
await matrix.client.fetchRoomEvent(this.roomId, replyId).then((res) => {
callback(new sdk.MatrixEvent(res));
});
},
splitArray, splitArray,
getDate, getDate,
getTime getTime
@ -126,6 +143,7 @@ export default {
} }
.username{ .username{
margin-left: 1rem; margin-left: 1rem;
font-weight: bold;
} }
.event{ .event{
.info{ .info{

@ -4,7 +4,7 @@
<div @scroll="scrollHandler()" ref="msgContainer" id="messagesContainer" class="messagesContainer"> <div @scroll="scrollHandler()" ref="msgContainer" id="messagesContainer" class="messagesContainer">
<div v-if="loadingStatus" @click="loadEvents()" class="loadMore">{{loadingStatus}}</div> <div v-if="loadingStatus" @click="loadEvents()" class="loadMore">{{loadingStatus}}</div>
<p v-if="room.timeline.length === 0" class="chatInfo">this room is empty</p> <p v-if="room.timeline.length === 0" class="chatInfo">this room is empty</p>
<timeline :timeline="room.timeline" :group-timeline="isGroup()" :user="user"/> <timeline :timeline="room.timeline" :group-timeline="isGroup()" :user="user" :roomId="room.roomId"/>
</div> </div>
<icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" /> <icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
</div> </div>

Loading…
Cancel
Save