forked from matrix/element-web
Hook up the encrypt button when creating rooms
This commit is contained in:
parent
3474f08334
commit
726ee7b50b
|
@ -118,6 +118,12 @@ module.exports = React.createClass({
|
|||
})
|
||||
},
|
||||
|
||||
onEncryptChanged: function(ev) {
|
||||
this.setState({
|
||||
encrypt: ev.target.checked,
|
||||
});
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var curr_phase = this.state.phase;
|
||||
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 />
|
||||
<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"/> Encrypt room</label>
|
||||
<label><input type="checkbox" ref="encrypt" checked={this.state.encrypt} onChange={this.onEncryptChanged}/> Encrypt room</label>
|
||||
<CreateRoomButton onCreateRoom={this.onCreateRoom} /> <br />
|
||||
{error_box}
|
||||
</div>
|
||||
|
|
|
@ -23,6 +23,16 @@ var matrixClient = null;
|
|||
|
||||
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) {
|
||||
var opts = {
|
||||
baseUrl: hs_url,
|
||||
|
@ -31,6 +41,11 @@ function createClient(hs_url, is_url, user_id, access_token) {
|
|||
userId: user_id
|
||||
};
|
||||
|
||||
if (localStorage) {
|
||||
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
|
||||
opts.deviceId = deviceId();
|
||||
}
|
||||
|
||||
matrixClient = Matrix.createClient(opts);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ limitations under the License.
|
|||
var React = require("react");
|
||||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||
var PresetValues = require('../atoms/create_room/Presets').Presets;
|
||||
var q = require('q');
|
||||
|
||||
module.exports = {
|
||||
propTypes: {
|
||||
|
@ -97,7 +98,28 @@ module.exports = {
|
|||
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({
|
||||
phase: this.phases.CREATING,
|
||||
|
|
Loading…
Reference in New Issue