|
|
@ -11,7 +11,7 @@ const elements = {
|
|
|
|
"m.image": require('./image.js')
|
|
|
|
"m.image": require('./image.js')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const mxReplyRegex = /<mx-reply>(.+)<\/mx-reply>/
|
|
|
|
const mxReplyRegex = /^<mx-reply>[\s\S]+<\/mx-reply>/
|
|
|
|
|
|
|
|
|
|
|
|
let Event = create({
|
|
|
|
let Event = create({
|
|
|
|
displayName: "Event",
|
|
|
|
displayName: "Event",
|
|
|
@ -21,6 +21,7 @@ let Event = create({
|
|
|
|
let state = ""
|
|
|
|
let state = ""
|
|
|
|
let reply = ""
|
|
|
|
let reply = ""
|
|
|
|
let element = "unsupported event"
|
|
|
|
let element = "unsupported event"
|
|
|
|
|
|
|
|
let parsedBody
|
|
|
|
|
|
|
|
|
|
|
|
if (event.local) {
|
|
|
|
if (event.local) {
|
|
|
|
state = " local"
|
|
|
|
state = " local"
|
|
|
@ -28,15 +29,23 @@ let Event = create({
|
|
|
|
|
|
|
|
|
|
|
|
if (event.type == "m.room.message") {
|
|
|
|
if (event.type == "m.room.message") {
|
|
|
|
let msgtype = event.content.msgtype;
|
|
|
|
let msgtype = event.content.msgtype;
|
|
|
|
let formattedEvent = getEvent(event)
|
|
|
|
|
|
|
|
let parsedBody = formattedEvent.body
|
|
|
|
let formattedEvent = parseEvent(event)
|
|
|
|
|
|
|
|
parsedBody = formattedEvent.body
|
|
|
|
|
|
|
|
|
|
|
|
let parsedReply = formattedEvent.parsedReply
|
|
|
|
let parsedReply = formattedEvent.parsedReply
|
|
|
|
if (parsedReply.isReply) {
|
|
|
|
if (parsedReply.isReply) {
|
|
|
|
let repliedEvent = this.props.room.findEventById(parsedReply.to)
|
|
|
|
let repliedEvent = this.props.room.findEventById(parsedReply.to)
|
|
|
|
let shortText = getEvent(repliedEvent.event).body
|
|
|
|
let shortText
|
|
|
|
if (shortText.length > 50) {
|
|
|
|
if (repliedEvent == undefined) {
|
|
|
|
shortText = shortText.substr(0, 50) + "..."
|
|
|
|
shortText = "Can't load this event"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
shortText = parseEvent(repliedEvent.event)
|
|
|
|
|
|
|
|
if (shortText.html) {
|
|
|
|
|
|
|
|
shortText = <span dangerouslySetInnerHTML={{__html: shortText.body}}/>
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
shortText = shortText.body
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reply = (
|
|
|
|
reply = (
|
|
|
|
<div className="reply">
|
|
|
|
<div className="reply">
|
|
|
@ -48,7 +57,8 @@ let Event = create({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={"event" + state}>
|
|
|
|
<div className={"event" + state} onClick={() => {console.log(parsedBody, event)
|
|
|
|
|
|
|
|
}}>
|
|
|
|
{reply}
|
|
|
|
{reply}
|
|
|
|
{element}
|
|
|
|
{element}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -56,16 +66,22 @@ let Event = create({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
function getEvent(event) {
|
|
|
|
function parseEvent(event, context) {
|
|
|
|
|
|
|
|
// context can be either 'main' or 'reply'
|
|
|
|
let body = event.content.body
|
|
|
|
let body = event.content.body
|
|
|
|
|
|
|
|
let html = false
|
|
|
|
|
|
|
|
|
|
|
|
if (event.content.format == "org.matrix.custom.html") {
|
|
|
|
if (event.content.format == "org.matrix.custom.html") {
|
|
|
|
body = riot.sanitize(event.content.formatted_body)
|
|
|
|
body = riot.sanitize(event.content.formatted_body)
|
|
|
|
|
|
|
|
html = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let parsedReply = parseReply(event, body)
|
|
|
|
let parsedReply = parseReply(event, body)
|
|
|
|
if (parsedReply.isReply) {
|
|
|
|
if (parsedReply.isReply) {
|
|
|
|
|
|
|
|
// body with fallback stripped
|
|
|
|
body = parsedReply.body
|
|
|
|
body = parsedReply.body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {body: body, parsedReply: parsedReply}
|
|
|
|
return {body: body, parsedReply: parsedReply, html: html}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function parseReply(event, body) {
|
|
|
|
function parseReply(event, body) {
|
|
|
@ -74,7 +90,9 @@ function parseReply(event, body) {
|
|
|
|
replyTo = event.content['m.relates_to']['m.in_reply_to'].event_id
|
|
|
|
replyTo = event.content['m.relates_to']['m.in_reply_to'].event_id
|
|
|
|
if (replyTo) {
|
|
|
|
if (replyTo) {
|
|
|
|
// strip <mx-reply> from message if it exists
|
|
|
|
// strip <mx-reply> from message if it exists
|
|
|
|
|
|
|
|
console.log("STRIPPING FROM", body)
|
|
|
|
body = body.replace(mxReplyRegex, "")
|
|
|
|
body = body.replace(mxReplyRegex, "")
|
|
|
|
|
|
|
|
console.log("TO ", body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
} catch(err) {
|
|
|
|
// no reply
|
|
|
|
// no reply
|
|
|
|