Avoid unnecessary promise wrapping
This commit is contained in:
parent
16deecd468
commit
cce27fac99
@ -473,7 +473,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'supports' (feature, entity_jid) {
|
'supports' (feature, jid) {
|
||||||
/* Returns a Promise which resolves with a list containing
|
/* Returns a Promise which resolves with a list containing
|
||||||
* _converse.Entity instances representing the entity
|
* _converse.Entity instances representing the entity
|
||||||
* itself or those items associated with the entity if
|
* itself or those items associated with the entity if
|
||||||
@ -484,30 +484,25 @@
|
|||||||
* supported. In the XML stanza, this is the `var`
|
* supported. In the XML stanza, this is the `var`
|
||||||
* attribute of the `<feature>` element. For
|
* attribute of the `<feature>` element. For
|
||||||
* example: 'http://jabber.org/protocol/muc'
|
* example: 'http://jabber.org/protocol/muc'
|
||||||
* (String) entity_jid - The JID of the entity
|
* (String) jid - The JID of the entity
|
||||||
* (and its associated items) which should be queried
|
* (and its associated items) which should be queried
|
||||||
*/
|
*/
|
||||||
if (_.isNil(entity_jid)) {
|
if (_.isNil(jid)) {
|
||||||
throw new TypeError('disco.supports: You need to provide an entity JID');
|
throw new TypeError('disco.supports: You need to provide an entity JID');
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return _converse.api.waitUntil('discoInitialized')
|
||||||
return _converse.api.waitUntil('discoInitialized').then(() => {
|
.then(() => _converse.api.disco.entities.get(jid, true))
|
||||||
_converse.api.disco.entities.get(entity_jid, true).then((entity) => {
|
.then(entity => entity.waitUntilFeaturesDiscovered)
|
||||||
entity.waitUntilFeaturesDiscovered.then(() => {
|
.then(entity => {
|
||||||
const promises = _.concat(
|
const promises = _.concat(
|
||||||
entity.items.map((item) => item.hasFeature(feature)),
|
entity.items.map(item => item.hasFeature(feature)),
|
||||||
entity.hasFeature(feature)
|
entity.hasFeature(feature)
|
||||||
);
|
);
|
||||||
Promise.all(promises).then((result) => {
|
return Promise.all(promises);
|
||||||
resolve(f.filter(f.isObject, result));
|
}).then(result => f.filter(f.isObject, result));
|
||||||
}).catch(reject);
|
|
||||||
}).catch(reject);
|
|
||||||
}).catch(reject);
|
|
||||||
}).catch(reject);
|
|
||||||
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'getIdentity' (category, type, entity_jid) {
|
'getIdentity' (category, type, jid) {
|
||||||
/* Returns a Promise which resolves with a map indicating
|
/* Returns a Promise which resolves with a map indicating
|
||||||
* whether an identity with a given type is provided by
|
* whether an identity with a given type is provided by
|
||||||
* the entity.
|
* the entity.
|
||||||
@ -521,12 +516,9 @@
|
|||||||
* In the XML stanza, this is the `type`
|
* In the XML stanza, this is the `type`
|
||||||
* attribute of the `<identity>` element.
|
* attribute of the `<identity>` element.
|
||||||
* For example: 'pep'
|
* For example: 'pep'
|
||||||
* (String) entity_jid - The JID of the entity which might have the identity
|
* (String) jid - The JID of the entity which might have the identity
|
||||||
*/
|
*/
|
||||||
return new Promise((resolve, reject) => {
|
return _converse.api.disco.entities.get(jid, true).then(e => e.getIdentity(category, type));
|
||||||
_converse.api.disco.entities.get(entity_jid, true)
|
|
||||||
.then((entity) => resolve(entity.getIdentity(category, type)));
|
|
||||||
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user