extending MatrixEvent

master
f0x 5 years ago
parent 58384996dd
commit 3e375adcd6

@ -6,6 +6,8 @@ const Promise = require('bluebird')
const debounce = require('debounce') const debounce = require('debounce')
const jdenticon = require('jdenticon') const jdenticon = require('jdenticon')
const defaultValue = require('default-value') const defaultValue = require('default-value')
const sdk = require('matrix-js-sdk')
const sanitize = require('sanitize-html')
const Event = require('./events/Event.js') const Event = require('./events/Event.js')
const Info = require('./info.js') const Info = require('./info.js')
@ -24,6 +26,21 @@ jdenticon.config = {
backColor: "#00000000" backColor: "#00000000"
}; };
sdk.MatrixEvent.prototype.plaintext = function() {
let event = this.event
let plain = "unknown event"
if (event.type == "m.room.message") {
plain = event.content.body
if (event.content.format == "org.matrix.custom.html") {
plain = sanitize(event.content.formatted_body, {allowedTags: []})
}
}
return plain
}
let chat = create({ let chat = create({
displayName: "Chat", displayName: "Chat",
@ -78,7 +95,8 @@ let chat = create({
let messageGroups = { let messageGroups = {
current: [], current: [],
groups: [], groups: [],
sender: "" sender: "",
type: ""
} }
// if the sender is the same, add it to the 'current' messageGroup, if not, // if the sender is the same, add it to the 'current' messageGroup, if not,
@ -86,14 +104,15 @@ let chat = create({
let events = [] let events = []
if (room.timeline.length > 0) { if (room.timeline.length > 0) {
room.timeline.forEach((timeline) => { room.timeline.forEach((MatrixEvent) => {
let event = timeline.event; let event = MatrixEvent.event;
if (event.user_id != null) { // localecho messages if (event.user_id != null) { // localecho messages
event.sender = event.user_id event.sender = event.user_id
event.local = true event.local = true
} }
if (event.sender != messageGroups.sender) { if (event.sender != messageGroups.sender || event.type != messageGroups.type) {
messageGroups.sender = event.sender messageGroups.sender = event.sender
messageGroups.type = event.type
if (messageGroups.current.length != 0) { if (messageGroups.current.length != 0) {
messageGroups.groups.push(messageGroups.current) messageGroups.groups.push(messageGroups.current)
} }

@ -73,7 +73,9 @@ let input = create({
} }
content = this.sendReply(content) content = this.sendReply(content)
this.props.client.sendEvent(this.props.roomId, "m.room.message", content, (err, res) => { this.props.client.sendEvent(this.props.roomId, "m.room.message", content, (err, res) => {
console.log(err) if (err != null) {
console.log(err)
}
}) })
}, },
@ -108,7 +110,7 @@ let input = create({
return <div className="input"> return <div className="input">
{this.props.replyEvent && {this.props.replyEvent &&
<div className="replyEvent"> <div className="replyEvent">
{this.props.replyEvent.content.body} {this.props.replyEvent.plaintext()}
</div> </div>
} }
<textarea ref={this.setRef} rows="1" spellCheck="false" placeholder="unencrypted message"></textarea> <textarea ref={this.setRef} rows="1" spellCheck="false" placeholder="unencrypted message"></textarea>

Loading…
Cancel
Save