|
| 1 | +/* |
| 2 | +Copyright 2017 Vector Creations Ltd |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import sdk from '../../../index'; |
| 19 | +import MatrixClientPeg from '../../../MatrixClientPeg'; |
| 20 | +import GeminiScrollbar from 'react-gemini-scrollbar'; |
| 21 | + |
| 22 | +function UserUnknownDeviceList(props) { |
| 23 | + const {userDevices} = props; |
| 24 | + |
| 25 | + const deviceListEntries = Object.keys(userDevices).map((deviceId) => |
| 26 | + <li key={ deviceId }> |
| 27 | + { deviceId } ( { userDevices[deviceId].getDisplayName() } ) |
| 28 | + </li>, |
| 29 | + ); |
| 30 | + |
| 31 | + return <ul>{deviceListEntries}</ul>; |
| 32 | +} |
| 33 | + |
| 34 | +UserUnknownDeviceList.propTypes = { |
| 35 | + // map from deviceid -> deviceinfo |
| 36 | + userDevices: React.PropTypes.object.isRequired, |
| 37 | +}; |
| 38 | + |
| 39 | + |
| 40 | +function UnknownDeviceList(props) { |
| 41 | + const {devices} = props; |
| 42 | + |
| 43 | + const userListEntries = Object.keys(devices).map((userId) => |
| 44 | + <li key={ userId }> |
| 45 | + <p>{ userId }:</p> |
| 46 | + <UserUnknownDeviceList userDevices={devices[userId]} /> |
| 47 | + </li>, |
| 48 | + ); |
| 49 | + |
| 50 | + return <ul>{userListEntries}</ul>; |
| 51 | +} |
| 52 | + |
| 53 | +UnknownDeviceList.propTypes = { |
| 54 | + // map from userid -> deviceid -> deviceinfo |
| 55 | + devices: React.PropTypes.object.isRequired, |
| 56 | +}; |
| 57 | + |
| 58 | + |
| 59 | +export default React.createClass({ |
| 60 | + displayName: 'UnknownEventDialog', |
| 61 | + |
| 62 | + propTypes: { |
| 63 | + // map from userid -> deviceid -> deviceinfo |
| 64 | + devices: React.PropTypes.object.isRequired, |
| 65 | + onFinished: React.PropTypes.func.isRequired, |
| 66 | + }, |
| 67 | + |
| 68 | + componentDidMount: function() { |
| 69 | + // Given we've now shown the user the unknown device, it is no longer |
| 70 | + // unknown to them. Therefore mark it as 'known'. |
| 71 | + Object.keys(this.props.devices).forEach((userId) => { |
| 72 | + Object.keys(this.props.devices[userId]).map((deviceId) => { |
| 73 | + MatrixClientPeg.get().setDeviceKnown(userId, deviceId, true); |
| 74 | + }); |
| 75 | + }); |
| 76 | + }, |
| 77 | + |
| 78 | + render: function() { |
| 79 | + const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); |
| 80 | + return ( |
| 81 | + <BaseDialog className='mx_UnknownDeviceDialog' |
| 82 | + onFinished={this.props.onFinished} |
| 83 | + title='Room contains unknown devices' |
| 84 | + > |
| 85 | + <GeminiScrollbar autoshow={false} className="mx_Dialog_content"> |
| 86 | + <h4>This room contains devices which have not been |
| 87 | + verified.</h4> |
| 88 | + <p> |
| 89 | + This means there is no guarantee that the devices belong |
| 90 | + to a rightful user of the room. |
| 91 | + </p><p> |
| 92 | + We recommend you go through the verification process |
| 93 | + for each device before continuing, but you can resend |
| 94 | + the message without verifying if you prefer. |
| 95 | + </p> |
| 96 | + <p>Unknown devices:</p> |
| 97 | + <UnknownDeviceList devices={this.props.devices} /> |
| 98 | + </GeminiScrollbar> |
| 99 | + <div className="mx_Dialog_buttons"> |
| 100 | + <button className="mx_Dialog_primary" autoFocus={ true } |
| 101 | + onClick={ this.props.onFinished } > |
| 102 | + OK |
| 103 | + </button> |
| 104 | + </div> |
| 105 | + </BaseDialog> |
| 106 | + ); |
| 107 | + }, |
| 108 | +}); |
0 commit comments