Commit 22ff93c3 authored by JC Brand's avatar JC Brand

core: Import individual lodash methods

and use some native ones instead
parent d0ee41d4
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
/** /**
* @module converse-core * @module converse-core
*/ */
import { assignIn, debounce, get, invoke, isFunction, isObject, isString, pick } from 'lodash';
import 'strophe.js/src/websocket'; import 'strophe.js/src/websocket';
import './polyfill'; import './polyfill';
import * as strophe from 'strophe.js/src/core'; import * as strophe from 'strophe.js/src/core';
...@@ -348,7 +349,7 @@ _converse.isUniView = function () { ...@@ -348,7 +349,7 @@ _converse.isUniView = function () {
* UniView means that only one chat is visible, even though there might be multiple ongoing chats. * UniView means that only one chat is visible, even though there might be multiple ongoing chats.
* MultiView means that multiple chats may be visible simultaneously. * MultiView means that multiple chats may be visible simultaneously.
*/ */
return _.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode); return ['mobile', 'fullscreen', 'embedded'].includes(_converse.view_mode);
}; };
...@@ -519,7 +520,7 @@ function connect (credentials) { ...@@ -519,7 +520,7 @@ function connect (credentials) {
BOSH_WAIT BOSH_WAIT
); );
} else if (_converse.authentication === _converse.LOGIN) { } else if (_converse.authentication === _converse.LOGIN) {
const password = credentials ? credentials.password : (_.get(_converse.connection, 'pass') || _converse.password); const password = credentials ? credentials.password : (get(_converse.connection, 'pass') || _converse.password);
if (!password) { if (!password) {
if (_converse.auto_login) { if (_converse.auto_login) {
throw new Error("autoLogin: If you use auto_login and "+ throw new Error("autoLogin: If you use auto_login and "+
...@@ -556,7 +557,7 @@ async function reconnect () { ...@@ -556,7 +557,7 @@ async function reconnect () {
return _converse.api.user.login(); return _converse.api.user.login();
} }
const debouncedReconnect = _.debounce(reconnect, 2000); const debouncedReconnect = debounce(reconnect, 2000);
_converse.shouldClearCache = () => (!_converse.config.get('trusted') || _converse.isTestEnv()); _converse.shouldClearCache = () => (!_converse.config.get('trusted') || _converse.isTestEnv());
...@@ -839,7 +840,7 @@ async function finishInitialization () { ...@@ -839,7 +840,7 @@ async function finishInitialization () {
}); });
} }
if (_converse.auto_login || if (_converse.auto_login ||
_converse.keepalive && _.invoke(_converse.pluggable.plugins['converse-bosh'], 'enabled')) { _converse.keepalive && invoke(_converse.pluggable.plugins['converse-bosh'], 'enabled')) {
await _converse.api.user.login(null, null, true); await _converse.api.user.login(null, null, true);
} }
} }
...@@ -870,7 +871,7 @@ function finishDisconnection () { ...@@ -870,7 +871,7 @@ function finishDisconnection () {
function fetchLoginCredentials (wait=0) { function fetchLoginCredentials (wait=0) {
return new Promise( return new Promise(
_.debounce((resolve, reject) => { debounce((resolve, reject) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true); xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', 'application/json, text/javascript'); xhr.setRequestHeader('Accept', 'application/json, text/javascript');
...@@ -1006,11 +1007,11 @@ _converse.initialize = async function (settings, callback) { ...@@ -1006,11 +1007,11 @@ _converse.initialize = async function (settings, callback) {
_converse.unloadevent = 'unload'; _converse.unloadevent = 'unload';
} }
_.assignIn(this, this.default_settings); assignIn(this, this.default_settings);
// Allow only whitelisted configuration attributes to be overwritten // Allow only whitelisted configuration attributes to be overwritten
_.assignIn(this, _.pick(settings, Object.keys(this.default_settings))); assignIn(this, pick(settings, Object.keys(this.default_settings)));
this.settings = {}; this.settings = {};
_.assignIn(this.settings, _.pick(settings, Object.keys(this.default_settings))); assignIn(this.settings, pick(settings, Object.keys(this.default_settings)));
log.setLogLevel(_converse.loglevel); log.setLogLevel(_converse.loglevel);
_converse.log = log.log; _converse.log = log.log;
...@@ -1090,7 +1091,7 @@ _converse.initialize = async function (settings, callback) { ...@@ -1090,7 +1091,7 @@ _converse.initialize = async function (settings, callback) {
return finishDisconnection(); return finishDisconnection();
} }
} else if (_converse.disconnection_cause === _converse.LOGOUT || } else if (_converse.disconnection_cause === _converse.LOGOUT ||
(reason !== undefined && reason === _.get(Strophe, 'ErrorCondition.NO_AUTH_MECH')) || (reason !== undefined && reason === get(Strophe, 'ErrorCondition.NO_AUTH_MECH')) ||
reason === "host-unknown" || reason === "host-unknown" ||
reason === "remote-connection-failed" || reason === "remote-connection-failed" ||
!_converse.auto_reconnect) { !_converse.auto_reconnect) {
...@@ -1166,7 +1167,7 @@ _converse.initialize = async function (settings, callback) { ...@@ -1166,7 +1167,7 @@ _converse.initialize = async function (settings, callback) {
if (message === "host-unknown" || message == "remote-connection-failed") { if (message === "host-unknown" || message == "remote-connection-failed") {
feedback = __("Sorry, we could not connect to the XMPP host with domain: %1$s", feedback = __("Sorry, we could not connect to the XMPP host with domain: %1$s",
`\"${Strophe.getDomainFromJid(_converse.connection.jid)}\"`); `\"${Strophe.getDomainFromJid(_converse.connection.jid)}\"`);
} else if (message !== undefined && message === _.get(Strophe, 'ErrorCondition.NO_AUTH_MECH')) { } else if (message !== undefined && message === get(Strophe, 'ErrorCondition.NO_AUTH_MECH')) {
feedback = __("The XMPP server did not offer a supported authentication mechanism"); feedback = __("The XMPP server did not offer a supported authentication mechanism");
} }
_converse.setConnectionStatus(status, feedback); _converse.setConnectionStatus(status, feedback);
...@@ -1233,7 +1234,7 @@ _converse.api = { ...@@ -1233,7 +1234,7 @@ _converse.api = {
* @returns {boolean} Whether there is an established connection or not. * @returns {boolean} Whether there is an established connection or not.
*/ */
connected () { connected () {
return _.get(_converse, 'connection', {}).connected && true; return get(_converse, 'connection', {}).connected && true;
}, },
/** /**
...@@ -1468,7 +1469,7 @@ _converse.api = { ...@@ -1468,7 +1469,7 @@ _converse.api = {
* @example _converse.api.settings.get("play_sounds"); * @example _converse.api.settings.get("play_sounds");
*/ */
get (key) { get (key) {
if (_.includes(Object.keys(_converse.default_settings), key)) { if (Object.keys(_converse.default_settings).includes(key)) {
return _converse[key]; return _converse[key];
} }
}, },
...@@ -1492,11 +1493,11 @@ _converse.api = { ...@@ -1492,11 +1493,11 @@ _converse.api = {
*/ */
set (key, val) { set (key, val) {
const o = {}; const o = {};
if (_.isObject(key)) { if (isObject(key)) {
_.assignIn(_converse, _.pick(key, Object.keys(_converse.default_settings))); assignIn(_converse, pick(key, Object.keys(_converse.default_settings)));
} else if (_.isString('string')) { } else if (isString('string')) {
o[key] = val; o[key] = val;
_.assignIn(_converse, _.pick(o, Object.keys(_converse.default_settings))); assignIn(_converse, pick(o, Object.keys(_converse.default_settings)));
} }
} }
}, },
...@@ -1612,7 +1613,7 @@ _converse.api = { ...@@ -1612,7 +1613,7 @@ _converse.api = {
* @param {function} handler The callback method to be called when the stanza appears * @param {function} handler The callback method to be called when the stanza appears
*/ */
stanza (name, options, handler) { stanza (name, options, handler) {
if (_.isFunction(options)) { if (isFunction(options)) {
handler = options; handler = options;
options = {}; options = {};
} else { } else {
...@@ -1639,7 +1640,7 @@ _converse.api = { ...@@ -1639,7 +1640,7 @@ _converse.api = {
* @returns {Promise} * @returns {Promise}
*/ */
waitUntil (condition) { waitUntil (condition) {
if (_.isFunction(condition)) { if (isFunction(condition)) {
return u.waitUntil(condition); return u.waitUntil(condition);
} else { } else {
const promise = _converse.promises[condition]; const promise = _converse.promises[condition];
...@@ -1667,7 +1668,7 @@ _converse.api = { ...@@ -1667,7 +1668,7 @@ _converse.api = {
log.warn(Strophe.serialize(stanza)); log.warn(Strophe.serialize(stanza));
return; return;
} }
if (_.isString(stanza)) { if (isString(stanza)) {
stanza = u.toStanza(stanza); stanza = u.toStanza(stanza);
} }
if (stanza.tagName === 'iq') { if (stanza.tagName === 'iq') {
......
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