Implement device blocking

This is the react-sdk part of
https://github.com/matrix-org/matrix-js-sdk/pull/146. It adds 'Block'/'Unblock'
buttons to the device list, and updates the deviceVerified listeners to listen
for deviceVerificationChanged instead.

Also adds an extra <div> to the deviceinfo section to help me with the
CSS.
This commit is contained in:
Richard van der Hoff 2016-06-23 17:27:23 +01:00
parent e046f5359f
commit a1dd427420
3 changed files with 60 additions and 15 deletions

View file

@ -139,7 +139,8 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
this._suppressReadReceiptAnimation = false; this._suppressReadReceiptAnimation = false;
MatrixClientPeg.get().on("deviceVerified", this.onDeviceVerified); MatrixClientPeg.get().on("deviceVerificationChanged",
this.onDeviceVerificationChanged);
}, },
componentWillReceiveProps: function (nextProps) { componentWillReceiveProps: function (nextProps) {
@ -163,11 +164,12 @@ module.exports = React.createClass({
componentWillUnmount: function() { componentWillUnmount: function() {
var client = MatrixClientPeg.get(); var client = MatrixClientPeg.get();
if (client) { if (client) {
client.removeListener("deviceVerified", this.onDeviceVerified); client.removeListener("deviceVerificationChanged",
this.onDeviceVerificationChanged);
} }
}, },
onDeviceVerified: function(userId, device) { onDeviceVerificationChanged: function(userId, device) {
if (userId == this.props.mxEvent.getSender()) { if (userId == this.props.mxEvent.getSender()) {
this._verifyEvent(this.props.mxEvent); this._verifyEvent(this.props.mxEvent);
} }

View file

@ -36,32 +36,73 @@ module.exports = React.createClass({
); );
}, },
onBlockClick: function() {
MatrixClientPeg.get().setDeviceBlocked(
this.props.userId, this.props.device.id, true
);
},
onUnblockClick: function() {
MatrixClientPeg.get().setDeviceBlocked(
this.props.userId, this.props.device.id, false
);
},
render: function() { render: function() {
var indicator = null, button = null; var indicator = null, blockButton = null, verifyButton = null;
if (this.props.device.verified) { if (this.props.device.blocked) {
indicator = ( blockButton = (
<div className="mx_MemberDeviceInfo_verified">&#x2714;</div> <div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unblock"
onClick={this.onUnblockClick}>
Unblock
</div>
); );
button = ( } else {
blockButton = (
<div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_block"
onClick={this.onBlockClick}>
Block
</div>
);
}
if (this.props.device.verified) {
verifyButton = (
<div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unverify" <div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unverify"
onClick={this.onUnverifyClick}> onClick={this.onUnverifyClick}>
Unverify Unverify
</div> </div>
); );
} else { } else {
button = ( verifyButton = (
<div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_verify" <div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_verify"
onClick={this.onVerifyClick}> onClick={this.onVerifyClick}>
Verify Verify
</div> </div>
); );
} }
if (this.props.device.blocked) {
indicator = (
<div className="mx_MemberDeviceInfo_blocked">&#x2716;</div>
);
} else if (this.props.device.verified) {
indicator = (
<div className="mx_MemberDeviceInfo_verified">&#x2714;</div>
);
} else {
indicator = (
<div className="mx_MemberDeviceInfo_unverified">?</div>
);
}
return ( return (
<div className="mx_MemberDeviceInfo"> <div className="mx_MemberDeviceInfo">
<div className="mx_MemberDeviceInfo_deviceId">{this.props.device.id}</div> <div className="mx_MemberDeviceInfo_deviceId">{this.props.device.id}</div>
<div className="mx_MemberDeviceInfo_deviceKey">{this.props.device.key}</div>
{indicator} {indicator}
{button} {verifyButton}
{blockButton}
</div> </div>
); );
}, },

View file

@ -70,7 +70,7 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
this._updateStateForNewMember(this.props.member); this._updateStateForNewMember(this.props.member);
MatrixClientPeg.get().on("deviceVerified", this.onDeviceVerified); MatrixClientPeg.get().on("deviceVerificationChanged", this.onDeviceVerificationChanged);
}, },
componentWillReceiveProps: function(newProps) { componentWillReceiveProps: function(newProps) {
@ -82,14 +82,14 @@ module.exports = React.createClass({
componentWillUnmount: function() { componentWillUnmount: function() {
var client = MatrixClientPeg.get(); var client = MatrixClientPeg.get();
if (client) { if (client) {
client.removeListener("deviceVerified", this.onDeviceVerified); client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
} }
if (this._cancelDeviceList) { if (this._cancelDeviceList) {
this._cancelDeviceList(); this._cancelDeviceList();
} }
}, },
onDeviceVerified: function(userId, device) { onDeviceVerificationChanged: function(userId, device) {
if (userId == this.props.member.userId) { if (userId == this.props.member.userId) {
// no need to re-download the whole thing; just update our copy of // no need to re-download the whole thing; just update our copy of
// the list. // the list.
@ -535,7 +535,9 @@ module.exports = React.createClass({
return ( return (
<div> <div>
<h3>Devices</h3> <h3>Devices</h3>
{devComponents} <div className="mx_MemberInfo_devices">
{devComponents}
</div>
</div> </div>
); );
}, },