Commit 1b38967d authored by JC Brand's avatar JC Brand

Updates #842 Persistent muc room creation not working

parent d781ebfd
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
## 3.0.2 (Unreleased) ## 3.0.2 (Unreleased)
Dependency updates: *Dependency updates*:
- Jasmine 2.5.3 - Jasmine 2.5.3
- Phantomjs 2.1.14 - Phantomjs 2.1.14
- moment 2.18.1 - moment 2.18.1
- sinon 2.1.0 - sinon 2.1.0
- eslint 3.19.0 - eslint 3.19.0
- #842 Persistent muc room creation not working [jcbrand]
## 3.0.1 (2017-04-04) ## 3.0.1 (2017-04-04)
......
...@@ -346,7 +346,7 @@ ...@@ -346,7 +346,7 @@
is_chatroom: true, is_chatroom: true,
events: { events: {
'click .close-chatbox-button': 'close', 'click .close-chatbox-button': 'close',
'click .configure-chatroom-button': 'configureChatRoom', 'click .configure-chatroom-button': 'getAndRenderConfigurationForm',
'click .toggle-smiley': 'toggleEmoticonMenu', 'click .toggle-smiley': 'toggleEmoticonMenu',
'click .toggle-smiley ul li': 'insertEmoticon', 'click .toggle-smiley ul li': 'insertEmoticon',
'click .toggle-clear': 'clearChatRoomMessages', 'click .toggle-clear': 'clearChatRoomMessages',
...@@ -1281,7 +1281,7 @@ ...@@ -1281,7 +1281,7 @@
return deferred.promise(); return deferred.promise();
}, },
autoConfigureChatRoom: function (stanza) { autoConfigureChatRoom: function () {
/* Automatically configure room based on the /* Automatically configure room based on the
* 'roomconfig' data on this view's model. * 'roomconfig' data on this view's model.
* *
...@@ -1292,14 +1292,18 @@ ...@@ -1292,14 +1292,18 @@
* (XMLElement) stanza: IQ stanza from the server, * (XMLElement) stanza: IQ stanza from the server,
* containing the configuration. * containing the configuration.
*/ */
var that = this, configArray = [], var that = this,
$fields = $(stanza).find('field'), deferred = new $.Deferred();
count = $fields.length,
config = this.model.get('roomconfig'); this.fetchRoomConfiguration().then(function (stanza) {
var configArray = [],
fields = stanza.querySelectorAll('field'),
count = fields.length,
config = that.model.get('roomconfig');
$fields.each(function () { _.each(fields, function (field) {
var fieldname = this.getAttribute('var').replace('muc#roomconfig_', ''), var fieldname = field.getAttribute('var').replace('muc#roomconfig_', ''),
type = this.getAttribute('type'), type = field.getAttribute('type'),
value; value;
if (fieldname in config) { if (fieldname in config) {
switch (type) { switch (type) {
...@@ -1308,18 +1312,24 @@ ...@@ -1308,18 +1312,24 @@
break; break;
case 'list-multi': case 'list-multi':
// TODO: we don't yet handle "list-multi" types // TODO: we don't yet handle "list-multi" types
value = this.innerHTML; value = field.innerHTML;
break; break;
default: default:
value = config[fieldname]; value = config[fieldname];
} }
this.innerHTML = $build('value').t(value); field.innerHTML = $build('value').t(value);
} }
configArray.push(this); configArray.push(field);
if (!--count) { if (!--count) {
that.sendConfiguration(configArray); that.sendConfiguration(
configArray,
deferred.resolve,
deferred.reject
);
} }
}); });
});
return deferred;
}, },
cancelConfiguration: function () { cancelConfiguration: function () {
...@@ -1409,7 +1419,7 @@ ...@@ -1409,7 +1419,7 @@
return deferred.promise(); return deferred.promise();
}, },
configureChatRoom: function (ev) { getAndRenderConfigurationForm: function (ev) {
/* Start the process of configuring a chat room, either by /* Start the process of configuring a chat room, either by
* rendering a configuration form, or by auto-configuring * rendering a configuration form, or by auto-configuring
* based on the "roomconfig" data stored on the * based on the "roomconfig" data stored on the
...@@ -1424,17 +1434,9 @@ ...@@ -1424,17 +1434,9 @@
* case, auto-configure won't happen, regardless of * case, auto-configure won't happen, regardless of
* the settings. * the settings.
*/ */
if (_.isUndefined(ev) && this.model.get('auto_configure')) {
this.fetchRoomConfiguration().then(
this.autoConfigureChatRoom.bind(this));
} else {
if (!_.isUndefined(ev) && ev.preventDefault) {
ev.preventDefault();
}
this.showSpinner(); this.showSpinner();
this.fetchRoomConfiguration().then( this.fetchRoomConfiguration().then(
this.renderConfigurationForm.bind(this)); this.renderConfigurationForm.bind(this));
}
}, },
submitNickname: function (ev) { submitNickname: function (ev) {
...@@ -1824,13 +1826,48 @@ ...@@ -1824,13 +1826,48 @@
return this; return this;
}, },
createInstantRoom: function () { onOwnChatRoomPresence: function (pres) {
/* Sends an empty IQ config stanza to inform the server that the /* Handles a received presence relating to the current
* room should be created with its default configuration. * user.
*
* For locked rooms (which are by definition "new"), the
* room will either be auto-configured or created instantly
* (with default config) or a configuration room will be
* rendered.
*
* If the room is not locked, then the room will be
* auto-configured only if applicable and if the current
* user is the room's owner.
* *
* See http://xmpp.org/extensions/xep-0045.html#createroom-instant * Parameters:
* (XMLElement) pres: The stanza
*/ */
this.saveAffiliationAndRole(pres);
var locked_room = pres.querySelector("status[code='201']");
if (locked_room) {
if (this.model.get('auto_configure')) {
this.autoConfigureChatRoom().then(this.getRoomFeatures.bind(this));
} else if (_converse.muc_instant_rooms) {
// Accept default configuration
this.saveConfiguration().then(this.getRoomFeatures.bind(this)); this.saveConfiguration().then(this.getRoomFeatures.bind(this));
} else {
this.getAndRenderConfigurationForm();
return; // We haven't yet entered the room, so bail here.
}
} else if (!this.model.get('features_fetched')) {
// The features for this room weren't fetched.
// That must mean it's a new room without locking
// (in which case Prosody doesn't send a 201 status),
// otherwise the features would have been fetched in
// the "initialize" method already.
if (this.model.get('affiliation') === 'owner' && this.model.get('auto_configure')) {
this.autoConfigureChatRoom().then(this.getRoomFeatures.bind(this));
} else {
this.getRoomFeatures();
}
}
this.model.save('connection_status', ROOMSTATUS.ENTERED);
}, },
onChatRoomPresence: function (pres) { onChatRoomPresence: function (pres) {
...@@ -1845,32 +1882,8 @@ ...@@ -1845,32 +1882,8 @@
return true; return true;
} }
var is_self = pres.querySelector("status[code='110']"); var is_self = pres.querySelector("status[code='110']");
var locked_room = pres.querySelector("status[code='201']"); if (is_self && pres.getAttribute('type') !== 'unavailable') {
if (is_self) { this.onOwnChatRoomPresence(pres);
this.saveAffiliationAndRole(pres);
if (locked_room) {
// This is a new room. It will now be configured
// and the configuration cached on the Backbone.Model.
if (_converse.muc_instant_rooms) {
this.createInstantRoom(); // Accept default configuration
} else {
this.configureChatRoom();
if (!this.model.get('auto_configure')) {
return;
}
}
}
this.model.save('connection_status', ROOMSTATUS.ENTERED);
this.hideSpinner();
}
if (!locked_room && !this.model.get('features_fetched') &&
this.model.get('connection_status') !== ROOMSTATUS.CONNECTED) {
// The features for this room weren't fetched yet, perhaps
// because it's a new room without locking (in which
// case Prosody doesn't send a 201 status).
// This is the first presence received for the room,
// so a good time to fetch the features.
this.getRoomFeatures();
} }
this.hideSpinner().showStatusMessages(pres); this.hideSpinner().showStatusMessages(pres);
// This must be called after showStatusMessages so that // This must be called after showStatusMessages so that
......
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