Wire together checkboxes and presets and use new /createRoom api

This commit is contained in:
Erik Johnston 2015-07-16 15:55:46 +01:00
parent c708976635
commit cd26d1323f
5 changed files with 124 additions and 13 deletions

View file

@ -18,20 +18,39 @@ limitations under the License.
var React = require('react');
var Presets = {
PrivateChat: "private_chat",
PublicChat: "public_chat",
Custom: "custom",
};
module.exports = {
propTypes: {
default_preset: React.PropTypes.string
onChange: React.PropTypes.func,
default_preset: React.PropTypes.string,
preset: React.PropTypes.string
},
Presets: Presets,
getDefaultProps: function() {
return {
default_preset: 'private_chat',
onChange: function() {},
default_preset: Presets.PrivateChat,
};
},
getInitialState: function() {
return {
preset: this.props.default_preset,
preset: this.props.preset || this.props.default_preset,
}
},
componentWillReceiveProps: function(new_props) {
if (new_props.preset) {
this.setState({
preset: new_props.preset
});
}
},

View file

@ -35,7 +35,15 @@ module.exports = {
}
},
getAlias: function() {
return this.state.room_alias;
getAliasLocalpart: function() {
var room_alias = this.state.room_alias;
if (room_alias) {
if (room_alias.startsWith("#") && room_alias.endsWith("example.com")) {
room_alias = room_alias.slice(1, -":example.com".length);
}
}
return room_alias;
},
};

View file

@ -18,6 +18,7 @@ limitations under the License.
var React = require("react");
var MatrixClientPeg = require("../../MatrixClientPeg");
var PresetValues = require('../atoms/create_room/Presets').Presets;
module.exports = {
propTypes: {
@ -41,6 +42,9 @@ module.exports = {
return {
phase: this.phases.CONFIG,
error_string: "",
is_private: true,
share_history: false,
default_preset: PresetValues.PrivateChat
};
},
@ -52,9 +56,31 @@ module.exports = {
options.name = room_name;
}
var room_topic = this.getTopic();
if (room_name) {
options.topic = room_topic;
}
var preset = this.getPreset();
if (preset) {
options.preset = preset;
if (preset != PresetValues.Custom) {
options.preset = 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"
}
},
];
}
}
var invited_users = this.getInvitedUsers();
@ -62,6 +88,11 @@ module.exports = {
options.invite = invited_users;
}
var alias = this.getAliasLocalpart();
if (alias) {
options.room_alias_name = alias;
}
var cli = MatrixClientPeg.get();
if (!cli) {
// TODO: Error.