Commit 281865d9 authored by JC Brand's avatar JC Brand

Based on feedback from @iNPUTmice, no need to check for PEP support

Since you can still start OMEMO sessions with contacts without it, they
just can't create sessions with you.
parent 09eb1731
......@@ -59,30 +59,10 @@
test_utils.waitUntil(function () {
return _.filter(_converse.connection.IQ_stanzas, function (iq) {
const node = iq.nodeTree.querySelector('iq[to="dummy@localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
const node = iq.nodeTree.querySelector('publish[node="eu.siacs.conversations.axolotl.bundles:31415"]');
if (node) { iq_stanza = iq.nodeTree; }
return node;
}).length > 0;
}, 1000).then(function () {
/* PEP support is prerequisite for OMEMO */
const stanza = $iq({
'type': 'result',
'from': 'dummy@localhost',
'to': 'dummy@localhost/resource',
'id': iq_stanza.getAttribute('id'),
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
.c('identity', {
'category': 'pubsub',
'type': 'pep'});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => {
return _.filter(_converse.connection.IQ_stanzas, function (iq) {
const node = iq.nodeTree.querySelector('publish[node="eu.siacs.conversations.axolotl.bundles:31415"]');
if (node) { iq_stanza = iq.nodeTree; }
return node;
}).length;
});
}).length;
}).then(function () {
expect(iq_stanza.getAttributeNames().sort().join()).toBe(["from", "type", "xmlns", "id"].sort().join());
expect(iq_stanza.querySelector('prekeys').childNodes.length).toBe(100);
......
......@@ -49,12 +49,6 @@
});
}
function serverHasOMEMOSupport (_converse) {
return new Promise((resolve, reject) => {
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid)
.then((identity) => resolve(!_.isNil(identity)));
});
}
converse.plugins.add('converse-omemo', {
......@@ -65,7 +59,6 @@
dependencies: ["converse-chatview"],
overrides: {
ChatBoxView: {
events: {
'click .toggle-omemo': 'toggleOMEMO'
......@@ -74,23 +67,6 @@
toggleOMEMO (ev) {
// TODO:
ev.preventDefault();
},
addOMEMOToolbarButton () {
const { _converse } = this.__super__,
{ __ } = _converse;
Promise.all([
contactHasOMEMOSupport(_converse, this.model.get('jid')),
serverHasOMEMOSupport(_converse)
]).then((support) => {
const client_supports = support[0],
server_supports = support[1];
if (client_supports && server_supports) {
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
'beforeend',
tpl_toolbar_omemo({'__': __}));
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}
}
},
......@@ -268,6 +244,8 @@
}
function updateDevicesFromStanza (stanza) {
// TODO: check whether our own device_id is still on the list,
// otherwise we need to update it.
const device_ids = _.map(
sizzle(`items[node="${Strophe.NS.OMEMO_DEVICELIST}"] item[xmlns="${Strophe.NS.OMEMO}"] device`, stanza),
(device) => device.getAttribute('id'));
......@@ -289,7 +267,7 @@
// Add a handler for devices pushed from other connected clients
_converse.connection.addHandler((message) => {
if (message.querySelector('event[xmlns="'+Strophe.NS.PUBSUB+'#event"]')) {
_converse.bookmarks.updateDevicesFromStanza(message);
updateDevicesFromStanza(message);
}
}, null, 'message', 'headline', null, _converse.bare_jid);
}
......@@ -302,31 +280,33 @@
return _converse.omemo_store.fetchSession()
}
function initOMEMO () {
/* Publish our bundle and then fetch our own device list.
* If our device list does not contain this device's id, publish the
* device list with the id added. Also deduplicate device ids in the list.
*/
restoreOMEMOSession()
.then(() => publishBundle())
.then(() => updateOwnDeviceList())
.then(() => _converse.emit('OMEMOInitialized'))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
function addOMEMOToolbarButton (view) {
const { __ } = _converse;
contactHasOMEMOSupport(_converse, view.model.get('jid')).then((support) => {
if (support) {
view.el.querySelector('.chat-toolbar').insertAdjacentHTML(
'beforeend',
tpl_toolbar_omemo({'__': __}));
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}
function onStatusInitialized () {
function initOMEMO() {
_converse.devicelists = new _converse.DeviceLists();
_converse.devicelists.browserStorage = new Backbone.BrowserStorage.session(
b64_sha1(`converse.devicelists-${_converse.bare_jid}`)
);
initOMEMO();
restoreOMEMOSession()
.then(() => publishBundle())
.then(() => updateOwnDeviceList())
.then(() => _converse.emit('OMEMOInitialized'))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}
_converse.api.listen.on('renderToolbar', (view) => view.addOMEMOToolbarButton());
_converse.api.listen.on('statusInitialized', onStatusInitialized);
_converse.api.listen.on('connected', registerPEPPushHandler);
_converse.api.listen.on('afterTearDown', () => _converse.devices.reset());
_converse.api.listen.on('connected', registerPEPPushHandler);
_converse.api.listen.on('renderToolbar', addOMEMOToolbarButton);
_converse.api.listen.on('statusInitialized', initOMEMO);
_converse.api.listen.on('addClientFeatures',
() => _converse.api.disco.own.features.add(Strophe.NS.OMEMO_DEVICELIST+"notify"));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment