From 3935287c3fd21e67613567caf596634d559a4432 Mon Sep 17 00:00:00 2001 From: Sharon Kennedy Date: Thu, 19 Mar 2020 09:38:44 -0400 Subject: [PATCH] simpler transcript implementation, forgetting about file and image downloads for now --- src/components/chatbox.jsx | 3 -- src/components/message.jsx | 106 +++++++++---------------------------- 2 files changed, 24 insertions(+), 85 deletions(-) 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 ( -
+
- { this.props.message.content.body } + { message.content.body }
) } - renderHtmlMessage = () => { + if (message.content.formatted_body) { return ( -
-
+
+
) } - renderImageMessage = () => { - return ( -
- + const linkifyOpts = { + linkAttributes: { + rel: 'noreferrer noopener', + }, + } + + return ( +
+
+ { message.content.body }
- ) - } - - renderFileMessage = () => { - return ( - - ) - } - - render() { - console.log(this.props.message) - console.log(this.state) - const { message } = this.props; - - switch(message.content.msgtype) { - case 'm.file': - return this.renderFileMessage() - case 'm.image': - return this.renderImageMessage() - default: - if (message.content.formatted_body) { - return this.renderHtmlMessage() - } - return this.renderTextMessage() - } - } +
+ ) } export default Message; \ No newline at end of file