Commit 346baa68 authored by JC Brand's avatar JC Brand

Refactor room auto-configuration

parent 273b9584
...@@ -67514,26 +67514,21 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -67514,26 +67514,21 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
}); });
}, },
autoConfigureChatRoom() { /**
/* Automatically configure groupchat based on this model's * Given a <field> element, return a copy with a <value> child if
* 'roomconfig' data. * we can find a value for it in this rooms config.
* * @private
* Returns a promise which resolves once a response IQ has * @method _converse.ChatRoom#autoConfigureChatRoom
* been received. * @returns { Element }
*/ */
return new Promise((resolve, reject) => { addFieldValue(field) {
this.fetchRoomConfiguration().then(stanza => { const type = field.getAttribute('type');
const configArray = [], const fieldname = field.getAttribute('var').replace('muc#roomconfig_', '');
fields = stanza.querySelectorAll('field'), const config = this.get('roomconfig');
config = this.get('roomconfig');
let count = fields.length;
_.each(fields, field => {
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', ''),
type = field.getAttribute('type');
let value;
if (fieldname in config) { if (fieldname in config) {
let value;
switch (type) { switch (type) {
case 'boolean': case 'boolean':
value = config[fieldname] ? 1 : 0; value = config[fieldname] ? 1 : 0;
...@@ -67551,14 +67546,28 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -67551,14 +67546,28 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
field.innerHTML = $build('value').t(value); field.innerHTML = $build('value').t(value);
} }
configArray.push(field); return field;
},
if (! --count) { /**
* Automatically configure the groupchat based on this model's
* 'roomconfig' data.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise }
* Returns a promise which resolves once a response IQ has
* been received.
*/
autoConfigureChatRoom() {
return new Promise(async (resolve, reject) => {
const stanza = await this.fetchRoomConfiguration();
const fields = sizzle('field', stanza);
const configArray = fields.map(f => this.addFieldValue(f));
if (configArray.length) {
this.sendConfiguration(configArray, resolve, reject); this.sendConfiguration(configArray, resolve, reject);
} }
}); });
});
});
}, },
fetchRoomConfiguration() { fetchRoomConfiguration() {
...@@ -644,25 +644,19 @@ converse.plugins.add('converse-muc', { ...@@ -644,25 +644,19 @@ converse.plugins.add('converse-muc', {
}); });
}, },
autoConfigureChatRoom () { /**
/* Automatically configure groupchat based on this model's * Given a <field> element, return a copy with a <value> child if
* 'roomconfig' data. * we can find a value for it in this rooms config.
* * @private
* Returns a promise which resolves once a response IQ has * @method _converse.ChatRoom#autoConfigureChatRoom
* been received. * @returns { Element }
*/ */
return new Promise((resolve, reject) => { addFieldValue (field) {
this.fetchRoomConfiguration().then((stanza) => { const type = field.getAttribute('type');
const configArray = [], const fieldname = field.getAttribute('var').replace('muc#roomconfig_', '');
fields = stanza.querySelectorAll('field'), const config = this.get('roomconfig');
config = this.get('roomconfig');
let count = fields.length;
_.each(fields, (field) => {
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', ''),
type = field.getAttribute('type');
let value;
if (fieldname in config) { if (fieldname in config) {
let value;
switch (type) { switch (type) {
case 'boolean': case 'boolean':
value = config[fieldname] ? 1 : 0; value = config[fieldname] ? 1 : 0;
...@@ -676,13 +670,27 @@ converse.plugins.add('converse-muc', { ...@@ -676,13 +670,27 @@ converse.plugins.add('converse-muc', {
} }
field.innerHTML = $build('value').t(value); field.innerHTML = $build('value').t(value);
} }
configArray.push(field); return field;
if (!--count) { },
/**
* Automatically configure the groupchat based on this model's
* 'roomconfig' data.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise }
* Returns a promise which resolves once a response IQ has
* been received.
*/
autoConfigureChatRoom () {
return new Promise(async (resolve, reject) => {
const stanza = await this.fetchRoomConfiguration();
const fields = sizzle('field', stanza);
const configArray = fields.map(f => this.addFieldValue(f))
if (configArray.length) {
this.sendConfiguration(configArray, resolve, reject); this.sendConfiguration(configArray, resolve, reject);
} }
}); });
});
});
}, },
fetchRoomConfiguration () { fetchRoomConfiguration () {
......
...@@ -45762,26 +45762,21 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -45762,26 +45762,21 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
}); });
}, },
autoConfigureChatRoom() { /**
/* Automatically configure groupchat based on this model's * Given a <field> element, return a copy with a <value> child if
* 'roomconfig' data. * we can find a value for it in this rooms config.
* * @private
* Returns a promise which resolves once a response IQ has * @method _converse.ChatRoom#autoConfigureChatRoom
* been received. * @returns { Element }
*/ */
return new Promise((resolve, reject) => { addFieldValue(field) {
this.fetchRoomConfiguration().then(stanza => { const type = field.getAttribute('type');
const configArray = [], const fieldname = field.getAttribute('var').replace('muc#roomconfig_', '');
fields = stanza.querySelectorAll('field'), const config = this.get('roomconfig');
config = this.get('roomconfig');
let count = fields.length;
_.each(fields, field => {
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', ''),
type = field.getAttribute('type');
let value;
if (fieldname in config) { if (fieldname in config) {
let value;
switch (type) { switch (type) {
case 'boolean': case 'boolean':
value = config[fieldname] ? 1 : 0; value = config[fieldname] ? 1 : 0;
...@@ -45799,14 +45794,28 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -45799,14 +45794,28 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
field.innerHTML = $build('value').t(value); field.innerHTML = $build('value').t(value);
} }
configArray.push(field); return field;
},
if (! --count) { /**
* Automatically configure the groupchat based on this model's
* 'roomconfig' data.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise }
* Returns a promise which resolves once a response IQ has
* been received.
*/
autoConfigureChatRoom() {
return new Promise(async (resolve, reject) => {
const stanza = await this.fetchRoomConfiguration();
const fields = sizzle('field', stanza);
const configArray = fields.map(f => this.addFieldValue(f));
if (configArray.length) {
this.sendConfiguration(configArray, resolve, reject); this.sendConfiguration(configArray, resolve, reject);
} }
}); });
});
});
}, },
fetchRoomConfiguration() { fetchRoomConfiguration() {
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