2017-01-21 08:13:36 +03:00
|
|
|
/*
|
2017-02-02 21:02:07 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2017-01-21 08:13:36 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-01-25 21:25:40 +03:00
|
|
|
import React from 'react';
|
|
|
|
import sdk from '../../../index';
|
2017-01-26 02:17:57 +03:00
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
2017-02-02 03:25:49 +03:00
|
|
|
import GeminiScrollbar from 'react-gemini-scrollbar';
|
2017-03-03 13:02:08 +03:00
|
|
|
import Resend from '../../../Resend';
|
2017-05-30 17:09:57 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2017-01-21 08:13:36 +03:00
|
|
|
|
2017-01-26 17:09:25 +03:00
|
|
|
function DeviceListEntry(props) {
|
|
|
|
const {userId, device} = props;
|
|
|
|
|
|
|
|
const DeviceVerifyButtons = sdk.getComponent('elements.DeviceVerifyButtons');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li>
|
2017-10-11 19:56:17 +03:00
|
|
|
<DeviceVerifyButtons device={device} userId={userId} />
|
2017-01-26 17:09:25 +03:00
|
|
|
{ device.deviceId }
|
2017-10-11 19:56:17 +03:00
|
|
|
<br />
|
2017-01-26 17:09:25 +03:00
|
|
|
{ device.getDisplayName() }
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceListEntry.propTypes = {
|
|
|
|
userId: React.PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
// deviceinfo
|
|
|
|
device: React.PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-25 21:25:40 +03:00
|
|
|
function UserUnknownDeviceList(props) {
|
2017-01-26 17:09:25 +03:00
|
|
|
const {userId, userDevices} = props;
|
2017-01-25 21:25:40 +03:00
|
|
|
|
|
|
|
const deviceListEntries = Object.keys(userDevices).map((deviceId) =>
|
2017-11-07 19:37:43 +03:00
|
|
|
<DeviceListEntry key={deviceId} userId={userId}
|
|
|
|
device={userDevices[deviceId]}
|
|
|
|
/>,
|
2017-01-25 21:25:40 +03:00
|
|
|
);
|
|
|
|
|
2017-01-26 17:09:25 +03:00
|
|
|
return (
|
|
|
|
<ul className="mx_UnknownDeviceDialog_deviceList">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ deviceListEntries }
|
2017-01-26 17:09:25 +03:00
|
|
|
</ul>
|
|
|
|
);
|
2017-01-25 21:25:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UserUnknownDeviceList.propTypes = {
|
2017-01-26 17:09:25 +03:00
|
|
|
userId: React.PropTypes.string.isRequired,
|
|
|
|
|
2017-01-25 21:25:40 +03:00
|
|
|
// map from deviceid -> deviceinfo
|
|
|
|
userDevices: React.PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function UnknownDeviceList(props) {
|
|
|
|
const {devices} = props;
|
|
|
|
|
|
|
|
const userListEntries = Object.keys(devices).map((userId) =>
|
2017-10-11 19:56:17 +03:00
|
|
|
<li key={userId}>
|
2017-01-25 21:25:40 +03:00
|
|
|
<p>{ userId }:</p>
|
2017-10-11 19:56:17 +03:00
|
|
|
<UserUnknownDeviceList userId={userId} userDevices={devices[userId]} />
|
2017-01-25 21:25:40 +03:00
|
|
|
</li>,
|
|
|
|
);
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
return <ul>{ userListEntries }</ul>;
|
2017-01-25 21:25:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UnknownDeviceList.propTypes = {
|
|
|
|
// map from userid -> deviceid -> deviceinfo
|
|
|
|
devices: React.PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default React.createClass({
|
2017-02-21 20:22:22 +03:00
|
|
|
displayName: 'UnknownDeviceDialog',
|
2017-01-21 08:13:36 +03:00
|
|
|
|
|
|
|
propTypes: {
|
2017-01-21 20:56:48 +03:00
|
|
|
room: React.PropTypes.object.isRequired,
|
2017-01-26 17:09:25 +03:00
|
|
|
|
2017-01-21 08:13:36 +03:00
|
|
|
onFinished: React.PropTypes.func.isRequired,
|
|
|
|
},
|
|
|
|
|
2017-11-07 19:37:43 +03:00
|
|
|
componentWillMount: function() {
|
2017-11-07 20:10:40 +03:00
|
|
|
this._unmounted = false;
|
|
|
|
|
2017-11-07 19:37:43 +03:00
|
|
|
const roomMembers = this.props.room.getJoinedMembers().map((m) => {
|
|
|
|
return m.userId;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
// map from userid -> deviceid -> deviceinfo
|
|
|
|
devices: null,
|
2017-01-26 01:52:48 +03:00
|
|
|
});
|
2017-11-07 19:37:43 +03:00
|
|
|
MatrixClientPeg.get().downloadKeys(roomMembers, false).then((devices) => {
|
2017-11-07 20:10:40 +03:00
|
|
|
if (this._unmounted) return;
|
|
|
|
|
2017-11-07 19:37:43 +03:00
|
|
|
const unknownDevices = {};
|
|
|
|
// This is all devices in this room, so find the unknown ones.
|
|
|
|
Object.keys(devices).forEach((userId) => {
|
|
|
|
Object.keys(devices[userId]).map((deviceId) => {
|
|
|
|
const device = devices[userId][deviceId];
|
|
|
|
|
|
|
|
if (device.isUnverified() && !device.isKnown()) {
|
|
|
|
if (unknownDevices[userId] === undefined) {
|
|
|
|
unknownDevices[userId] = {};
|
|
|
|
}
|
|
|
|
unknownDevices[userId][deviceId] = device;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given we've now shown the user the unknown device, it is no longer
|
|
|
|
// unknown to them. Therefore mark it as 'known'.
|
|
|
|
if (!device.isKnown()) {
|
|
|
|
MatrixClientPeg.get().setDeviceKnown(userId, deviceId, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-02-06 19:01:25 +03:00
|
|
|
|
2017-11-07 19:37:43 +03:00
|
|
|
this.setState({
|
|
|
|
devices: unknownDevices,
|
|
|
|
});
|
|
|
|
});
|
2017-01-21 08:13:36 +03:00
|
|
|
},
|
|
|
|
|
2017-11-07 20:10:40 +03:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._unmounted = true;
|
|
|
|
},
|
|
|
|
|
2017-01-21 08:13:36 +03:00
|
|
|
render: function() {
|
2017-11-07 19:37:43 +03:00
|
|
|
if (this.state.devices === null) {
|
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
|
|
|
return <Spinner />;
|
|
|
|
}
|
|
|
|
|
2017-01-26 17:09:25 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2017-01-26 17:12:00 +03:00
|
|
|
const blacklistUnverified = client.getGlobalBlacklistUnverifiedDevices() ||
|
|
|
|
this.props.room.getBlacklistUnverifiedDevices();
|
2017-01-26 17:09:25 +03:00
|
|
|
|
|
|
|
let warning;
|
2017-01-21 21:06:15 +03:00
|
|
|
if (blacklistUnverified) {
|
2017-01-26 17:12:00 +03:00
|
|
|
warning = (
|
|
|
|
<h4>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("You are currently blacklisting unverified devices; to send " +
|
|
|
|
"messages to these devices you must verify them.") }
|
2017-01-26 17:12:00 +03:00
|
|
|
</h4>
|
|
|
|
);
|
|
|
|
} else {
|
2017-02-03 01:05:44 +03:00
|
|
|
warning = (
|
|
|
|
<div>
|
|
|
|
<p>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("We recommend you go through the verification process " +
|
2017-05-30 17:09:57 +03:00
|
|
|
"for each device to confirm they belong to their legitimate owner, " +
|
2017-10-11 19:56:17 +03:00
|
|
|
"but you can resend the message without verifying if you prefer.") }
|
2017-01-26 17:55:58 +03:00
|
|
|
</p>
|
2017-02-03 01:05:44 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-01-21 20:56:48 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 21:25:40 +03:00
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
2017-01-21 08:13:36 +03:00
|
|
|
return (
|
2017-01-25 21:25:40 +03:00
|
|
|
<BaseDialog className='mx_UnknownDeviceDialog'
|
2017-02-06 19:01:25 +03:00
|
|
|
onFinished={() => {
|
|
|
|
// XXX: temporary logging to try to diagnose
|
|
|
|
// https://github.com/vector-im/riot-web/issues/3148
|
|
|
|
console.log("UnknownDeviceDialog closed by escape");
|
|
|
|
this.props.onFinished();
|
|
|
|
}}
|
2017-06-08 14:33:29 +03:00
|
|
|
title={_t('Room contains unknown devices')}
|
2017-01-25 21:25:40 +03:00
|
|
|
>
|
2017-02-03 01:05:44 +03:00
|
|
|
<GeminiScrollbar autoshow={false} className="mx_Dialog_content">
|
2017-01-26 17:12:00 +03:00
|
|
|
<h4>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t('"%(RoomName)s" contains devices that you haven\'t seen before.', {RoomName: this.props.room.name}) }
|
2017-01-26 17:12:00 +03:00
|
|
|
</h4>
|
2017-01-21 20:56:48 +03:00
|
|
|
{ warning }
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Unknown devices") }:
|
2017-02-03 01:05:44 +03:00
|
|
|
|
2017-11-07 19:37:43 +03:00
|
|
|
<UnknownDeviceList devices={this.state.devices} />
|
2017-02-02 03:25:49 +03:00
|
|
|
</GeminiScrollbar>
|
2017-01-21 08:13:36 +03:00
|
|
|
<div className="mx_Dialog_buttons">
|
2017-10-11 19:56:17 +03:00
|
|
|
<button className="mx_Dialog_primary" autoFocus={true}
|
2017-02-22 13:21:43 +03:00
|
|
|
onClick={() => {
|
|
|
|
this.props.onFinished();
|
2017-02-27 16:39:12 +03:00
|
|
|
Resend.resendUnsentEvents(this.props.room);
|
2017-02-22 13:21:43 +03:00
|
|
|
}}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Send anyway") }
|
2017-02-22 13:21:43 +03:00
|
|
|
</button>
|
2017-10-11 19:56:17 +03:00
|
|
|
<button className="mx_Dialog_primary" autoFocus={true}
|
2017-02-06 19:01:25 +03:00
|
|
|
onClick={() => {
|
|
|
|
// XXX: temporary logging to try to diagnose
|
|
|
|
// https://github.com/vector-im/riot-web/issues/3148
|
|
|
|
console.log("UnknownDeviceDialog closed by OK");
|
|
|
|
this.props.onFinished();
|
|
|
|
}}>
|
2017-01-21 08:13:36 +03:00
|
|
|
OK
|
|
|
|
</button>
|
|
|
|
</div>
|
2017-01-25 21:25:40 +03:00
|
|
|
</BaseDialog>
|
2017-01-21 08:13:36 +03:00
|
|
|
);
|
2017-01-21 20:39:31 +03:00
|
|
|
// XXX: do we want to give the user the option to enable blacklistUnverifiedDevices for this room (or globally) at this point?
|
|
|
|
// It feels like confused users will likely turn it on and then disappear in a cloud of UISIs...
|
2017-01-25 21:25:40 +03:00
|
|
|
},
|
2017-01-21 08:13:36 +03:00
|
|
|
});
|