From 3a21958faf5073021e4f8ff3b327577900c19e71 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 23 Jun 2016 12:21:31 +0100 Subject: [PATCH] RoomSettings: add encryption setting Add a knob to RoomSettings which will send the appropriate event to enable encryption in the room. --- src/components/views/rooms/RoomSettings.js | 58 ++++++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index d6b8b67f25..173f19b615 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -21,6 +21,7 @@ var sdk = require('../../../index'); var Modal = require('../../../Modal'); var ObjectUtils = require("../../../ObjectUtils"); var dis = require("../../../dispatcher"); +var UserSettingsStore = require('../../../UserSettingsStore'); // parse a string as an integer; if the input is undefined, or cannot be parsed // as an integer, return a default. @@ -206,11 +207,14 @@ module.exports = React.createClass({ } }); } - console.log("Performing %s operations", promises.length); // color scheme promises.push(this.saveColor()); + // encryption + promises.push(this.saveEncryption()); + + console.log("Performing %s operations", promises.length); return q.allSettled(promises); }, @@ -224,6 +228,19 @@ module.exports = React.createClass({ return this.refs.color_settings.saveSettings(); }, + saveEncryption: function () { + if (!this.refs.encrypt) { return q(); } + + var encrypt = this.refs.encrypt.checked; + if (!encrypt) { return q(); } + + var roomId = this.props.room.roomId; + return MatrixClientPeg.get().sendStateEvent( + roomId, "m.room.encryption", + { algorithm: "m.olm.v1.curve25519-aes-sha2" } + ); + }, + _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! @@ -366,6 +383,39 @@ module.exports = React.createClass({ roomState.mayClientSendStateEvent("m.room.guest_access", cli)) }, + _renderEncryptionSection: function() { + if (!UserSettingsStore.isFeatureEnabled("e2e_encryption")) { + return null; + } + + var cli = MatrixClientPeg.get(); + var roomState = this.props.room.currentState; + var isEncrypted = cli.isRoomEncrypted(this.props.room.roomId); + + var text = "Encryption is " + (isEncrypted ? "" : "not ") + + "enabled in this room."; + + var button; + if (!isEncrypted && + roomState.mayClientSendStateEvent("m.room.encryption", cli)) { + button = ( + + ); + } + + return ( +
+

Encryption

+ + {button} +
+ ); + }, + + render: function() { // TODO: go through greying out things you don't have permission to change // (or turning them into informative stuff) @@ -587,10 +637,6 @@ module.exports = React.createClass({ Members only (since they joined) - @@ -655,6 +701,8 @@ module.exports = React.createClass({ { bannedUsersSection } + { this._renderEncryptionSection() } +

Advanced

This room's internal ID is { this.props.room.roomId }