Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 28d28b5

Browse files
committed
correctly reflect verify/blacklist state in UI
1 parent 5de84f8 commit 28d28b5

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/components/views/elements/DeviceVerifyButtons.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ export default React.createClass({
2727
device: React.PropTypes.object.isRequired,
2828
},
2929

30+
getInitialState: function() {
31+
return {
32+
device: this.props.device
33+
};
34+
},
35+
36+
componentWillMount: function() {
37+
const cli = MatrixClientPeg.get();
38+
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
39+
},
40+
41+
componentWillUnmount: function() {
42+
const cli = MatrixClientPeg.get();
43+
cli.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
44+
},
45+
46+
onDeviceVerificationChanged: function(userId, deviceId) {
47+
if (userId === this.props.userId && deviceId === this.props.device.deviceId) {
48+
this.setState({ device: MatrixClientPeg.get().getStoredDevice(userId, deviceId) });
49+
}
50+
},
51+
3052
onVerifyClick: function() {
3153
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
3254
Modal.createDialog(QuestionDialog, {
@@ -41,9 +63,9 @@ export default React.createClass({
4163
</p>
4264
<div className="mx_UserSettings_cryptoSection">
4365
<ul>
44-
<li><label>Device name:</label> <span>{ this.props.device.getDisplayName() }</span></li>
45-
<li><label>Device ID:</label> <span><code>{ this.props.device.deviceId}</code></span></li>
46-
<li><label>Device key:</label> <span><code><b>{ this.props.device.getFingerprint() }</b></code></span></li>
66+
<li><label>Device name:</label> <span>{ this.state.device.getDisplayName() }</span></li>
67+
<li><label>Device ID:</label> <span><code>{ this.state.device.deviceId}</code></span></li>
68+
<li><label>Device key:</label> <span><code><b>{ this.state.device.getFingerprint() }</b></code></span></li>
4769
</ul>
4870
</div>
4971
<p>
@@ -60,7 +82,7 @@ export default React.createClass({
6082
onFinished: confirm=>{
6183
if (confirm) {
6284
MatrixClientPeg.get().setDeviceVerified(
63-
this.props.userId, this.props.device.deviceId, true
85+
this.props.userId, this.state.device.deviceId, true
6486
);
6587
}
6688
},
@@ -69,26 +91,26 @@ export default React.createClass({
6991

7092
onUnverifyClick: function() {
7193
MatrixClientPeg.get().setDeviceVerified(
72-
this.props.userId, this.props.device.deviceId, false
94+
this.props.userId, this.state.device.deviceId, false
7395
);
7496
},
7597

7698
onBlacklistClick: function() {
7799
MatrixClientPeg.get().setDeviceBlocked(
78-
this.props.userId, this.props.device.deviceId, true
100+
this.props.userId, this.state.device.deviceId, true
79101
);
80102
},
81103

82104
onUnblacklistClick: function() {
83105
MatrixClientPeg.get().setDeviceBlocked(
84-
this.props.userId, this.props.device.deviceId, false
106+
this.props.userId, this.state.device.deviceId, false
85107
);
86108
},
87109

88110
render: function() {
89111
var blacklistButton = null, verifyButton = null;
90112

91-
if (this.props.device.isBlocked()) {
113+
if (this.state.device.isBlocked()) {
92114
blacklistButton = (
93115
<button className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unblacklist"
94116
onClick={this.onUnblacklistClick}>
@@ -104,7 +126,7 @@ export default React.createClass({
104126
);
105127
}
106128

107-
if (this.props.device.isVerified()) {
129+
if (this.state.device.isVerified()) {
108130
verifyButton = (
109131
<button className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unverify"
110132
onClick={this.onUnverifyClick}>

0 commit comments

Comments
 (0)