Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
96f38150
Commit
96f38150
authored
Jan 10, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async/await and don't swallow errors.
Also, handle the error in `getRoomFeatures`
parent
a4d608dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
54 deletions
+38
-54
dist/converse.js
dist/converse.js
+18
-25
src/headless/converse-disco.js
src/headless/converse-disco.js
+6
-14
src/headless/converse-muc.js
src/headless/converse-muc.js
+14
-15
No files found.
dist/converse.js
View file @
96f38150
...
...
@@ -64630,25 +64630,18 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
this.items.fetch();
},
getIdentity(category, type) {
async
getIdentity(category, type) {
/* 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:
* (String) category - The identity category
* (String) type - The identity type
*/
const entity = this;
return new Promise((resolve, reject) => {
function fulfillPromise() {
const model = entity.identities.findWhere({
'category': category,
'type': type
});
resolve(model);
}
entity.waitUntilFeaturesDiscovered.then(fulfillPromise).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
await this.waitUntilFeaturesDiscovered;
return this.identities.findWhere({
'category': category,
'type': type
});
},
...
...
@@ -66590,26 +66583,26 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
return this.getRoomFeatures();
},
async getRoomIdentity() {
const _ref = await Promise.all([_converse.api.disco.getIdentity('conference', 'text', this.get('jid')), _converse.api.disco.getFields(this.get('jid'))]),
_ref2 = _slicedToArray(_ref, 2),
identity = _ref2[0],
fields = _ref2[1];
async getRoomFeatures() {
let identity;
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({
'name': identity && identity.get('name'),
'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'));
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)), {
const 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()
});
src/headless/converse-disco.js
View file @
96f38150
...
...
@@ -64,26 +64,18 @@ converse.plugins.add('converse-disco', {
this
.
items
.
fetch
();
},
getIdentity
(
category
,
type
)
{
async
getIdentity
(
category
,
type
)
{
/* 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:
* (String) category - The identity category
* (String) type - The identity type
*/
const
entity
=
this
;
return
new
Promise
((
resolve
,
reject
)
=>
{
function
fulfillPromise
()
{
const
model
=
entity
.
identities
.
findWhere
({
'
category
'
:
category
,
'
type
'
:
type
});
resolve
(
model
);
}
entity
.
waitUntilFeaturesDiscovered
.
then
(
fulfillPromise
)
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
await
this
.
waitUntilFeaturesDiscovered
;
return
this
.
identities
.
findWhere
({
'
category
'
:
category
,
'
type
'
:
type
});
},
...
...
src/headless/converse-muc.js
View file @
96f38150
...
...
@@ -502,26 +502,25 @@ converse.plugins.add('converse-muc', {
return
this
.
getRoomFeatures
();
},
async
getRoomIdentity
()
{
const
[
identity
,
fields
]
=
await
Promise
.
all
([
_converse
.
api
.
disco
.
getIdentity
(
'
conference
'
,
'
text
'
,
this
.
get
(
'
jid
'
)),
_converse
.
api
.
disco
.
getFields
(
this
.
get
(
'
jid
'
))
]);
async
getRoomFeatures
()
{
let
identity
;
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
({
'
name
'
:
identity
&&
identity
.
get
(
'
name
'
),
'
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
=>
{
const
fieldname
=
feature
.
get
(
'
var
'
);
if
(
!
fieldname
.
startsWith
(
'
muc_
'
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment