/* Copyright 2015, 2016 OpenMarket Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ var React = require("react"); var sdk = require('../../../index'); var MatrixClientPeg = require("../../../MatrixClientPeg"); module.exports = React.createClass({ displayName: 'EncryptedEventDialog', propTypes: { event: React.PropTypes.object.isRequired, onFinished: React.PropTypes.func.isRequired, }, getInitialState: function() { return { device: this.refreshDevice() }; }, componentWillMount: function() { this._unmounted = false; var client = MatrixClientPeg.get(); client.on("deviceVerificationChanged", this.onDeviceVerificationChanged); // no need to redownload keys if we already have the device if (this.state.device) { return; } client.downloadKeys([this.props.event.getSender()], true).done(()=>{ if (this._unmounted) { return; } this.setState({ device: this.refreshDevice() }); }, (err)=>{ console.log("Error downloading devices", err); }); }, componentWillUnmount: function() { this._unmounted = true; var client = MatrixClientPeg.get(); if (client) { client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged); } }, refreshDevice: function() { return MatrixClientPeg.get().getEventSenderDeviceInfo(this.props.event); }, onDeviceVerificationChanged: function(userId, device) { if (userId == this.props.event.getSender()) { this.setState({ device: this.refreshDevice() }); } }, onKeyDown: function(e) { if (e.keyCode === 27) { // escape e.stopPropagation(); e.preventDefault(); this.props.onFinished(false); } }, _renderDeviceInfo: function() { var device = this.state.device; if (!device) { return (unknown device); } var verificationStatus = (NOT verified); if (device.isBlocked()) { verificationStatus = (Blacklisted); } else if (device.isVerified()) { verificationStatus = "verified"; } return (
Name { device.getDisplayName() }
Device ID { device.deviceId }
Verification { verificationStatus }
Ed25519 fingerprint {device.getFingerprint()}
); }, _renderEventInfo: function() { var event = this.props.event; return ( { event.getContent().msgtype === 'm.bad.encrypted' ? ( ) : null }
User ID { event.getSender() }
Curve25519 identity key { event.getSenderKey() || none }
Claimed Ed25519 fingerprint key { event.getKeysClaimed().ed25519 || none }
Algorithm { event.getWireContent().algorithm || unencrypted }
Decryption error { event.getContent().body }
Session ID { event.getWireContent().session_id || none }
); }, render: function() { var DeviceVerifyButtons = sdk.getComponent('elements.DeviceVerifyButtons'); var buttons = null; if (this.state.device) { buttons = ( ); } return (
End-to-end encryption information

Event information

{this._renderEventInfo()}

Sender device information

{this._renderDeviceInfo()}
{buttons}
); } });