|
@@ -23,17 +23,27 @@
|
|
const TRUSTED = 1;
|
|
const TRUSTED = 1;
|
|
const UNTRUSTED = -1;
|
|
const UNTRUSTED = -1;
|
|
|
|
|
|
- function contactHasOMEMOSupport (_converse, contact_jid) {
|
|
|
|
|
|
+ function getDevicesForContact (_converse, jid) {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
- _converse.api.waitUntil('OMEMOInitialized', () => {
|
|
|
|
- resolve(_converse.devicelists.get(contact_jid).devices.length > 0);
|
|
|
|
- });
|
|
|
|
|
|
+ _converse.api.waitUntil('OMEMOInitialized').then(() => {
|
|
|
|
+ const devicelist = _converse.devicelists.get(jid);
|
|
|
|
+ resolve(devicelist ? devicelist.devices : []);
|
|
|
|
+ }).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function contactHasOMEMOSupport (_converse, jid) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ getDevicesForContact(_converse, jid).then((devices) => {
|
|
|
|
+ resolve(devices.length > 0)
|
|
|
|
+ }).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
function serverHasOMEMOSupport (_converse) {
|
|
function serverHasOMEMOSupport (_converse) {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
- _converse.api.disco.getIdentity('pubsub', 'pep').then((identity) => resolve(!_.isNil(identity)))
|
|
|
|
|
|
+ _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid)
|
|
|
|
+ .then((identity) => resolve(!_.isNil(identity)));
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -48,14 +58,14 @@
|
|
|
|
|
|
addOMEMOToolbarButton (options) {
|
|
addOMEMOToolbarButton (options) {
|
|
const { _converse } = this.__super__;
|
|
const { _converse } = this.__super__;
|
|
-
|
|
|
|
Promise.all([
|
|
Promise.all([
|
|
contactHasOMEMOSupport(_converse, this.model.get('jid')),
|
|
contactHasOMEMOSupport(_converse, this.model.get('jid')),
|
|
serverHasOMEMOSupport(_converse)
|
|
serverHasOMEMOSupport(_converse)
|
|
- ]).then((client_support, server_support) => {
|
|
|
|
- debugger;
|
|
|
|
|
|
+ ]).then((support) => {
|
|
|
|
+ const client_supports = support[0],
|
|
|
|
+ server_supports = support[1];
|
|
|
|
|
|
- if (client_support && server_support) {
|
|
|
|
|
|
+ if (client_supports && server_supports) {
|
|
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
|
|
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
|
|
'beforeend',
|
|
'beforeend',
|
|
tpl_toolbar_omemo({'__': __}));
|
|
tpl_toolbar_omemo({'__': __}));
|
|
@@ -124,12 +134,15 @@
|
|
|
|
|
|
initialize () {
|
|
initialize () {
|
|
this.devices = new _converse.Devices();
|
|
this.devices = new _converse.Devices();
|
|
|
|
+ this.devices.browserStorage = new Backbone.BrowserStorage.session(
|
|
|
|
+ b64_sha1(`converse.devicelist-${_converse.bare_jid}-${this.get('jid')}`)
|
|
|
|
+ );
|
|
},
|
|
},
|
|
|
|
|
|
fetchDevices () {
|
|
fetchDevices () {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
this.devices.fetch({
|
|
this.devices.fetch({
|
|
- success (collection) {
|
|
|
|
|
|
+ 'success': (collection) => {
|
|
if (collection.length === 0) {
|
|
if (collection.length === 0) {
|
|
this.fetchDevicesFromServer().then(resolve).catch(reject);
|
|
this.fetchDevicesFromServer().then(resolve).catch(reject);
|
|
} else {
|
|
} else {
|
|
@@ -168,9 +181,15 @@
|
|
/* If our own device is not on the list, add it.
|
|
/* If our own device is not on the list, add it.
|
|
* Also, deduplicate devices if necessary.
|
|
* Also, deduplicate devices if necessary.
|
|
*/
|
|
*/
|
|
- // TODO:
|
|
|
|
- const devicelist = _converse.devicelists.get(_converse.bare_jid);
|
|
|
|
- return Promise.resolve();
|
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let own_devicelist = _converse.devicelists.get(_converse.bare_jid);
|
|
|
|
+ if (_.isNil(own_devicelist)) {
|
|
|
|
+ own_devicelist = _converse.devicelists.create({'jid': _converse.bare_jid});
|
|
|
|
+ }
|
|
|
|
+ own_devicelist.fetchDevices().then(resolve).catch(reject);
|
|
|
|
+ // TODO: if our own device is not onthe list, add it.
|
|
|
|
+ // TODO: deduplicate
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
function updateDevicesFromStanza (stanza) {
|
|
function updateDevicesFromStanza (stanza) {
|
|
@@ -207,7 +226,6 @@
|
|
*/
|
|
*/
|
|
publishBundle()
|
|
publishBundle()
|
|
.then(() => fetchDeviceLists())
|
|
.then(() => fetchDeviceLists())
|
|
- .then(() => _converse.devicelists.get(_converse.bare_jid).fetchDevices())
|
|
|
|
.then(() => updateOwnDeviceList())
|
|
.then(() => updateOwnDeviceList())
|
|
.then(() => _converse.emit('OMEMOInitialized'))
|
|
.then(() => _converse.emit('OMEMOInitialized'))
|
|
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
|
|
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
|