UI for blacklisting unverified devices per-room & globally

(written blind; untested as yet)
This commit is contained in:
Matthew Hodgson 2017-01-21 17:39:31 +00:00
parent 2e15e8f9b4
commit 3071fc0ddc
4 changed files with 94 additions and 3 deletions

View file

@ -228,11 +228,13 @@ module.exports = React.createClass({
}
// encryption
p = this.saveEncryption();
p = this.saveEnableEncryption();
if (!q.isFulfilled(p)) {
promises.push(p);
}
this.saveBlacklistUnverifiedDevicesPerRoom();
console.log("Performing %s operations: %s", promises.length, JSON.stringify(promises));
return promises;
},
@ -252,11 +254,11 @@ module.exports = React.createClass({
return this.refs.url_preview_settings.saveSettings();
},
saveEncryption: function() {
saveEnableEncryption: function() {
if (!this.refs.encrypt) { return q(); }
var encrypt = this.refs.encrypt.checked;
if (!encrypt) { return q(); }
if (encrypt) { return q(); }
var roomId = this.props.room.roomId;
return MatrixClientPeg.get().sendStateEvent(
@ -265,6 +267,29 @@ module.exports = React.createClass({
);
},
saveBlacklistUnverifiedDevicesPerRoom: function() {
if (!this.refs.blacklistUnverified) return;
if (this._isRoomBlacklistUnverified() !== this.refs.blacklistUnverified.checked) {
this._setRoomBlacklistUnverified(this.refs.blacklistUnverified.checked);
}
},
_isRoomBlacklistUnverified: function() {
var blacklistUnverifiedDevicesPerRoom = UserSettingsStore.getLocalSettings().blacklistUnverifiedDevicesPerRoom;
if (blacklistUnverifiedDevicesPerRoom) {
return blacklistUnverifiedDevicesPerRoom[this.props.room.roomId];
}
return false;
},
_setRoomBlacklistUnverified: function(value) {
var blacklistUnverifiedDevicesPerRoom = UserSettingsStore.getLocalSettings().blacklistUnverifiedDevicesPerRoom;
blacklistUnverifiedDevicesPerRoom[this.props.room.roomId] = value;
UserSettingsStore.setLocalSettings('blacklistUnverifiedDevicesPerRoom', blacklistUnverifiedDevicesPerRoom);
this.props.room.setBlacklistUnverifiedDevices(value);
},
_hasDiff: function(strA, strB) {
// treat undefined as an empty string because other components may blindly
// call setName("") when there has been no diff made to the name!
@ -477,6 +502,16 @@ module.exports = React.createClass({
var cli = MatrixClientPeg.get();
var roomState = this.props.room.currentState;
var isEncrypted = cli.isRoomEncrypted(this.props.room.roomId);
var isGlobalBlacklistUnverified = UserSettingsStore.getLocalSettings().blacklistUnverifiedDevices;
var isRoomBlacklistUnverified = this._isRoomBlacklistUnverified();
var settings =
<label>
<input type="checkbox" ref="blacklistUnverified"
checked={ isGlobalBlacklistUnverified || isRoomBlacklistUnverified }
disabled={ isGlobalBlacklistUnverified || !this.refs.encrypt.checked }/>
Never send encrypted messages to unverified devices in this room.
</label>;
if (!isEncrypted &&
roomState.mayClientSendStateEvent("m.room.encryption", cli)) {
@ -486,6 +521,7 @@ module.exports = React.createClass({
<img className="mx_RoomSettings_e2eIcon" src="img/e2e-unencrypted.svg" width="12" height="12" />
Enable encryption (warning: cannot be disabled again!)
</label>
{ settings }
);
}
else {
@ -497,6 +533,7 @@ module.exports = React.createClass({
}
Encryption is { isEncrypted ? "" : "not " } enabled in this room.
</label>
{ settings }
);
}
},