From e2c9afb27877f86fbbe5028d271805259e26632f Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 21 Sep 2015 16:28:39 +0100 Subject: [PATCH] port create room --- src/controllers/organisms/CreateRoom.js | 67 ++++++++++++++++++++----- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js index c2112ce58f..f6404eb231 100644 --- a/src/controllers/organisms/CreateRoom.js +++ b/src/controllers/organisms/CreateRoom.js @@ -18,6 +18,9 @@ limitations under the License. var React = require("react"); var MatrixClientPeg = require("../../MatrixClientPeg"); +var PresetValues = require('../atoms/create_room/Presets').Presets; +var q = require('q'); +var encryption = require("../../encryption"); module.exports = { propTypes: { @@ -41,25 +44,52 @@ module.exports = { return { phase: this.phases.CONFIG, error_string: "", + is_private: true, + share_history: false, + default_preset: PresetValues.PrivateChat, + topic: '', + room_name: '', + invited_users: [], }; }, onCreateRoom: function() { var options = {}; - var room_name = this.getName(); - if (room_name) { - options.name = room_name; + if (this.state.room_name) { + options.name = this.state.room_name; } - var preset = this.getPreset(); - if (preset) { - options.preset = preset; + if (this.state.topic) { + options.topic = this.state.topic; } - var invited_users = this.getInvitedUsers(); - if (invited_users) { - options.invite = invited_users; + if (this.state.preset) { + if (this.state.preset != PresetValues.Custom) { + options.preset = this.state.preset; + } else { + options.initial_state = [ + { + type: "m.room.join_rules", + content: { + "join_rules": this.state.is_private ? "invite" : "public" + } + }, + { + type: "m.room.history_visibility", + content: { + "history_visibility": this.state.share_history ? "shared" : "invited" + } + }, + ]; + } + } + + options.invite = this.state.invited_users; + + var alias = this.getAliasLocalpart(); + if (alias) { + options.room_alias_name = alias; } var cli = MatrixClientPeg.get(); @@ -69,7 +99,20 @@ module.exports = { return; } - var deferred = MatrixClientPeg.get().createRoom(options); + var deferred = cli.createRoom(options); + + var response; + + if (this.state.encrypt) { + deferred = deferred.then(function(res) { + response = res; + return encryption.enableEncryption( + cli, response.roomId, options.invite + ); + }).then(function() { + return q(response) } + ); + } this.setState({ phase: this.phases.CREATING, @@ -77,11 +120,11 @@ module.exports = { var self = this; - deferred.then(function () { + deferred.then(function (resp) { self.setState({ phase: self.phases.CREATED, }); - self.props.onRoomCreated(); + self.props.onRoomCreated(resp.room_id); }, function(err) { self.setState({ phase: self.phases.ERROR,