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