extending MatrixEvent

master
f0x 6 years ago
parent 58384996dd
commit 3e375adcd6

@ -6,6 +6,8 @@ const Promise = require('bluebird')
const debounce = require('debounce')
const jdenticon = require('jdenticon')
const defaultValue = require('default-value')
const sdk = require('matrix-js-sdk')
const sanitize = require('sanitize-html')
const Event = require('./events/Event.js')
const Info = require('./info.js')
@ -24,6 +26,21 @@ jdenticon.config = {
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({
displayName: "Chat",
@ -78,7 +95,8 @@ let chat = create({
let messageGroups = {
current: [],
groups: [],
sender: ""
sender: "",
type: ""
}
// if the sender is the same, add it to the 'current' messageGroup, if not,
@ -86,14 +104,15 @@ let chat = create({
let events = []
if (room.timeline.length > 0) {
room.timeline.forEach((timeline) => {
let event = timeline.event;
room.timeline.forEach((MatrixEvent) => {
let event = MatrixEvent.event;
if (event.user_id != null) { // localecho messages
event.sender = event.user_id
event.local = true
}
if (event.sender != messageGroups.sender) {
if (event.sender != messageGroups.sender || event.type != messageGroups.type) {
messageGroups.sender = event.sender
messageGroups.type = event.type
if (messageGroups.current.length != 0) {
messageGroups.groups.push(messageGroups.current)
}

@ -73,7 +73,9 @@ let input = create({
}
content = this.sendReply(content)
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">
{this.props.replyEvent &&
<div className="replyEvent">
{this.props.replyEvent.content.body}
{this.props.replyEvent.plaintext()}
</div>
}
<textarea ref={this.setRef} rows="1" spellCheck="false" placeholder="unencrypted message"></textarea>

Loading…
Cancel
Save