Hook up the encrypt button when creating rooms

This commit is contained in:
Mark Haines 2015-07-21 12:03:15 +01:00
parent 3474f08334
commit 726ee7b50b
3 changed files with 45 additions and 2 deletions

View file

@ -118,6 +118,12 @@ module.exports = React.createClass({
}) })
}, },
onEncryptChanged: function(ev) {
this.setState({
encrypt: ev.target.checked,
});
},
render: function() { render: function() {
var curr_phase = this.state.phase; var curr_phase = this.state.phase;
if (curr_phase == this.phases.CREATING) { if (curr_phase == this.phases.CREATING) {
@ -142,7 +148,7 @@ module.exports = React.createClass({
<Presets ref="presets" onChange={this.onPresetChanged} preset={this.state.preset}/> <br /> <Presets ref="presets" onChange={this.onPresetChanged} preset={this.state.preset}/> <br />
<label><input type="checkbox" ref="is_private" checked={this.state.is_private} onChange={this.onPrivateChanged}/> Make this room private</label> <label><input type="checkbox" ref="is_private" checked={this.state.is_private} onChange={this.onPrivateChanged}/> Make this room private</label>
<label><input type="checkbox" ref="share_history" checked={this.state.share_history} onChange={this.onShareHistoryChanged}/> Share message history with new users</label> <label><input type="checkbox" ref="share_history" checked={this.state.share_history} onChange={this.onShareHistoryChanged}/> Share message history with new users</label>
<label><input type="checkbox"/> Encrypt room</label> <label><input type="checkbox" ref="encrypt" checked={this.state.encrypt} onChange={this.onEncryptChanged}/> Encrypt room</label>
<CreateRoomButton onCreateRoom={this.onCreateRoom} /> <br /> <CreateRoomButton onCreateRoom={this.onCreateRoom} /> <br />
{error_box} {error_box}
</div> </div>

View file

@ -23,6 +23,16 @@ var matrixClient = null;
var localStorage = window.localStorage; var localStorage = window.localStorage;
function deviceId() {
var id = Math.floor(Math.random()*16777215).toString(16);
id = "W" + "000000".substring(id.length) + id;
if (localStorage) {
id = localStorage.getItem("mx_device_id") || id;
localStorage.setItem("mx_device_id", id);
}
return id;
}
function createClient(hs_url, is_url, user_id, access_token) { function createClient(hs_url, is_url, user_id, access_token) {
var opts = { var opts = {
baseUrl: hs_url, baseUrl: hs_url,
@ -31,6 +41,11 @@ function createClient(hs_url, is_url, user_id, access_token) {
userId: user_id userId: user_id
}; };
if (localStorage) {
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
opts.deviceId = deviceId();
}
matrixClient = Matrix.createClient(opts); matrixClient = Matrix.createClient(opts);
} }

View file

@ -19,6 +19,7 @@ limitations under the License.
var React = require("react"); var React = require("react");
var MatrixClientPeg = require("../../MatrixClientPeg"); var MatrixClientPeg = require("../../MatrixClientPeg");
var PresetValues = require('../atoms/create_room/Presets').Presets; var PresetValues = require('../atoms/create_room/Presets').Presets;
var q = require('q');
module.exports = { module.exports = {
propTypes: { propTypes: {
@ -97,7 +98,28 @@ module.exports = {
return; return;
} }
var deferred = MatrixClientPeg.get().createRoom(options); var deferred = cli.createRoom(options);
var response;
if (this.state.encrypt) {
var deferred = deferred.then(function(res) {
response = res;
return cli.downloadKeys([cli.credentials.userId]);
}).then(function(res) {
// TODO: Check the keys are valid.
return cli.downloadKeys(options.invite);
}).then(function(res) {
return cli.setRoomEncryption(response.room_id, {
algorithm: "m.olm.v1.curve25519-aes-sha2",
members: options.invite,
});
}).then(function(res) {
var d = q.defer();
d.resolve(response);
return d.promise;
});
}
this.setState({ this.setState({
phase: this.phases.CREATING, phase: this.phases.CREATING,