Commit 802f2b24 authored by JC Brand's avatar JC Brand

converse-muc: Update `sendConfiguration` to not take callbacks

parent d95a7987
...@@ -878,16 +878,14 @@ converse.plugins.add('converse-muc', { ...@@ -878,16 +878,14 @@ converse.plugins.add('converse-muc', {
* @param { HTMLElement } form - The configuration form DOM element. * @param { HTMLElement } form - The configuration form DOM element.
* If no form is provided, the default configuration * If no form is provided, the default configuration
* values will be used. * values will be used.
* @returns { promise } * @returns { Promise<XMLElement> }
* Returns a promise which resolves once the XMPP server * Returns a promise which resolves once the XMPP server
* has return a response IQ. * has return a response IQ.
*/ */
saveConfiguration (form) { saveConfiguration (form) {
return new Promise((resolve, reject) => {
const inputs = form ? sizzle(':input:not([type=button]):not([type=submit])', form) : [], const inputs = form ? sizzle(':input:not([type=button]):not([type=submit])', form) : [],
configArray = _.map(inputs, u.webForm2xForm); configArray = _.map(inputs, u.webForm2xForm);
this.sendConfiguration(configArray, resolve, reject); return this.sendConfiguration(configArray);
});
}, },
/** /**
...@@ -926,26 +924,28 @@ converse.plugins.add('converse-muc', { ...@@ -926,26 +924,28 @@ converse.plugins.add('converse-muc', {
* 'roomconfig' data. * 'roomconfig' data.
* @private * @private
* @method _converse.ChatRoom#autoConfigureChatRoom * @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise } * @returns { Promise<XMLElement> }
* Returns a promise which resolves once a response IQ has * Returns a promise which resolves once a response IQ has
* been received. * been received.
*/ */
autoConfigureChatRoom () { async autoConfigureChatRoom () {
return new Promise(async (resolve, reject) => { /* eslint-disable-line no-async-promise-executor */
const stanza = await this.fetchRoomConfiguration(); const stanza = await this.fetchRoomConfiguration();
const fields = sizzle('field', stanza); const fields = sizzle('field', stanza);
const configArray = fields.map(f => this.addFieldValue(f)) const configArray = fields.map(f => this.addFieldValue(f))
if (configArray.length) { if (configArray.length) {
this.sendConfiguration(configArray, resolve, reject); return this.sendConfiguration(configArray);
} }
});
}, },
fetchRoomConfiguration () { /**
/* Send an IQ stanza to fetch the groupchat configuration data. * Send an IQ stanza to fetch the groupchat configuration data.
* Returns a promise which resolves once the response IQ * Returns a promise which resolves once the response IQ
* has been received. * has been received.
* @private
* @method _converse.ChatRoom#fetchRoomConfiguration
* @returns { Promise<XMLElement> }
*/ */
fetchRoomConfiguration () {
return _converse.api.sendIQ( return _converse.api.sendIQ(
$iq({'to': this.get('jid'), 'type': "get"}) $iq({'to': this.get('jid'), 'type': "get"})
.c("query", {xmlns: Strophe.NS.MUC_OWNER}) .c("query", {xmlns: Strophe.NS.MUC_OWNER})
...@@ -953,27 +953,19 @@ converse.plugins.add('converse-muc', { ...@@ -953,27 +953,19 @@ converse.plugins.add('converse-muc', {
}, },
/** /**
* Send an IQ stanza with the groupchat configuration. * Sends an IQ stanza with the groupchat configuration.
* @private * @private
* @method _converse.ChatRoom#sendConfiguration * @method _converse.ChatRoom#sendConfiguration
* @param { Array } config - The groupchat configuration * @param { Array } config - The groupchat configuration
* @param { Function } callback - Callback upon succesful IQ response * @returns { Promise<XMLElement> } - A promise which resolves with
* The first parameter passed in is IQ containing the * the `result` stanza received from the XMPP server.
* groupchat configuration.
* The second is the response IQ from the server.
* @param { Function } errback - Callback upon error IQ response
* The first parameter passed in is IQ containing the
* groupchat configuration.
* The second is the response IQ from the server.
*/ */
sendConfiguration (config=[], callback, errback) { sendConfiguration (config=[]) {
const iq = $iq({to: this.get('jid'), type: "set"}) const iq = $iq({to: this.get('jid'), type: "set"})
.c("query", {xmlns: Strophe.NS.MUC_OWNER}) .c("query", {xmlns: Strophe.NS.MUC_OWNER})
.c("x", {xmlns: Strophe.NS.XFORM, type: "submit"}); .c("x", {xmlns: Strophe.NS.XFORM, type: "submit"});
config.forEach(node => iq.cnode(node).up()); config.forEach(node => iq.cnode(node).up());
callback = _.isUndefined(callback) ? _.noop : _.partial(callback, iq.nodeTree); return _converse.api.sendIQ(iq);
errback = _.isUndefined(errback) ? _.noop : _.partial(errback, iq.nodeTree);
return _converse.api.sendIQ(iq).then(callback).catch(errback);
}, },
/** /**
...@@ -1138,7 +1130,7 @@ converse.plugins.add('converse-muc', { ...@@ -1138,7 +1130,7 @@ converse.plugins.add('converse-muc', {
* a string if only one affiliation. * a string if only one affiliation.
* @param { function } deltaFunc - The function to compute the delta * @param { function } deltaFunc - The function to compute the delta
* between old and new member lists. * between old and new member lists.
* @returns { promise } * @returns { Promise }
* A promise which is resolved once the list has been * A promise which is resolved once the list has been
* updated or once it's been established there's no need * updated or once it's been established there's no need
* to update the list. * to update the list.
...@@ -1156,7 +1148,7 @@ converse.plugins.add('converse-muc', { ...@@ -1156,7 +1148,7 @@ converse.plugins.add('converse-muc', {
* nickname and if found, persist that to the model state. * nickname and if found, persist that to the model state.
* @private * @private
* @method _converse.ChatRoom#getAndPersistNickname * @method _converse.ChatRoom#getAndPersistNickname
* @returns { promise } A promise which resolves with the nickname * @returns { Promise<string> } A promise which resolves with the nickname
*/ */
async getAndPersistNickname (nick) { async getAndPersistNickname (nick) {
nick = nick || nick = nick ||
...@@ -1176,7 +1168,7 @@ converse.plugins.add('converse-muc', { ...@@ -1176,7 +1168,7 @@ converse.plugins.add('converse-muc', {
* If so, we'll use that, otherwise we render the nickname form. * If so, we'll use that, otherwise we render the nickname form.
* @private * @private
* @method _converse.ChatRoom#getReservedNick * @method _converse.ChatRoom#getReservedNick
* @returns { promise } A promise which resolves with the reserved nick or null * @returns { Promise<string> } A promise which resolves with the reserved nick or null
*/ */
async getReservedNick () { async getReservedNick () {
let iq; let iq;
......
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