From da85cb9f454227d9d165c1e6660463cafaa59457 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 8 Aug 2017 12:34:40 +0100 Subject: [PATCH] Show unencrypted messages as unencrypted Previously, we were special-casing outgoing messages such that they were shown as encrypted even when encryption had failed for some reason. There's no need for this: outgoing messages have a working isEncrypted() method which we can use to show whether the event has been encrypted yet. Arguably we could do better than an open padlock for events in the 'encrypting' send state, but I'm not really sure what. --- src/components/views/rooms/EventTile.js | 94 +++++++++++++++++++------ 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index b3831a7d0d..815f0a3c6a 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -155,7 +155,9 @@ module.exports = withMatrixClient(React.createClass({ }, componentWillReceiveProps: function(nextProps) { - if (nextProps.mxEvent !== this.props.mxEvent) { + // re-check the sender verification as outgoing events progress through + // the send process. + if (nextProps.eventSendStatus !== this.props.eventSendStatus) { this._verifyEvent(nextProps.mxEvent); } }, @@ -386,6 +388,36 @@ module.exports = withMatrixClient(React.createClass({ }); }, + _renderE2EPadlock: function() { + const ev = this.props.mxEvent; + const props = {onClick: this.onCryptoClicked}; + + + if (ev.getContent().msgtype === 'm.bad.encrypted') { + return ; + } else if (ev.isEncrypted()) { + if (this.state.verified) { + return ; + } else { + return ; + } + } else { + // XXX: if the event is being encrypted (ie eventSendStatus === + // encrypting), it might be nice to show something other than the + // open padlock? + + // if the event is not encrypted, but it's an e2e room, show the + // open padlock + const e2eEnabled = this.props.matrixClient.isRoomEncrypted(ev.getRoomId()); + if (e2eEnabled) { + return ; + } + } + + // no padlock needed + return null; + }, + render: function() { var MessageTimestamp = sdk.getComponent('messages.MessageTimestamp'); var SenderProfile = sdk.getComponent('messages.SenderProfile'); @@ -407,7 +439,6 @@ module.exports = withMatrixClient(React.createClass({ throw new Error("Event type not supported"); } - var e2eEnabled = this.props.matrixClient.isRoomEncrypted(this.props.mxEvent.getRoomId()); var isSending = (['sending', 'queued', 'encrypting'].indexOf(this.props.eventSendStatus) !== -1); const isRedacted = (eventType === 'm.room.message') && this.props.isRedacted; @@ -485,26 +516,7 @@ module.exports = withMatrixClient(React.createClass({ const editButton = ( ); - let e2e; - // cosmetic padlocks: - if ((e2eEnabled && this.props.eventSendStatus) || this.props.mxEvent.getType() === 'm.room.encryption') { - e2e = {_t("Encrypted; - } - // real padlocks - else if (this.props.mxEvent.isEncrypted() || (e2eEnabled && this.props.eventSendStatus)) { - if (this.props.mxEvent.getContent().msgtype === 'm.bad.encrypted') { - e2e = {_t("Undecryptable")}; - } - else if (this.state.verified == true || (e2eEnabled && this.props.eventSendStatus)) { - e2e = {_t("Encrypted; - } - else { - e2e = {_t("Encrypted; - } - } - else if (e2eEnabled) { - e2e = {_t("Unencrypted; - } + const timestamp = this.props.mxEvent.getTs() ? : null; @@ -572,7 +584,7 @@ module.exports = withMatrixClient(React.createClass({ { timestamp } - { e2e } + { this._renderE2EPadlock() } + ); +} + +function E2ePadlockVerified(props) { + return ( + + ); +} + +function E2ePadlockUnverified(props) { + return ( + + ); +} + +function E2ePadlockUnencrypted(props) { + return ( + + ); +} + +function E2ePadlock(props) { + return ; +}