diff --git a/src/components/chatbox.jsx b/src/components/chatbox.jsx index 2e9f24e..479b47e 100644 --- a/src/components/chatbox.jsx +++ b/src/components/chatbox.jsx @@ -341,11 +341,8 @@ class ChatBox extends React.Component { sender: event.getSender(), roomId: event.getRoomId(), content: event.getContent(), - } - console.log('message ===========>', message) - const messages = [...this.state.messages] messages.push(message) this.setState({ messages }) diff --git a/src/components/message.jsx b/src/components/message.jsx index 08b67f5..b8c33b7 100644 --- a/src/components/message.jsx +++ b/src/components/message.jsx @@ -1,113 +1,55 @@ import React from "react" import PropTypes from "prop-types" import Linkify from 'linkifyjs/react'; -import decryptFile from '../utils/decryptFile' +const Message = ({ message, userId, botId, client }) => { -class Message extends React.Component { - constructor(props) { - super(props); - this.state = { - decryptedUrl: null, - decryptedFile: null, - } - } - - componentDidMount() { - const needsDecryption = ['m.file', 'm.image']; - if (needsDecryption.includes(this.props.message.content.msgtype)) { - decryptFile(this.props.message.content.file, this.props.client) - .then((decryptedBlob) => { - const decryptedUrl = URL.createObjectURL(decryptedBlob) - this.setState({ - decryptedUrl: decryptedUrl, - decryptedBlob: decryptedBlob - }) - - }) - } - } - - componentWillUnmount() { - if (this.state.decryptedUrl) { - URL.revokeObjectURL(this.state.decryptedUrl); - } - } - - senderClass = () => { - switch (this.props.message.sender) { + const senderClass = () => { + switch (message.sender) { case 'from-me': return 'from-me' - case this.props.userId: + case userId: return 'from-me' - case this.props.botId: + case botId: return 'from-bot' default: return 'from-support' } } - renderTextMessage = () => { - const linkifyOpts = { - linkAttributes: { - rel: 'noreferrer noopener', - }, - } + if (message.content.msgtype === 'm.file') { + const url = client.mxcUrlToHttp(message.content.url); return ( -