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
461ebc0a
Commit
461ebc0a
authored
Nov 09, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async/await instead of explicit promises
parent
d9093c09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
65 deletions
+73
-65
dist/converse.js
dist/converse.js
+41
-32
src/converse-omemo.js
src/converse-omemo.js
+32
-33
No files found.
dist/converse.js
View file @
461ebc0a
...
...
@@ -65812,21 +65812,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
return _converse.getDevicesForContact(jid).then(devices => devices.get(device_id));
};
_converse.getDevicesForContact = function (jid) {
let devicelist;
return _converse.api.waitUntil('OMEMOInitialized').then(() => {
devicelist = _converse.devicelists.get(jid) || _converse.devicelists.create({
'jid': jid
});
return devicelist.fetchDevices();
}).then(() => devicelist.devices);
_converse.getDevicesForContact = async function (jid) {
await _converse.api.waitUntil('OMEMOInitialized');
const devicelist = _converse.devicelists.get(jid) || _converse.devicelists.create({
'jid': jid
});
await devicelist.fetchDevices();
return devicelist.devices;
};
_converse.contactHasOMEMOSupport = function (jid) {
_converse.contactHasOMEMOSupport =
async
function (jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
_converse.getDevicesForContact(jid).then(devices => resolve(devices.length > 0)).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
const devices = await _converse.getDevicesForContact(jid);
return devices.length > 0;
};
function generateDeviceID() {
...
...
@@ -66192,22 +66192,23 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
fetchDevices() {
if (_.isUndefined(this._devices_promise)) {
this._devices_promise = new Promise((resolve, reject) => {
this.devices.fetch({
'success': collection => {
if (collection.length === 0) {
this.fetchDevicesFromServer().then(ids => this.publishCurrentDevice(ids)).finally(resolve);
} else {
resolve();
}
}
});
});
const options = {
'success': c => this.onCachedDevicesFetched(c),
'error': e => _converse.log(e, Strophe.LogLevel.ERROR)
};
this._devices_promise = this.devices.fetch(options);
}
return this._devices_promise;
},
async onCachedDevicesFetched(collection) {
if (collection.length === 0) {
const ids = await this.fetchDevicesFromServer();
this.publishCurrentDevice(ids);
}
},
async publishCurrentDevice(device_ids) {
if (this.get('jid') !== _converse.bare_jid) {
// We only publish for ourselves.
...
...
@@ -66231,7 +66232,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
}
},
fetchDevicesFromServer() {
async
fetchDevicesFromServer() {
const stanza = $iq({
'type': 'get',
'from': _converse.bare_jid,
...
...
@@ -66241,16 +66242,24 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
}).c('items', {
'node': Strophe.NS.OMEMO_DEVICELIST
});
return _converse.api.sendIQ(stanza).then(iq => {
const device_ids = _.map(sizzle(`list[xmlns="${Strophe.NS.OMEMO}"] device`, iq), dev => dev.getAttribute('id'));
let iq;
_.forEach(device_ids, id => this.devices.create(
{
'id': id,
'jid': this.get('jid')
})
);
try
{
iq = await _converse.api.sendIQ(stanza);
} catch (e) {
_converse.log(e, Strophe.LogLevel.ERROR
);
return device_ids;
});
return [];
}
const device_ids = _.map(sizzle(`list[xmlns="${Strophe.NS.OMEMO}"] device`, iq), dev => dev.getAttribute('id'));
_.forEach(device_ids, id => this.devices.create({
'id': id,
'jid': this.get('jid')
}));
return device_ids;
},
publishDevices() {
src/converse-omemo.js
View file @
461ebc0a
...
...
@@ -497,22 +497,17 @@ converse.plugins.add('converse-omemo', {
return
_converse
.
getDevicesForContact
(
jid
).
then
(
devices
=>
devices
.
get
(
device_id
));
}
_converse
.
getDevicesForContact
=
function
(
jid
)
{
let
devicelist
;
return
_converse
.
api
.
waitUntil
(
'
OMEMOInitialized
'
)
.
then
(()
=>
{
devicelist
=
_converse
.
devicelists
.
get
(
jid
)
||
_converse
.
devicelists
.
create
({
'
jid
'
:
jid
});
return
devicelist
.
fetchDevices
();
}).
then
(()
=>
devicelist
.
devices
);
_converse
.
getDevicesForContact
=
async
function
(
jid
)
{
await
_converse
.
api
.
waitUntil
(
'
OMEMOInitialized
'
);
const
devicelist
=
_converse
.
devicelists
.
get
(
jid
)
||
_converse
.
devicelists
.
create
({
'
jid
'
:
jid
});
await
devicelist
.
fetchDevices
();
return
devicelist
.
devices
;
}
_converse
.
contactHasOMEMOSupport
=
function
(
jid
)
{
_converse
.
contactHasOMEMOSupport
=
async
function
(
jid
)
{
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return
new
Promise
((
resolve
,
reject
)
=>
{
_converse
.
getDevicesForContact
(
jid
)
.
then
((
devices
)
=>
resolve
(
devices
.
length
>
0
))
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
ERROR
));
});
const
devices
=
await
_converse
.
getDevicesForContact
(
jid
);
return
devices
.
length
>
0
;
}
...
...
@@ -845,23 +840,22 @@ converse.plugins.add('converse-omemo', {
fetchDevices
()
{
if
(
_
.
isUndefined
(
this
.
_devices_promise
))
{
this
.
_devices_promise
=
new
Promise
((
resolve
,
reject
)
=>
{
this
.
devices
.
fetch
({
'
success
'
:
(
collection
)
=>
{
if
(
collection
.
length
===
0
)
{
this
.
fetchDevicesFromServer
()
.
then
(
ids
=>
this
.
publishCurrentDevice
(
ids
))
.
finally
(
resolve
)
}
else
{
resolve
();
}
}
});
});
const
options
=
{
'
success
'
:
c
=>
this
.
onCachedDevicesFetched
(
c
),
'
error
'
:
e
=>
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
)
}
this
.
_devices_promise
=
this
.
devices
.
fetch
(
options
);
}
return
this
.
_devices_promise
;
},
async
onCachedDevicesFetched
(
collection
)
{
if
(
collection
.
length
===
0
)
{
const
ids
=
await
this
.
fetchDevicesFromServer
()
this
.
publishCurrentDevice
(
ids
);
}
},
async
publishCurrentDevice
(
device_ids
)
{
if
(
this
.
get
(
'
jid
'
)
!==
_converse
.
bare_jid
)
{
// We only publish for ourselves.
...
...
@@ -879,19 +873,24 @@ converse.plugins.add('converse-omemo', {
}
},
fetchDevicesFromServer
()
{
async
fetchDevicesFromServer
()
{
const
stanza
=
$iq
({
'
type
'
:
'
get
'
,
'
from
'
:
_converse
.
bare_jid
,
'
to
'
:
this
.
get
(
'
jid
'
)
}).
c
(
'
pubsub
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
PUBSUB
})
.
c
(
'
items
'
,
{
'
node
'
:
Strophe
.
NS
.
OMEMO_DEVICELIST
});
return
_converse
.
api
.
sendIQ
(
stanza
)
.
then
(
iq
=>
{
const
device_ids
=
_
.
map
(
sizzle
(
`list[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"] device`
,
iq
),
dev
=>
dev
.
getAttribute
(
'
id
'
));
_
.
forEach
(
device_ids
,
id
=>
this
.
devices
.
create
({
'
id
'
:
id
,
'
jid
'
:
this
.
get
(
'
jid
'
)}));
return
device_ids
;
});
let
iq
;
try
{
iq
=
await
_converse
.
api
.
sendIQ
(
stanza
);
}
catch
(
e
)
{
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
);
return
[];
}
const
device_ids
=
_
.
map
(
sizzle
(
`list[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"] device`
,
iq
),
dev
=>
dev
.
getAttribute
(
'
id
'
));
_
.
forEach
(
device_ids
,
id
=>
this
.
devices
.
create
({
'
id
'
:
id
,
'
jid
'
:
this
.
get
(
'
jid
'
)}));
return
device_ids
;
},
publishDevices
()
{
...
...
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