Commit 724e66d0 authored by JC Brand's avatar JC Brand

Initial code for opening a room via URL

parent 79080b35
......@@ -300,6 +300,22 @@ have to be registered anew.
``_converse.on('reconnected', function () { ... });``
roomsAutoJoined
---------------
Emitted once any rooms that have been configured to be automatically joined,
specified via the _`auto_join_rooms` setting, have been entered.
``_converse.on('roomsAutoJoined', function () { ... });``
Also available as an `ES2015 Promise <http://es6-features.org/#PromiseUsage>`_:
.. code-block:: javascript
_converse.api.waitUntil('roomsAutoJoined').then(function () {
// Your code here...
});
roomInviteSent
~~~~~~~~~~~~~~
......
......@@ -511,7 +511,7 @@
if (jid_element.value &&
!_converse.locked_domain &&
!_converse.default_domain &&
_.filter(jid_element.value.split('@')).length < 2) {
!utils.isValidJID(jid_element.value)) {
jid_element.setCustomValidity(__('Please enter a valid XMPP address'));
return false;
}
......
......@@ -353,7 +353,22 @@
'toggle_occupants': true
},
});
_converse.api.promises.add('roomsPanelRendered');
_converse.api.promises.add(['roomsPanelRendered', 'roomsAutoJoined']);
const MUCRouter = Backbone.Router.extend({
routes: {
'converse?room=:room': 'openRoom'
},
openRoom (room) {
_converse.api.waitUntil('roomsAutoJoined').then(() => {
if (utils.isValidJID(room)) {
_converse.api.rooms.open(room);
}
});
}
});
const router = new MUCRouter();
_converse.openChatRoom = function (settings, bring_to_foreground) {
/* Opens a chat room, making sure that certain attributes
......@@ -2724,6 +2739,9 @@
Strophe.LogLevel.ERROR);
}
});
// XXX: Could return Promise for api.rooms.open and then wait
// until all promises have resolved before emitting this.
_converse.emit('roomsAutoJoined');
}
_converse.on('chatBoxesFetched', autoJoinRooms);
......
......@@ -80,9 +80,6 @@
ControlBoxView: {
events: {
},
initialize () {
this.__super__.initialize.apply(this, arguments);
this.model.on('change:active-form', this.showLoginOrRegisterForm.bind(this))
......@@ -102,7 +99,6 @@
}
},
renderRegistrationPanel () {
const { _converse } = this.__super__;
if (_converse.allow_registration) {
......@@ -149,13 +145,11 @@
providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page
});
_converse.RegistrationRouter = Backbone.Router.extend({
const RegistrationRouter = Backbone.Router.extend({
initialize () {
this.route('converse-login', _.partial(this.setActiveForm, 'login'));
this.route('converse-register', _.partial(this.setActiveForm, 'register'));
},
setActiveForm (value) {
_converse.api.waitUntil('controlboxInitialized').then(() => {
const controlbox = _converse.chatboxes.get('controlbox')
......@@ -163,7 +157,7 @@
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
});
const router = new _converse.RegistrationRouter();
const router = new RegistrationRouter();
_converse.RegisterPanel = Backbone.View.extend({
......
......@@ -268,6 +268,10 @@
}
};
u.isValidJID = function (jid) {
return _.filter(jid.split('@')).length === 2 && !jid.startsWith('@') && !jid.endsWith('@');
};
u.isSameBareJID = function (jid1, jid2) {
return Strophe.getBareJidFromJid(jid1).toLowerCase() ===
Strophe.getBareJidFromJid(jid2).toLowerCase();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment