Skip to content

Commit 6bb6eaf

Browse files
committed
Hook up slash commands to enable and disable encryption for a room so that we can experiment with encryption while we wait for the rest of the UI to exist
1 parent 726ee7b commit 6bb6eaf

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

‎src/SlashCommands.js‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818

1919
var MatrixClientPeg = require("./MatrixClientPeg");
2020
var dis = require("./dispatcher");
21+
var encryption = require("./encryption");
2122

2223
var reject = function(msg) {
2324
return {
@@ -42,6 +43,25 @@ var commands = {
4243
return reject("Usage: /nick <display_name>");
4344
},
4445

46+
encrypt: function(room_id, args) {
47+
if (args == "on") {
48+
var client = MatrixClientPeg.get();
49+
var members = client.getRoom(room_id).currentState.members;
50+
var user_ids = Object.keys(members);
51+
return success(
52+
encryption.enableEncryption(client, room_id, user_ids)
53+
);
54+
}
55+
if (args == "off") {
56+
var client = MatrixClientPeg.get();
57+
return success(
58+
encryption.disableEncryption(client, room_id)
59+
);
60+
61+
}
62+
return reject("Usage: encrypt <on/off>");
63+
},
64+
4565
// Change the room topic
4666
topic: function(room_id, args) {
4767
if (args) {
@@ -234,4 +254,4 @@ module.exports = {
234254
}
235255
return null; // not a command
236256
}
237-
};
257+
};

‎src/controllers/organisms/CreateRoom.js‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var React = require("react");
2020
var MatrixClientPeg = require("../../MatrixClientPeg");
2121
var PresetValues = require('../atoms/create_room/Presets').Presets;
2222
var q = require('q');
23+
var encryption = require("../../encryption");
2324

2425
module.exports = {
2526
propTypes: {
@@ -103,22 +104,14 @@ module.exports = {
103104
var response;
104105

105106
if (this.state.encrypt) {
106-
var deferred = deferred.then(function(res) {
107+
deferred = deferred.then(function(res) {
107108
response = res;
108-
return cli.downloadKeys([cli.credentials.userId]);
109-
}).then(function(res) {
110-
// TODO: Check the keys are valid.
111-
return cli.downloadKeys(options.invite);
112-
}).then(function(res) {
113-
return cli.setRoomEncryption(response.room_id, {
114-
algorithm: "m.olm.v1.curve25519-aes-sha2",
115-
members: options.invite,
116-
});
117-
}).then(function(res) {
118-
var d = q.defer();
119-
d.resolve(response);
120-
return d.promise;
121-
});
109+
return encryption.enableEncryption(
110+
cli, response.roomId, options.invite
111+
);
112+
}).then(function() {
113+
return q(response) }
114+
);
122115
}
123116

124117
this.setState({

0 commit comments

Comments
 (0)