Use async/await and don't swallow errors.
Also, handle the error in `getRoomFeatures`
This commit is contained in:
parent
a4d608dcdf
commit
96f38150f9
43
dist/converse.js
vendored
43
dist/converse.js
vendored
|
@ -64630,25 +64630,18 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
|
||||||
this.items.fetch();
|
this.items.fetch();
|
||||||
},
|
},
|
||||||
|
|
||||||
getIdentity(category, type) {
|
async getIdentity(category, type) {
|
||||||
/* Returns a Promise which resolves with a map indicating
|
/* Returns a Promise which resolves with a map indicating
|
||||||
* whether a given identity is provided.
|
* whether a given identity is provided by this entity.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* (String) category - The identity category
|
* (String) category - The identity category
|
||||||
* (String) type - The identity type
|
* (String) type - The identity type
|
||||||
*/
|
*/
|
||||||
const entity = this;
|
await this.waitUntilFeaturesDiscovered;
|
||||||
return new Promise((resolve, reject) => {
|
return this.identities.findWhere({
|
||||||
function fulfillPromise() {
|
'category': category,
|
||||||
const model = entity.identities.findWhere({
|
'type': type
|
||||||
'category': category,
|
|
||||||
'type': type
|
|
||||||
});
|
|
||||||
resolve(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.waitUntilFeaturesDiscovered.then(fulfillPromise).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -66590,26 +66583,26 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
|
||||||
return this.getRoomFeatures();
|
return this.getRoomFeatures();
|
||||||
},
|
},
|
||||||
|
|
||||||
async getRoomIdentity() {
|
async getRoomFeatures() {
|
||||||
const _ref = await Promise.all([_converse.api.disco.getIdentity('conference', 'text', this.get('jid')), _converse.api.disco.getFields(this.get('jid'))]),
|
let identity;
|
||||||
_ref2 = _slicedToArray(_ref, 2),
|
|
||||||
identity = _ref2[0],
|
|
||||||
fields = _ref2[1];
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
identity = await _converse.api.disco.getIdentity('conference', 'text', this.get('jid'));
|
||||||
|
} catch (e) {
|
||||||
|
// Getting the identity probably failed because this room doesn't exist yet.
|
||||||
|
return _converse.log(e, Strophe.LogLevel.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fields = await _converse.api.disco.getFields(this.get('jid'));
|
||||||
this.save({
|
this.save({
|
||||||
'name': identity && identity.get('name'),
|
'name': identity && identity.get('name'),
|
||||||
'description': _.get(fields.findWhere({
|
'description': _.get(fields.findWhere({
|
||||||
'var': "muc#roominfo_description"
|
'var': "muc#roominfo_description"
|
||||||
}), 'attributes.value')
|
}), 'attributes.value')
|
||||||
});
|
});
|
||||||
},
|
const features = await _converse.api.disco.getFeatures(this.get('jid'));
|
||||||
|
|
||||||
async getRoomFeatures() {
|
const attrs = _.extend(_.zipObject(_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].ROOM_FEATURES, _.map(_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].ROOM_FEATURES, _.stubFalse)), {
|
||||||
// XXX: not sure whet the right place is to get the room identitiy
|
|
||||||
this.getRoomIdentity();
|
|
||||||
|
|
||||||
const features = await _converse.api.disco.getFeatures(this.get('jid')),
|
|
||||||
attrs = _.extend(_.zipObject(_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].ROOM_FEATURES, _.map(_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].ROOM_FEATURES, _.stubFalse)), {
|
|
||||||
'fetched': moment().format()
|
'fetched': moment().format()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -64,26 +64,18 @@ converse.plugins.add('converse-disco', {
|
||||||
this.items.fetch();
|
this.items.fetch();
|
||||||
},
|
},
|
||||||
|
|
||||||
getIdentity (category, type) {
|
async getIdentity (category, type) {
|
||||||
/* Returns a Promise which resolves with a map indicating
|
/* Returns a Promise which resolves with a map indicating
|
||||||
* whether a given identity is provided.
|
* whether a given identity is provided by this entity.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* (String) category - The identity category
|
* (String) category - The identity category
|
||||||
* (String) type - The identity type
|
* (String) type - The identity type
|
||||||
*/
|
*/
|
||||||
const entity = this;
|
await this.waitUntilFeaturesDiscovered;
|
||||||
return new Promise((resolve, reject) => {
|
return this.identities.findWhere({
|
||||||
function fulfillPromise () {
|
'category': category,
|
||||||
const model = entity.identities.findWhere({
|
'type': type
|
||||||
'category': category,
|
|
||||||
'type': type
|
|
||||||
});
|
|
||||||
resolve(model);
|
|
||||||
}
|
|
||||||
entity.waitUntilFeaturesDiscovered
|
|
||||||
.then(fulfillPromise)
|
|
||||||
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -502,26 +502,25 @@ converse.plugins.add('converse-muc', {
|
||||||
return this.getRoomFeatures();
|
return this.getRoomFeatures();
|
||||||
},
|
},
|
||||||
|
|
||||||
async getRoomIdentity () {
|
async getRoomFeatures () {
|
||||||
const [identity, fields] = await Promise.all([
|
let identity;
|
||||||
_converse.api.disco.getIdentity('conference', 'text', this.get('jid')),
|
try {
|
||||||
_converse.api.disco.getFields(this.get('jid'))
|
identity = await _converse.api.disco.getIdentity('conference', 'text', this.get('jid'));
|
||||||
]);
|
} catch (e) {
|
||||||
|
// Getting the identity probably failed because this room doesn't exist yet.
|
||||||
|
return _converse.log(e, Strophe.LogLevel.ERROR);
|
||||||
|
}
|
||||||
|
const fields = await _converse.api.disco.getFields(this.get('jid'));
|
||||||
this.save({
|
this.save({
|
||||||
'name': identity && identity.get('name'),
|
'name': identity && identity.get('name'),
|
||||||
'description': _.get(fields.findWhere({'var': "muc#roominfo_description"}), 'attributes.value')
|
'description': _.get(fields.findWhere({'var': "muc#roominfo_description"}), 'attributes.value')
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
async getRoomFeatures () {
|
|
||||||
// XXX: not sure whet the right place is to get the room identitiy
|
|
||||||
this.getRoomIdentity();
|
|
||||||
const features = await _converse.api.disco.getFeatures(this.get('jid')),
|
|
||||||
attrs = _.extend(
|
|
||||||
_.zipObject(converse.ROOM_FEATURES, _.map(converse.ROOM_FEATURES, _.stubFalse)),
|
|
||||||
{'fetched': moment().format()}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
const features = await _converse.api.disco.getFeatures(this.get('jid'));
|
||||||
|
const attrs = _.extend(
|
||||||
|
_.zipObject(converse.ROOM_FEATURES, _.map(converse.ROOM_FEATURES, _.stubFalse)),
|
||||||
|
{'fetched': moment().format()}
|
||||||
|
);
|
||||||
features.each(feature => {
|
features.each(feature => {
|
||||||
const fieldname = feature.get('var');
|
const fieldname = feature.get('var');
|
||||||
if (!fieldname.startsWith('muc_')) {
|
if (!fieldname.startsWith('muc_')) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user