Skip to content

Commit 802f2b2

Browse files
committed
converse-muc: Update sendConfiguration to not take callbacks
1 parent d95a798 commit 802f2b2

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

src/headless/converse-muc.js

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -878,16 +878,14 @@ converse.plugins.add('converse-muc', {
878878
* @param { HTMLElement } form - The configuration form DOM element.
879879
* If no form is provided, the default configuration
880880
* values will be used.
881-
* @returns { promise }
881+
* @returns { Promise<XMLElement> }
882882
* Returns a promise which resolves once the XMPP server
883883
* has return a response IQ.
884884
*/
885885
saveConfiguration (form) {
886-
return new Promise((resolve, reject) => {
887-
const inputs = form ? sizzle(':input:not([type=button]):not([type=submit])', form) : [],
888-
configArray = _.map(inputs, u.webForm2xForm);
889-
this.sendConfiguration(configArray, resolve, reject);
890-
});
886+
const inputs = form ? sizzle(':input:not([type=button]):not([type=submit])', form) : [],
887+
configArray = _.map(inputs, u.webForm2xForm);
888+
return this.sendConfiguration(configArray);
891889
},
892890

893891
/**
@@ -926,54 +924,48 @@ converse.plugins.add('converse-muc', {
926924
* 'roomconfig' data.
927925
* @private
928926
* @method _converse.ChatRoom#autoConfigureChatRoom
929-
* @returns { promise }
927+
* @returns { Promise<XMLElement> }
930928
* Returns a promise which resolves once a response IQ has
931929
* been received.
932930
*/
933-
autoConfigureChatRoom () {
934-
return new Promise(async (resolve, reject) => { /* eslint-disable-line no-async-promise-executor */
935-
const stanza = await this.fetchRoomConfiguration();
936-
const fields = sizzle('field', stanza);
937-
const configArray = fields.map(f => this.addFieldValue(f))
938-
if (configArray.length) {
939-
this.sendConfiguration(configArray, resolve, reject);
940-
}
941-
});
931+
async autoConfigureChatRoom () {
932+
const stanza = await this.fetchRoomConfiguration();
933+
const fields = sizzle('field', stanza);
934+
const configArray = fields.map(f => this.addFieldValue(f))
935+
if (configArray.length) {
936+
return this.sendConfiguration(configArray);
937+
}
942938
},
943939

940+
/**
941+
* Send an IQ stanza to fetch the groupchat configuration data.
942+
* Returns a promise which resolves once the response IQ
943+
* has been received.
944+
* @private
945+
* @method _converse.ChatRoom#fetchRoomConfiguration
946+
* @returns { Promise<XMLElement> }
947+
*/
944948
fetchRoomConfiguration () {
945-
/* Send an IQ stanza to fetch the groupchat configuration data.
946-
* Returns a promise which resolves once the response IQ
947-
* has been received.
948-
*/
949949
return _converse.api.sendIQ(
950950
$iq({'to': this.get('jid'), 'type': "get"})
951951
.c("query", {xmlns: Strophe.NS.MUC_OWNER})
952952
);
953953
},
954954

955955
/**
956-
* Send an IQ stanza with the groupchat configuration.
956+
* Sends an IQ stanza with the groupchat configuration.
957957
* @private
958958
* @method _converse.ChatRoom#sendConfiguration
959959
* @param { Array } config - The groupchat configuration
960-
* @param { Function } callback - Callback upon succesful IQ response
961-
* The first parameter passed in is IQ containing the
962-
* groupchat configuration.
963-
* The second is the response IQ from the server.
964-
* @param { Function } errback - Callback upon error IQ response
965-
* The first parameter passed in is IQ containing the
966-
* groupchat configuration.
967-
* The second is the response IQ from the server.
960+
* @returns { Promise<XMLElement> } - A promise which resolves with
961+
* the `result` stanza received from the XMPP server.
968962
*/
969-
sendConfiguration (config=[], callback, errback) {
963+
sendConfiguration (config=[]) {
970964
const iq = $iq({to: this.get('jid'), type: "set"})
971965
.c("query", {xmlns: Strophe.NS.MUC_OWNER})
972966
.c("x", {xmlns: Strophe.NS.XFORM, type: "submit"});
973967
config.forEach(node => iq.cnode(node).up());
974-
callback = _.isUndefined(callback) ? _.noop : _.partial(callback, iq.nodeTree);
975-
errback = _.isUndefined(errback) ? _.noop : _.partial(errback, iq.nodeTree);
976-
return _converse.api.sendIQ(iq).then(callback).catch(errback);
968+
return _converse.api.sendIQ(iq);
977969
},
978970

979971
/**
@@ -1138,7 +1130,7 @@ converse.plugins.add('converse-muc', {
11381130
* a string if only one affiliation.
11391131
* @param { function } deltaFunc - The function to compute the delta
11401132
* between old and new member lists.
1141-
* @returns { promise }
1133+
* @returns { Promise }
11421134
* A promise which is resolved once the list has been
11431135
* updated or once it's been established there's no need
11441136
* to update the list.
@@ -1156,7 +1148,7 @@ converse.plugins.add('converse-muc', {
11561148
* nickname and if found, persist that to the model state.
11571149
* @private
11581150
* @method _converse.ChatRoom#getAndPersistNickname
1159-
* @returns { promise } A promise which resolves with the nickname
1151+
* @returns { Promise<string> } A promise which resolves with the nickname
11601152
*/
11611153
async getAndPersistNickname (nick) {
11621154
nick = nick ||
@@ -1176,7 +1168,7 @@ converse.plugins.add('converse-muc', {
11761168
* If so, we'll use that, otherwise we render the nickname form.
11771169
* @private
11781170
* @method _converse.ChatRoom#getReservedNick
1179-
* @returns { promise } A promise which resolves with the reserved nick or null
1171+
* @returns { Promise<string> } A promise which resolves with the reserved nick or null
11801172
*/
11811173
async getReservedNick () {
11821174
let iq;

0 commit comments

Comments
 (0)