2016-09-22 21:23:34 +03:00
|
|
|
/*
|
|
|
|
Copyright 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import Modal from '../../../Modal';
|
2017-05-30 17:09:57 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2016-09-22 21:23:34 +03:00
|
|
|
|
|
|
|
export default React.createClass({
|
|
|
|
displayName: 'DeviceVerifyButtons',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
userId: React.PropTypes.string.isRequired,
|
|
|
|
device: React.PropTypes.object.isRequired,
|
|
|
|
},
|
|
|
|
|
2017-02-03 04:49:22 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2017-10-11 19:56:17 +03:00
|
|
|
device: this.props.device,
|
2017-02-03 04:49:22 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
cli.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
|
|
|
},
|
|
|
|
|
2017-02-03 17:34:19 +03:00
|
|
|
onDeviceVerificationChanged: function(userId, deviceId, deviceInfo) {
|
2017-02-03 04:49:22 +03:00
|
|
|
if (userId === this.props.userId && deviceId === this.props.device.deviceId) {
|
2017-02-03 17:34:19 +03:00
|
|
|
this.setState({ device: deviceInfo });
|
2017-02-03 04:49:22 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-22 21:23:34 +03:00
|
|
|
onVerifyClick: function() {
|
2017-05-17 18:40:48 +03:00
|
|
|
const DeviceVerifyDialog = sdk.getComponent('views.dialogs.DeviceVerifyDialog');
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Device Verify Dialog', '', DeviceVerifyDialog, {
|
2017-05-17 18:40:48 +03:00
|
|
|
userId: this.props.userId,
|
|
|
|
device: this.state.device,
|
2016-09-22 21:23:34 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onUnverifyClick: function() {
|
|
|
|
MatrixClientPeg.get().setDeviceVerified(
|
2017-10-11 19:56:17 +03:00
|
|
|
this.props.userId, this.state.device.deviceId, false,
|
2016-09-22 21:23:34 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-11-29 21:25:26 +03:00
|
|
|
onBlacklistClick: function() {
|
2016-09-22 21:23:34 +03:00
|
|
|
MatrixClientPeg.get().setDeviceBlocked(
|
2017-10-11 19:56:17 +03:00
|
|
|
this.props.userId, this.state.device.deviceId, true,
|
2016-09-22 21:23:34 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-11-29 21:25:26 +03:00
|
|
|
onUnblacklistClick: function() {
|
2016-09-22 21:23:34 +03:00
|
|
|
MatrixClientPeg.get().setDeviceBlocked(
|
2017-10-11 19:56:17 +03:00
|
|
|
this.props.userId, this.state.device.deviceId, false,
|
2016-09-22 21:23:34 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
let blacklistButton = null, verifyButton = null;
|
2016-09-22 21:23:34 +03:00
|
|
|
|
2017-02-03 04:49:22 +03:00
|
|
|
if (this.state.device.isBlocked()) {
|
2016-11-29 21:25:26 +03:00
|
|
|
blacklistButton = (
|
|
|
|
<button className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unblacklist"
|
|
|
|
onClick={this.onUnblacklistClick}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Unblacklist") }
|
2016-09-22 21:23:34 +03:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
} else {
|
2016-11-29 21:25:26 +03:00
|
|
|
blacklistButton = (
|
|
|
|
<button className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_blacklist"
|
|
|
|
onClick={this.onBlacklistClick}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Blacklist") }
|
2016-09-22 21:23:34 +03:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-03 04:49:22 +03:00
|
|
|
if (this.state.device.isVerified()) {
|
2016-09-22 21:23:34 +03:00
|
|
|
verifyButton = (
|
|
|
|
<button className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unverify"
|
|
|
|
onClick={this.onUnverifyClick}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Unverify") }
|
2016-09-22 21:23:34 +03:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
verifyButton = (
|
|
|
|
<button className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_verify"
|
|
|
|
onClick={this.onVerifyClick}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Verify...") }
|
2016-09-22 21:23:34 +03:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mx_MemberDeviceInfo because the vector's CSS on EncryptedEventDialog is awful
|
|
|
|
return (
|
|
|
|
<div className="mx_MemberDeviceInfo mx_DeviceVerifyButtons" >
|
|
|
|
{ verifyButton }
|
2016-11-29 21:25:26 +03:00
|
|
|
{ blacklistButton }
|
2016-09-22 21:23:34 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|