2017-01-21 08:13:36 +03:00
|
|
|
/*
|
2017-02-02 21:02:07 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2017-11-09 18:58:15 +03:00
|
|
|
Copyright 2017 New Vector 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';
|
2017-11-15 18:14:42 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-01-25 21:25:40 +03:00
|
|
|
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-11-09 03:43:06 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2018-01-09 16:52:37 +03:00
|
|
|
import { markAllDevicesKnown } from '../../../cryptodevices';
|
2017-11-16 20:59:42 +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>
|
|
|
|
{ device.deviceId }
|
2019-02-01 20:15:19 +03:00
|
|
|
<DeviceVerifyButtons device={device} userId={userId} />
|
2017-10-11 19:56:17 +03:00
|
|
|
<br />
|
2017-01-26 17:09:25 +03:00
|
|
|
{ device.getDisplayName() }
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceListEntry.propTypes = {
|
2017-11-15 18:14:42 +03:00
|
|
|
userId: PropTypes.string.isRequired,
|
2017-01-26 17:09:25 +03:00
|
|
|
|
|
|
|
// deviceinfo
|
2017-11-15 18:14:42 +03:00
|
|
|
device: PropTypes.object.isRequired,
|
2017-01-26 17:09:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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-08 21:49:50 +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-11-15 18:14:42 +03:00
|
|
|
userId: PropTypes.string.isRequired,
|
2017-01-26 17:09:25 +03:00
|
|
|
|
2017-01-25 21:25:40 +03:00
|
|
|
// map from deviceid -> deviceinfo
|
2017-11-15 18:14:42 +03:00
|
|
|
userDevices: PropTypes.object.isRequired,
|
2017-01-25 21:25:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2017-11-15 18:14:42 +03:00
|
|
|
devices: PropTypes.object.isRequired,
|
2017-01-25 21:25:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default React.createClass({
|
2017-02-21 20:22:22 +03:00
|
|
|
displayName: 'UnknownDeviceDialog',
|
2017-01-21 08:13:36 +03:00
|
|
|
|
|
|
|
propTypes: {
|
2017-11-15 18:14:42 +03:00
|
|
|
room: PropTypes.object.isRequired,
|
2017-01-26 17:09:25 +03:00
|
|
|
|
2017-12-06 22:07:12 +03:00
|
|
|
// map from userid -> deviceid -> deviceinfo or null if devices are not yet loaded
|
|
|
|
devices: PropTypes.object,
|
2017-11-16 20:59:42 +03:00
|
|
|
|
2017-11-15 18:14:42 +03:00
|
|
|
onFinished: PropTypes.func.isRequired,
|
2017-01-26 17:09:25 +03:00
|
|
|
|
2017-11-16 20:59:42 +03:00
|
|
|
// Label for the button that marks all devices known and tries the send again
|
2017-11-15 20:21:04 +03:00
|
|
|
sendAnywayLabel: PropTypes.string.isRequired,
|
2017-11-16 20:59:42 +03:00
|
|
|
|
|
|
|
// Label for the button that to send the event if you've verified all devices
|
|
|
|
sendLabel: PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
// function to retry the request once all devices are verified / known
|
|
|
|
onSend: PropTypes.func.isRequired,
|
2017-01-21 08:13:36 +03:00
|
|
|
},
|
|
|
|
|
2017-11-16 20:59:42 +03:00
|
|
|
componentWillMount: function() {
|
|
|
|
MatrixClientPeg.get().on("deviceVerificationChanged", this._onDeviceVerificationChanged);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2017-12-06 22:05:25 +03:00
|
|
|
if (MatrixClientPeg.get()) {
|
|
|
|
MatrixClientPeg.get().removeListener("deviceVerificationChanged", this._onDeviceVerificationChanged);
|
|
|
|
}
|
2017-11-16 20:59:42 +03:00
|
|
|
},
|
2017-01-21 08:13:36 +03:00
|
|
|
|
2017-11-16 20:59:42 +03:00
|
|
|
_onDeviceVerificationChanged: function(userId, deviceId, deviceInfo) {
|
|
|
|
if (this.props.devices[userId] && this.props.devices[userId][deviceId]) {
|
|
|
|
// XXX: Mutating props :/
|
|
|
|
this.props.devices[userId][deviceId] = deviceInfo;
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
2017-11-09 18:58:15 +03:00
|
|
|
},
|
2017-01-21 08:13:36 +03:00
|
|
|
|
2017-11-09 18:58:15 +03:00
|
|
|
_onDismissClicked: function() {
|
|
|
|
this.props.onFinished();
|
2017-11-07 20:10:40 +03:00
|
|
|
},
|
|
|
|
|
2017-11-15 20:21:04 +03:00
|
|
|
_onSendAnywayClicked: function() {
|
2018-01-09 16:52:37 +03:00
|
|
|
markAllDevicesKnown(MatrixClientPeg.get(), this.props.devices);
|
2017-11-16 20:59:42 +03:00
|
|
|
|
|
|
|
this.props.onFinished();
|
|
|
|
this.props.onSend();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onSendClicked: function() {
|
2017-11-15 20:21:04 +03:00
|
|
|
this.props.onFinished();
|
2017-11-16 20:59:42 +03:00
|
|
|
this.props.onSend();
|
2017-11-07 20:10:40 +03:00
|
|
|
},
|
|
|
|
|
2017-01-21 08:13:36 +03:00
|
|
|
render: function() {
|
2018-03-21 15:00:56 +03:00
|
|
|
const GeminiScrollbarWrapper = sdk.getComponent("elements.GeminiScrollbarWrapper");
|
2017-11-15 18:14:42 +03:00
|
|
|
if (this.props.devices === null) {
|
2017-11-07 19:37:43 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
|
|
|
return <Spinner />;
|
|
|
|
}
|
2017-01-26 17:09:25 +03:00
|
|
|
|
|
|
|
let warning;
|
2017-11-09 03:43:06 +03:00
|
|
|
if (SettingsStore.getValue("blacklistUnverifiedDevices", this.props.room.roomId)) {
|
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-11-16 20:59:42 +03:00
|
|
|
let haveUnknownDevices = false;
|
|
|
|
Object.keys(this.props.devices).forEach((userId) => {
|
|
|
|
Object.keys(this.props.devices[userId]).map((deviceId) => {
|
|
|
|
const device = this.props.devices[userId][deviceId];
|
|
|
|
if (device.isUnverified() && !device.isKnown()) {
|
|
|
|
haveUnknownDevices = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-12-23 06:50:45 +03:00
|
|
|
const sendButtonOnClick = haveUnknownDevices ? this._onSendAnywayClicked : this._onSendClicked;
|
|
|
|
const sendButtonLabel = haveUnknownDevices ? this.props.sendAnywayLabel : this.props.sendAnywayLabel;
|
2017-11-16 20:59:42 +03:00
|
|
|
|
2017-01-25 21:25:40 +03:00
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
2017-12-23 06:50:45 +03:00
|
|
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
2017-01-21 08:13:36 +03:00
|
|
|
return (
|
2017-01-25 21:25:40 +03:00
|
|
|
<BaseDialog className='mx_UnknownDeviceDialog'
|
2017-11-09 18:58:15 +03:00
|
|
|
onFinished={this.props.onFinished}
|
2017-06-08 14:33:29 +03:00
|
|
|
title={_t('Room contains unknown devices')}
|
2017-12-05 15:52:20 +03:00
|
|
|
contentId='mx_Dialog_content'
|
2017-01-25 21:25:40 +03:00
|
|
|
>
|
2018-03-21 15:00:56 +03:00
|
|
|
<GeminiScrollbarWrapper autoshow={false} className="mx_Dialog_content" id='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-08 21:49:50 +03:00
|
|
|
<UnknownDeviceList devices={this.props.devices} />
|
2018-03-21 15:00:56 +03:00
|
|
|
</GeminiScrollbarWrapper>
|
2017-12-23 06:50:45 +03:00
|
|
|
<DialogButtons primaryButton={sendButtonLabel}
|
|
|
|
onPrimaryButtonClick={sendButtonOnClick}
|
|
|
|
onCancel={this._onDismissClicked} />
|
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
|
|
|
});
|