From 85770feb31437419200cd89bde2b3f204570e2bb Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 8 Jun 2016 21:25:42 +0100 Subject: [PATCH] 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. --- src/components/views/rooms/EventTile.js | 17 ++++++----- .../views/rooms/MemberDeviceInfo.js | 10 ------- src/components/views/rooms/MemberInfo.js | 28 ++++++++----------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index e1390ced6a..ff02139d87 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -139,7 +139,7 @@ module.exports = React.createClass({ componentDidMount: function() { this._suppressReadReceiptAnimation = false; - this.dispatcherRef = dispatcher.register(this.onAction); + MatrixClientPeg.get().on("deviceVerified", this.onDeviceVerified); }, componentWillReceiveProps: function (nextProps) { @@ -161,16 +161,15 @@ module.exports = React.createClass({ }, componentWillUnmount: function() { - dispatcher.unregister(this.dispatcherRef); + var client = MatrixClientPeg.get(); + if (client) { + client.removeListener("deviceVerified", this.onDeviceVerified); + } }, - onAction: function(payload) { - switch (payload.action) { - case 'device_verified': - if (payload.params.userId == this.props.mxEvent.getSender()) { - this._verifyEvent(this.props.mxEvent); - } - break; + onDeviceVerified: function(userId, device) { + if (userId == this.props.mxEvent.getSender()) { + this._verifyEvent(this.props.mxEvent); } }, diff --git a/src/components/views/rooms/MemberDeviceInfo.js b/src/components/views/rooms/MemberDeviceInfo.js index 296e0b4720..da53c744b2 100644 --- a/src/components/views/rooms/MemberDeviceInfo.js +++ b/src/components/views/rooms/MemberDeviceInfo.js @@ -17,8 +17,6 @@ limitations under the License. var React = require('react'); var MatrixClientPeg = require("../../../MatrixClientPeg"); -var dis = require("../../../dispatcher"); - module.exports = React.createClass({ displayName: 'MemberDeviceInfo', propTypes: { @@ -29,14 +27,6 @@ module.exports = React.createClass({ onVerifyClick: function() { MatrixClientPeg.get().setDeviceVerified(this.props.userId, this.props.device.id); - - dis.dispatch({ - action: 'device_verified', - params: { - userId: this.props.userId, - deviceId: this.props.device.id, - }, - }); }, render: function() { diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index 2f68ebfb7d..c50b6e919e 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -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;