Skip to content

Commit 726ee7b

Browse files
committed
Hook up the encrypt button when creating rooms
1 parent 3474f08 commit 726ee7b

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎skins/base/views/organisms/CreateRoom.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ module.exports = React.createClass({
118118
})
119119
},
120120

121+
onEncryptChanged: function(ev) {
122+
this.setState({
123+
encrypt: ev.target.checked,
124+
});
125+
},
126+
121127
render: function() {
122128
var curr_phase = this.state.phase;
123129
if (curr_phase == this.phases.CREATING) {
@@ -142,7 +148,7 @@ module.exports = React.createClass({
142148
<Presets ref="presets" onChange={this.onPresetChanged} preset={this.state.preset}/> <br />
143149
<label><input type="checkbox" ref="is_private" checked={this.state.is_private} onChange={this.onPrivateChanged}/> Make this room private</label>
144150
<label><input type="checkbox" ref="share_history" checked={this.state.share_history} onChange={this.onShareHistoryChanged}/> Share message history with new users</label>
145-
<label><input type="checkbox"/> Encrypt room</label>
151+
<label><input type="checkbox" ref="encrypt" checked={this.state.encrypt} onChange={this.onEncryptChanged}/> Encrypt room</label>
146152
<CreateRoomButton onCreateRoom={this.onCreateRoom} /> <br />
147153
{error_box}
148154
</div>

‎src/MatrixClientPeg.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ var matrixClient = null;
2323

2424
var localStorage = window.localStorage;
2525

26+
function deviceId() {
27+
var id = Math.floor(Math.random()*16777215).toString(16);
28+
id = "W" + "000000".substring(id.length) + id;
29+
if (localStorage) {
30+
id = localStorage.getItem("mx_device_id") || id;
31+
localStorage.setItem("mx_device_id", id);
32+
}
33+
return id;
34+
}
35+
2636
function createClient(hs_url, is_url, user_id, access_token) {
2737
var opts = {
2838
baseUrl: hs_url,
@@ -31,6 +41,11 @@ function createClient(hs_url, is_url, user_id, access_token) {
3141
userId: user_id
3242
};
3343

44+
if (localStorage) {
45+
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
46+
opts.deviceId = deviceId();
47+
}
48+
3449
matrixClient = Matrix.createClient(opts);
3550
}
3651

‎src/controllers/organisms/CreateRoom.js‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
var React = require("react");
2020
var MatrixClientPeg = require("../../MatrixClientPeg");
2121
var PresetValues = require('../atoms/create_room/Presets').Presets;
22+
var q = require('q');
2223

2324
module.exports = {
2425
propTypes: {
@@ -97,7 +98,28 @@ module.exports = {
9798
return;
9899
}
99100

100-
var deferred = MatrixClientPeg.get().createRoom(options);
101+
var deferred = cli.createRoom(options);
102+
103+
var response;
104+
105+
if (this.state.encrypt) {
106+
var deferred = deferred.then(function(res) {
107+
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+
});
122+
}
101123

102124
this.setState({
103125
phase: this.phases.CREATING,

0 commit comments

Comments
 (0)