From 95968bf619e0783cc195d932c2be843bfc66ba3a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Jul 2015 16:14:55 +0100 Subject: [PATCH] Make server_name magix in RoomAlias optional --- .../base/views/atoms/create_room/RoomAlias.js | 48 +++++++++++-------- .../atoms/create_room/RoomAlias.js | 8 ++-- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/skins/base/views/atoms/create_room/RoomAlias.js b/skins/base/views/atoms/create_room/RoomAlias.js index f60ec6b3..fd0789b9 100644 --- a/skins/base/views/atoms/create_room/RoomAlias.js +++ b/skins/base/views/atoms/create_room/RoomAlias.js @@ -32,34 +32,40 @@ module.exports = React.createClass({ var target = ev.target; var curr_val = ev.target.value; - if (curr_val == "") { - target.value = "#:example.com"; - setTimeout(function() { - target.setSelectionRange(1, 1); - }, 0); - } else { - setTimeout(function() { - target.setSelectionRange( - curr_val.startsWith("#") ? 1 : 0, - curr_val.endsWith(":example.com") ? (target.value.length - ":example.com".length) : target.value.length - ); - }, 0); + if (this.props.homeserver) { + if (curr_val == "") { + setTimeout(function() { + target.value = "#:" + this.props.homeserver; + target.setSelectionRange(1, 1); + }, 0); + } else { + var suffix = ":" + this.props.homeserver; + setTimeout(function() { + target.setSelectionRange( + curr_val.startsWith("#") ? 1 : 0, + curr_val.endsWith(suffix) ? (target.value.length - suffix.length) : target.value.length + ); + }, 0); + } } }, onBlur: function(ev) { var curr_val = ev.target.value; - if (curr_val == "#:example.com") { - ev.target.value = ""; - return; - } + if (this.props.homeserver) { + if (curr_val == "#:" + this.props.homeserver) { + ev.target.value = ""; + return; + } - if (curr_val != "") { - var new_val = ev.target.value; - if (!curr_val.startsWith("#")) new_val = "#" + new_val; - if (!curr_val.endsWith(":example.com")) new_val = new_val + ":example.com"; - ev.target.value = new_val; + if (curr_val != "") { + var new_val = ev.target.value; + var suffix = ":" + this.props.homeserver; + if (!curr_val.startsWith("#")) new_val = "#" + new_val; + if (!curr_val.endsWith(suffix)) new_val = new_val + suffix; + ev.target.value = new_val; + } } }, diff --git a/src/controllers/atoms/create_room/RoomAlias.js b/src/controllers/atoms/create_room/RoomAlias.js index 7e3e38a5..6aff8947 100644 --- a/src/controllers/atoms/create_room/RoomAlias.js +++ b/src/controllers/atoms/create_room/RoomAlias.js @@ -20,6 +20,7 @@ var React = require('react'); module.exports = { propTypes: { + homeserver: React.PropTypes.string, default_alias: React.PropTypes.string }, @@ -38,9 +39,10 @@ module.exports = { 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); + if (room_alias && this.props.homeserver) { + var suffix = ":" + this.props.homeserver; + if (room_alias.startsWith("#") && room_alias.endsWith(suffix)) { + room_alias = room_alias.slice(1, -suffix.length); } }