Make server_name magix in RoomAlias optional

This commit is contained in:
Erik Johnston 2015-07-16 16:14:55 +01:00
parent cd26d1323f
commit 95968bf619
2 changed files with 32 additions and 24 deletions

View File

@ -32,34 +32,40 @@ module.exports = React.createClass({
var target = ev.target; var target = ev.target;
var curr_val = ev.target.value; var curr_val = ev.target.value;
if (curr_val == "") { if (this.props.homeserver) {
target.value = "#:example.com"; if (curr_val == "") {
setTimeout(function() { setTimeout(function() {
target.setSelectionRange(1, 1); target.value = "#:" + this.props.homeserver;
}, 0); target.setSelectionRange(1, 1);
} else { }, 0);
setTimeout(function() { } else {
target.setSelectionRange( var suffix = ":" + this.props.homeserver;
curr_val.startsWith("#") ? 1 : 0, setTimeout(function() {
curr_val.endsWith(":example.com") ? (target.value.length - ":example.com".length) : target.value.length target.setSelectionRange(
); curr_val.startsWith("#") ? 1 : 0,
}, 0); curr_val.endsWith(suffix) ? (target.value.length - suffix.length) : target.value.length
);
}, 0);
}
} }
}, },
onBlur: function(ev) { onBlur: function(ev) {
var curr_val = ev.target.value; var curr_val = ev.target.value;
if (curr_val == "#:example.com") { if (this.props.homeserver) {
ev.target.value = ""; if (curr_val == "#:" + this.props.homeserver) {
return; ev.target.value = "";
} return;
}
if (curr_val != "") { if (curr_val != "") {
var new_val = ev.target.value; var new_val = ev.target.value;
if (!curr_val.startsWith("#")) new_val = "#" + new_val; var suffix = ":" + this.props.homeserver;
if (!curr_val.endsWith(":example.com")) new_val = new_val + ":example.com"; if (!curr_val.startsWith("#")) new_val = "#" + new_val;
ev.target.value = new_val; if (!curr_val.endsWith(suffix)) new_val = new_val + suffix;
ev.target.value = new_val;
}
} }
}, },

View File

@ -20,6 +20,7 @@ var React = require('react');
module.exports = { module.exports = {
propTypes: { propTypes: {
homeserver: React.PropTypes.string,
default_alias: React.PropTypes.string default_alias: React.PropTypes.string
}, },
@ -38,9 +39,10 @@ module.exports = {
getAliasLocalpart: function() { getAliasLocalpart: function() {
var room_alias = this.state.room_alias; var room_alias = this.state.room_alias;
if (room_alias) { if (room_alias && this.props.homeserver) {
if (room_alias.startsWith("#") && room_alias.endsWith("example.com")) { var suffix = ":" + this.props.homeserver;
room_alias = room_alias.slice(1, -":example.com".length); if (room_alias.startsWith("#") && room_alias.endsWith(suffix)) {
room_alias = room_alias.slice(1, -suffix.length);
} }
} }