Commit 54c90e14 authored by JC Brand's avatar JC Brand

Replace lodash methods with built-ins

parent 54b3fc6d
...@@ -1310,10 +1310,8 @@ converse.plugins.add('converse-chatview', { ...@@ -1310,10 +1310,8 @@ converse.plugins.add('converse-chatview', {
}); });
}); });
_converse.api.listen.on('connected', () => {
// Advertise that we support XEP-0382 Message Spoilers // Advertise that we support XEP-0382 Message Spoilers
_converse.api.disco.own.features.add(Strophe.NS.SPOILER); _converse.api.listen.on('connected', () => _converse.api.disco.own.features.add(Strophe.NS.SPOILER));
});
/************************ BEGIN API ************************/ /************************ BEGIN API ************************/
Object.assign(_converse.api, { Object.assign(_converse.api, {
...@@ -1327,15 +1325,13 @@ converse.plugins.add('converse-chatview', { ...@@ -1327,15 +1325,13 @@ converse.plugins.add('converse-chatview', {
'chatviews': { 'chatviews': {
/** /**
* Get the view of an already open chat. * Get the view of an already open chat.
*
* @method _converse.api.chatviews.get * @method _converse.api.chatviews.get
* @param { Array.string | string } jids
* @returns {ChatBoxView} A [Backbone.View](http://backbonejs.org/#View) instance. * @returns {ChatBoxView} A [Backbone.View](http://backbonejs.org/#View) instance.
* The chat should already be open, otherwise `undefined` will be returned. * The chat should already be open, otherwise `undefined` will be returned.
*
* @example * @example
* // To return a single view, provide the JID of the contact: * // To return a single view, provide the JID of the contact:
* _converse.api.chatviews.get('buddy@example.com') * _converse.api.chatviews.get('buddy@example.com')
*
* @example * @example
* // To return an array of views, provide an array of JIDs: * // To return an array of views, provide an array of JIDs:
* _converse.api.chatviews.get(['buddy1@example.com', 'buddy2@example.com']) * _converse.api.chatviews.get(['buddy1@example.com', 'buddy2@example.com'])
...@@ -1351,7 +1347,7 @@ converse.plugins.add('converse-chatview', { ...@@ -1351,7 +1347,7 @@ converse.plugins.add('converse-chatview', {
if (_.isString(jids)) { if (_.isString(jids)) {
return _converse.chatboxviews.get(jids); return _converse.chatboxviews.get(jids);
} }
return _.map(jids, (jid) => _converse.chatboxviews.get(jids)); return jids.map(jid => _converse.chatboxviews.get(jids));
} }
} }
}); });
......
...@@ -48,14 +48,12 @@ function parseBundle (bundle_el) { ...@@ -48,14 +48,12 @@ function parseBundle (bundle_el) {
signed_prekey_signature_el = bundle_el.querySelector('signedPreKeySignature'), signed_prekey_signature_el = bundle_el.querySelector('signedPreKeySignature'),
identity_key_el = bundle_el.querySelector('identityKey'); identity_key_el = bundle_el.querySelector('identityKey');
const prekeys = _.map( const prekeys = sizzle(`prekeys > preKeyPublic`, bundle_el)
sizzle(`prekeys > preKeyPublic`, bundle_el), .map(el => ({
(el) => {
return {
'id': parseInt(el.getAttribute('preKeyId'), 10), 'id': parseInt(el.getAttribute('preKeyId'), 10),
'key': el.textContent 'key': el.textContent
} }));
});
return { return {
'identity_key': bundle_el.querySelector('identityKey').textContent.trim(), 'identity_key': bundle_el.querySelector('identityKey').textContent.trim(),
'signed_prekey': { 'signed_prekey': {
...@@ -122,8 +120,7 @@ converse.plugins.add('converse-omemo', { ...@@ -122,8 +120,7 @@ converse.plugins.add('converse-omemo', {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
ev.target.querySelector('.select-all').checked = false ev.target.querySelector('.select-all').checked = false
const checkboxes = ev.target.querySelectorAll('.fingerprint-removal-item input[type="checkbox"]:checked'), const device_ids = sizzle('.fingerprint-removal-item input[type="checkbox"]:checked', ev.target).map(c => c.value);
device_ids = _.map(checkboxes, 'value');
this.devicelist.removeOwnDevices(device_ids) this.devicelist.removeOwnDevices(device_ids)
.then(this.modal.hide) .then(this.modal.hide)
.catch(err => { .catch(err => {
...@@ -848,19 +845,19 @@ converse.plugins.add('converse-omemo', { ...@@ -848,19 +845,19 @@ converse.plugins.add('converse-omemo', {
}, },
async generateMissingPreKeys () { async generateMissingPreKeys () {
const current_keys = this.getPreKeys(), const missing_keys = _.difference(
missing_keys = _.difference(_.invokeMap(_.range(0, _converse.NUM_PREKEYS), Number.prototype.toString), Object.keys(current_keys)); _.invokeMap(_.range(0, _converse.NUM_PREKEYS), Number.prototype.toString),
Object.keys(this.getPreKeys())
);
if (missing_keys.length < 1) { if (missing_keys.length < 1) {
_converse.log("No missing prekeys to generate for our own device", Strophe.LogLevel.WARN); _converse.log("No missing prekeys to generate for our own device", Strophe.LogLevel.WARN);
return Promise.resolve(); return Promise.resolve();
} }
const keys = await Promise.all(_.map(missing_keys, id => libsignal.KeyHelper.generatePreKey(parseInt(id, 10)))); const keys = await Promise.all(missing_keys.map(id => libsignal.KeyHelper.generatePreKey(parseInt(id, 10))));
_.forEach(keys, k => this.storePreKey(k.keyId, k.keyPair)); keys.forEach(k => this.storePreKey(k.keyId, k.keyPair));
const marshalled_keys = _.map(this.getPreKeys(), k => ({'id': k.keyId, 'key': u.arrayBufferToBase64(k.pubKey)})), const marshalled_keys = Object.keys(this.getPreKeys()).map(k => ({'id': k.keyId, 'key': u.arrayBufferToBase64(k.pubKey)}));
devicelist = _converse.devicelists.get(_converse.bare_jid), const devicelist = _converse.devicelists.get(_converse.bare_jid);
device = devicelist.devices.get(this.get('device_id')); const device = devicelist.devices.get(this.get('device_id'));
const bundle = await device.getBundle(); const bundle = await device.getBundle();
device.save('bundle', Object.assign(bundle, {'prekeys': marshalled_keys})); device.save('bundle', Object.assign(bundle, {'prekeys': marshalled_keys}));
}, },
...@@ -895,11 +892,11 @@ converse.plugins.add('converse-omemo', { ...@@ -895,11 +892,11 @@ converse.plugins.add('converse-omemo', {
'public_key': u.arrayBufferToBase64(signed_prekey.keyPair.privKey), 'public_key': u.arrayBufferToBase64(signed_prekey.keyPair.privKey),
'signature': u.arrayBufferToBase64(signed_prekey.signature) 'signature': u.arrayBufferToBase64(signed_prekey.signature)
} }
const keys = await Promise.all(_.map(_.range(0, _converse.NUM_PREKEYS), id => libsignal.KeyHelper.generatePreKey(id))); const keys = await Promise.all(_.range(0, _converse.NUM_PREKEYS).map(id => libsignal.KeyHelper.generatePreKey(id)));
_.forEach(keys, k => _converse.omemo_store.storePreKey(k.keyId, k.keyPair)); keys.forEach(k => _converse.omemo_store.storePreKey(k.keyId, k.keyPair));
const devicelist = _converse.devicelists.get(_converse.bare_jid), const devicelist = _converse.devicelists.get(_converse.bare_jid);
device = devicelist.devices.create({'id': bundle.device_id, 'jid': _converse.bare_jid}), const device = devicelist.devices.create({'id': bundle.device_id, 'jid': _converse.bare_jid});
marshalled_keys = _.map(keys, k => ({'id': k.keyId, 'key': u.arrayBufferToBase64(k.keyPair.pubKey)})); const marshalled_keys = keys.map(k => ({'id': k.keyId, 'key': u.arrayBufferToBase64(k.keyPair.pubKey)}));
bundle['prekeys'] = marshalled_keys; bundle['prekeys'] = marshalled_keys;
device.save('bundle', bundle); device.save('bundle', bundle);
}, },
...@@ -1061,7 +1058,7 @@ converse.plugins.add('converse-omemo', { ...@@ -1061,7 +1058,7 @@ converse.plugins.add('converse-omemo', {
_converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
return []; return [];
} }
const device_ids = _.map(sizzle(`list[xmlns="${Strophe.NS.OMEMO}"] device`, iq), dev => dev.getAttribute('id')); const device_ids = sizzle(`list[xmlns="${Strophe.NS.OMEMO}"] device`, iq).map(dev => dev.getAttribute('id'));
_.forEach(device_ids, id => this.devices.create({'id': id, 'jid': this.get('jid')})); _.forEach(device_ids, id => this.devices.create({'id': id, 'jid': this.get('jid')}));
return device_ids; return device_ids;
}, },
...@@ -1133,22 +1130,20 @@ converse.plugins.add('converse-omemo', { ...@@ -1133,22 +1130,20 @@ converse.plugins.add('converse-omemo', {
if (!items_el) { if (!items_el) {
return; return;
} }
const device_ids = _.map( const device_selector = `item list[xmlns="${Strophe.NS.OMEMO}"] device`;
sizzle(`item list[xmlns="${Strophe.NS.OMEMO}"] device`, items_el), const device_ids = sizzle(device_selector, items_el).map(d => d.getAttribute('id'));
(device) => device.getAttribute('id') const jid = stanza.getAttribute('from');
); const devicelist = _converse.devicelists.getDeviceList(jid);
const jid = stanza.getAttribute('from'), const devices = devicelist.devices;
devicelist = _converse.devicelists.getDeviceList(jid), const removed_ids = _.difference(devices.pluck('id'), device_ids);
devices = devicelist.devices,
removed_ids = _.difference(devices.pluck('id'), device_ids);
_.forEach(removed_ids, (id) => { removed_ids.forEach(id => {
if (jid === _converse.bare_jid && id === _converse.omemo_store.get('device_id')) { if (jid === _converse.bare_jid && id === _converse.omemo_store.get('device_id')) {
return // We don't set the current device as inactive return // We don't set the current device as inactive
} }
devices.get(id).save('active', false); devices.get(id).save('active', false);
}); });
_.forEach(device_ids, (device_id) => { device_ids.forEach(device_id => {
const device = devices.get(device_id); const device = devices.get(device_id);
if (device) { if (device) {
device.save('active', true); device.save('active', true);
......
...@@ -626,7 +626,7 @@ converse.plugins.add('converse-register', { ...@@ -626,7 +626,7 @@ converse.plugins.add('converse-register', {
return; return;
} else if (field.tagName.toLowerCase() === 'x') { } else if (field.tagName.toLowerCase() === 'x') {
if (field.getAttribute('xmlns') === 'jabber:x:oob') { if (field.getAttribute('xmlns') === 'jabber:x:oob') {
this.urls.concat(_.map(field.querySelectorAll('url'), 'textContent')); this.urls.concat(sizzle('url', field).map(u => u.textContent));
} }
return; return;
} }
......
...@@ -66,7 +66,7 @@ converse.plugins.add('converse-roomslist', { ...@@ -66,7 +66,7 @@ converse.plugins.add('converse-roomslist', {
_converse.chatboxes.on('change:num_unread', this.onChatBoxChanged, this); _converse.chatboxes.on('change:num_unread', this.onChatBoxChanged, this);
_converse.chatboxes.on('change:num_unread_general', this.onChatBoxChanged, this); _converse.chatboxes.on('change:num_unread_general', this.onChatBoxChanged, this);
_converse.chatboxes.on('remove', this.onChatBoxRemoved, this); _converse.chatboxes.on('remove', this.onChatBoxRemoved, this);
this.reset(_.map(_converse.chatboxes.where({'type': _converse.CHATROOMS_TYPE}), 'attributes')); this.reset(_converse.chatboxes.where({'type': _converse.CHATROOMS_TYPE}).map(cb => cb.attributes));
}, },
onChatBoxAdded (item) { onChatBoxAdded (item) {
......
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