device verification: use a js-sdk event

We'll probably want to be able to bubble up device verifications from the
js-sdk at some point, so let's use a js-sdk event for this.
This commit is contained in:
Richard van der Hoff 2016-06-08 21:25:42 +01:00
parent 7ce49c752f
commit 85770feb31
3 changed files with 19 additions and 36 deletions

View file

@ -67,7 +67,7 @@ module.exports = React.createClass({
componentDidMount: function() {
this._updateStateForNewMember(this.props.member);
this.dispatcherRef = dis.register(this.onAction);
MatrixClientPeg.get().on("deviceVerified", this.onDeviceVerified);
},
componentWillReceiveProps: function(newProps) {
@ -77,30 +77,24 @@ module.exports = React.createClass({
},
componentWillUnmount: function() {
dis.unregister(this.dispatcherRef);
var client = MatrixClientPeg.get();
if (client) {
client.removeListener("deviceVerified", this.onDeviceVerified);
}
if (this._cancelDeviceList) {
this._cancelDeviceList();
}
},
onAction: function(payload) {
switch (payload.action) {
case 'device_verified':
if (payload.params.userId == this.props.member.userId) {
this._onDeviceVerified();
}
break;
onDeviceVerified: function(userId, device) {
if (userId == this.props.member.userId) {
// no need to re-download the whole thing; just update our copy of
// the list.
var devices = MatrixClientPeg.get().listDeviceKeys(userId);
this.setState({devices: devices});
}
},
_onDeviceVerified: function() {
// no need to re-download the whole thing; just update our copy of the
// list.
var devices = MatrixClientPeg.get().listDeviceKeys(
this.props.member.userId);
this.setState({devices: devices});
},
_updateStateForNewMember: function(member) {
var newState = this._calculateOpsPermissions(member);
newState.devices = null;