'use strict' const React = require('react') const ReactDOM = require('react-dom') const create = require('create-react-class') 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') const Input = require('./input.js') const User = require('./events/user.js') jdenticon.config = { lightness: { color: [0.58, 0.66], grayscale: [0.30, 0.90] }, saturation: { color: 0.66, grayscale: 0.00 }, backColor: "#00000000" }; let eventFunctions = { plaintext: function() { let plain = "unknown event" if (this.type == "m.room.message") { plain = this.content.body if (this.content.format == "org.matrix.custom.html") { plain = sanitize(this.content.formatted_body, {allowedTags: []}) } } if (this.type == "m.room.member") { if (this.content.membership == "invite") { plain = `${this.sender} invited ${this.state_key}` } else if (this.content.membership == "join") { plain = `${this.state_key} joined the room` } else if (this.content.membership == "leave") { plain = `${this.state_key} left the room` } else if (this.content.membership == "kick") { plain = `${this.sender} kicked ${this.state_key}` } else if (this.content.membership == "ban") { plain = `${this.sender} banned ${this.state_key}` } } if (this.type == "m.room.avatar") { if (this.content.url.length > 0) { plain = `${this.sender} changed the room avatar` } } if (this.type == "m.room.name") { return `${this.sender} changed the room name to ${this.content.name}` } return plain } } let chat = create({ displayName: "Chat", getInitialState: function() { return { ref: null } }, getSnapshotBeforeUpdate: function(oldProps, oldState) { let ref = this.state.ref if (ref == null) {return null} if ((ref.scrollHeight - ref.offsetHeight) - ref.scrollTop < 100) { // Less than 100px from bottom return true } return null }, componentDidUpdate(prevProps, prevState, snapshot) { let ref = this.state.ref if (ref == null) {return} if (snapshot) { // scroll to bottom ref.scrollTop = (ref.scrollHeight - ref.offsetHeight) } }, setRef: function(ref) { if (ref != null) { this.setState({ref: ref}) } }, onReplyClick: function(e) { this.setState({replyEvent: e}) }, render: function() { let empty = (