Commit 7a590f7c authored by JC Brand's avatar JC Brand

Stop using certain lodash methods.

* _.isNil
* _.noop
* _.isNull
parent 78c7ded2
......@@ -28,14 +28,15 @@
]
}],
"lodash/import-scope": "off",
"lodash/prefer-invoke-map": "off",
"lodash/prefer-startswith": "off",
"lodash/prefer-constant": "off",
"lodash/prefer-noop": "off",
"lodash/prefer-lodash-typecheck": "off",
"lodash/prefer-get": "off",
"lodash/prefer-includes": "off",
"lodash/prefer-invoke-map": "off",
"lodash/prefer-is-nil": "off",
"lodash/prefer-lodash-typecheck": "off",
"lodash/prefer-noop": "off",
"lodash/prefer-startswith": "off",
"lodash/preferred-alias": "off",
"lodash/prefer-get": "off",
"accessor-pairs": "error",
"array-bracket-spacing": "off",
"array-callback-return": "error",
......
......@@ -41,8 +41,8 @@
const textarea = view.el.querySelector('textarea.chat-textarea');
const at_event = {
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'preventDefault': function noop () {},
'stopPropagation': function noop () {},
'keyCode': 50,
'key': '@'
};
......@@ -84,8 +84,8 @@
// Press tab
const tab_event = {
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'preventDefault': function noop () {},
'stopPropagation': function noop () {},
'keyCode': 9,
'key': 'Tab'
}
......@@ -97,7 +97,7 @@
const backspace_event = {
'target': textarea,
'preventDefault': _.noop,
'preventDefault': function noop () {},
'keyCode': 8
}
for (var i=0; i<3; i++) {
......@@ -129,7 +129,7 @@
const up_arrow_event = {
'target': textarea,
'preventDefault': () => (up_arrow_event.defaultPrevented = true),
'stopPropagation': _.noop,
'stopPropagation': function noop () {},
'keyCode': 38
}
view.onKeyDown(up_arrow_event);
......@@ -140,8 +140,8 @@
view.onKeyDown({
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'preventDefault': function noop () {},
'stopPropagation': function noop () {},
'keyCode': 13 // Enter
});
expect(textarea.value).toBe('hello s @some2 ');
......@@ -195,8 +195,8 @@
// Press backspace
const backspace_event = {
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'preventDefault': function noop () {},
'stopPropagation': function noop () {},
'keyCode': 8,
'key': 'Backspace'
}
......
......@@ -497,7 +497,7 @@
const textarea = view.el.querySelector('.chat-textarea');
const ev = {
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
};
view.onKeyDown(ev);
......@@ -546,7 +546,7 @@
let view = _converse.chatboxviews.get(contact_jid);
toolbar = view.el.querySelector('ul.chat-toolbar');
call_button = toolbar.querySelector('.toggle-call');
expect(_.isNull(call_button)).toBeTruthy();
expect(call_button === null).toBeTruthy();
view.close();
// Now check that it's shown if enabled and that it emits
// callButtonClicked
......@@ -1167,7 +1167,7 @@
view.el.querySelector('.chat-textarea').value = message;
view.onKeyDown({
target: view.el.querySelector('textarea.chat-textarea'),
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(view.clearMessages).toHaveBeenCalled();
......
......@@ -267,7 +267,7 @@
async function (done, _converse) {
const xhr = {
'open': _.noop,
'open': function noop () {},
'send': function () {
xhr.responseText = JSON.stringify([
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
......@@ -328,7 +328,7 @@
test_utils.createContacts(_converse, 'all').openControlBox();
var modal;
const xhr = {
'open': _.noop,
'open': function noop () {},
'send': function () {
const value = modal.el.querySelector('input[name="name"]').value;
if (value === 'existing') {
......
......@@ -27,7 +27,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -55,7 +55,7 @@
textarea.value = 'But soft, what light through yonder window breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
expect(_converse.connection.send).toHaveBeenCalled();
......@@ -161,7 +161,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -184,7 +184,7 @@
textarea.value = 'But soft, what light through yonder window breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
expect(_converse.connection.send).toHaveBeenCalled();
......@@ -237,7 +237,7 @@
textarea.value = 'It is the east, and Juliet is the one.';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -246,7 +246,7 @@
textarea.value = 'Arise, fair sun, and kill the envious moon';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -277,7 +277,7 @@
textarea.value = 'It is the east, and Juliet is the sun.';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.model.messages.once('rendered', resolve));
......@@ -1331,7 +1331,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await u.waitUntil(() => _converse.api.chats.get().length);
......@@ -1354,7 +1354,7 @@
textarea.value = 'Another message';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -2537,7 +2537,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -2561,7 +2561,7 @@
textarea.value = 'But soft, what light through yonder window breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
expect(_converse.connection.send).toHaveBeenCalled();
......@@ -2636,7 +2636,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -2715,7 +2715,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -2751,7 +2751,7 @@
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -2996,8 +2996,8 @@
textarea.value = 'hello @z3r0 @gibson @mr.robot, how are you?'
const enter_event = {
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'preventDefault': function noop () {},
'stopPropagation': function noop () {},
'keyCode': 13 // Enter
}
spyOn(_converse.connection, 'send');
......@@ -3074,8 +3074,8 @@
textarea.value = 'hello @z3r0 @gibson @mr.robot, how are you?'
const enter_event = {
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'preventDefault': function noop () {},
'stopPropagation': function noop () {},
'keyCode': 13 // Enter
}
view.onKeyDown(enter_event);
......
......@@ -87,7 +87,7 @@
_converse.minimized_chats.toggleview.model.set({'collapsed': true});
const unread_el = _converse.minimized_chats.toggleview.el.querySelector('.unread-message-count');
expect(_.isNull(unread_el)).toBe(true);
expect(unread_el === null).toBe(true);
for (i=0; i<3; i++) {
contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
......
......@@ -2011,7 +2011,7 @@
textarea.value = text;
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -2864,7 +2864,7 @@
const textarea = view.el.querySelector('.chat-textarea');
textarea.value = '/clear';
const enter = { 'target': textarea, 'preventDefault': _.noop, 'keyCode': 13 };
const enter = { 'target': textarea, 'preventDefault': function noop () {}, 'keyCode': 13 };
view.onKeyDown(enter);
textarea.value = '/help';
view.onKeyDown(enter);
......@@ -2935,7 +2935,7 @@
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit');
var textarea = view.el.querySelector('.chat-textarea');
const enter = { 'target': textarea, 'preventDefault': _.noop, 'keyCode': 13 };
const enter = { 'target': textarea, 'preventDefault': function noop () {}, 'keyCode': 13 };
spyOn(window, 'confirm').and.callFake(() => true);
textarea.value = '/clear';
view.onKeyDown(enter);
......@@ -2999,7 +2999,7 @@
textarea.value = '/member chris Welcome to the club!';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(_converse.connection.send).not.toHaveBeenCalled();
......@@ -3011,7 +3011,7 @@
textarea.value = '/member marc Welcome to the club!';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(_converse.connection.send).toHaveBeenCalled();
......@@ -3126,7 +3126,7 @@
textarea.value = '/topic This is the groupchat subject';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(_converse.connection.send).toHaveBeenCalled();
......@@ -3136,7 +3136,7 @@
textarea.value = '/subject This is a new subject';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
......@@ -3150,7 +3150,7 @@
textarea.value = '/Subject This is yet another subject';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(sent_stanza.textContent).toBe('This is yet another subject');
......@@ -3173,7 +3173,7 @@
textarea.value = '/clear';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(view.clearMessages).toHaveBeenCalled();
......@@ -3215,7 +3215,7 @@
textarea.value = '/owner';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(view.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
......@@ -3303,7 +3303,7 @@
textarea.value = '/ban';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(view.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
......@@ -3404,7 +3404,7 @@
textarea.value = '/kick';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
expect(view.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
......@@ -3508,7 +3508,7 @@
textarea.value = '/op';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
......@@ -3651,7 +3651,7 @@
textarea.value = '/mute';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
......@@ -5250,7 +5250,7 @@
view.model.features.set('moderated', false);
expect(view.el.querySelector('.muc-bottom-panel')).toBe(null);
let textarea = view.el.querySelector('.chat-textarea');
expect(_.isNull(textarea)).toBe(false);
expect(textarea === null).toBe(false);
view.model.features.set('moderated', true);
expect(view.el.querySelector('.chat-textarea')).toBe(null);
......@@ -5281,7 +5281,7 @@
expect(bottom_panel).toBe(null);
textarea = view.el.querySelector('.chat-textarea');
expect(_.isNull(textarea)).toBe(false);
expect(textarea === null).toBe(false);
expect(info_msgs.length).toBe(3);
expect(info_msgs[2].textContent).toBe("troll has been given a voice");
......
......@@ -126,7 +126,7 @@
textarea.value = 'This message will be encrypted';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
iq_stanza = await u.waitUntil(() => bundleFetched(_converse, contact_jid, '555'));
......@@ -310,7 +310,7 @@
textarea.value = 'This message will be encrypted';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
iq_stanza = await u.waitUntil(() => bundleFetched(_converse, contact_jid, '4e30f35051b7b8b42abe083742187228'), 1000);
......@@ -458,7 +458,7 @@
textarea.value = 'This is an encrypted message from this device';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
iq_stanza = await u.waitUntil(() => bundleFetched(_converse, _converse.bare_jid, '988349631'));
......@@ -515,7 +515,7 @@
textarea.value = 'This message will be encrypted';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13 // Enter
});
let iq_stanza = await u.waitUntil(() => deviceListFetched(_converse, contact_jid));
......@@ -1232,7 +1232,7 @@
const toolbar = view.el.querySelector('.chat-toolbar');
expect(view.model.get('omemo_active')).toBe(undefined);
let toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(false);
expect(toggle === null).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(true);
expect(u.hasClass('fa-lock', toggle)).toBe(false);
......@@ -1251,7 +1251,7 @@
textarea.value = 'This message will be sent encrypted';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
......@@ -1298,7 +1298,7 @@
const toolbar = view.el.querySelector('.chat-toolbar');
let toggle = toolbar.querySelector('.toggle-omemo');
expect(view.model.get('omemo_active')).toBe(undefined);
expect(_.isNull(toggle)).toBe(false);
expect(toggle === null).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(true);
expect(u.hasClass('fa-lock', toggle)).toBe(false);
expect(u.hasClass('disabled', toggle)).toBe(false);
......@@ -1356,7 +1356,7 @@
expect(view.model.get('omemo_active')).toBe(true);
toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(false);
expect(toggle === null).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(false);
expect(u.hasClass('fa-lock', toggle)).toBe(true);
expect(u.hasClass('disabled', toggle)).toBe(false);
......@@ -1367,13 +1367,13 @@
view.model.features.save({'nonanonymous': false, 'semianonymous': true});
await u.waitUntil(() => !view.model.get('omemo_supported'));
toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(true);
expect(toggle === null).toBe(true);
expect(view.model.get('omemo_supported')).toBe(false);
view.model.features.save({'nonanonymous': true, 'semianonymous': false});
await u.waitUntil(() => view.model.get('omemo_supported'));
toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(false);
expect(toggle === null).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(true);
expect(u.hasClass('fa-lock', toggle)).toBe(false);
expect(u.hasClass('disabled', toggle)).toBe(false);
......@@ -1382,12 +1382,12 @@
view.model.features.save({'membersonly': false, 'open': true});
await u.waitUntil(() => !view.model.get('omemo_supported'));
toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(true);
expect(toggle === null).toBe(true);
view.model.features.save({'membersonly': true, 'open': false});
await u.waitUntil(() => view.model.get('omemo_supported'));
toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(false);
expect(toggle === null).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(true);
expect(u.hasClass('fa-lock', toggle)).toBe(false);
expect(u.hasClass('disabled', toggle)).toBe(false);
......@@ -1436,7 +1436,7 @@
);
toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(false);
expect(toggle === null).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(true);
expect(u.hasClass('fa-lock', toggle)).toBe(false);
expect(u.hasClass('disabled', toggle)).toBe(true);
......
......@@ -24,7 +24,7 @@
textarea.value = '/register';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
let stanza = await u.waitUntil(() => _.filter(
......
......@@ -337,7 +337,7 @@
// When the chat gets maximized again, the unread indicators are removed
view.model.set({'minimized': false});
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(_.isNull(indicator_el));
expect(indicator_el === null);
room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
expect(_.includes(room_el.classList, 'unread-msgs')).toBeFalsy();
done();
......
......@@ -121,7 +121,7 @@
const filter = _converse.rosterview.el.querySelector('.roster-filter');
test_utils.openControlBox();
expect(_.isNull(filter)).toBe(false);
expect(filter === null).toBe(false);
test_utils.createContacts(_converse, 'current').openControlBox();
const view = _converse.chatboxviews.get('controlbox');
......
......@@ -111,7 +111,7 @@
textarea.value = 'This is the spoiler';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -130,7 +130,7 @@
*/
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
const spoiler_el = stanza.querySelector('spoiler[xmlns="urn:xmpp:spoiler:0"]');
expect(_.isNull(spoiler_el)).toBeFalsy();
expect(spoiler_el === null).toBeFalsy();
expect(spoiler_el.textContent).toBe('');
const body_el = stanza.querySelector('body');
......@@ -188,7 +188,7 @@
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
preventDefault: function noop () {},
keyCode: 13
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
......@@ -208,7 +208,7 @@
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
const spoiler_el = stanza.querySelector('spoiler[xmlns="urn:xmpp:spoiler:0"]');
expect(_.isNull(spoiler_el)).toBeFalsy();
expect(spoiler_el === null).toBeFalsy();
expect(spoiler_el.textContent).toBe('This is the hint');
const body_el = stanza.querySelector('body');
......
......@@ -43,7 +43,7 @@
show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click();
remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(_.isNull(remove_contact_button)).toBeTruthy();
expect(remove_contact_button === null).toBeTruthy();
done();
}));
......
......@@ -280,7 +280,7 @@ converse.plugins.add('converse-bookmark-views', {
const controlboxview = _converse.chatboxviews.get('controlbox');
if (controlboxview !== undefined && !u.rootContains(_converse.root, this.el)) {
const el = controlboxview.el.querySelector('.bookmarks-list');
if (!_.isNull(el)) {
if (el !== null) {
el.parentNode.replaceChild(this.el, el);
}
}
......@@ -301,13 +301,10 @@ converse.plugins.add('converse-bookmark-views', {
renderBookmarkListElement (chatbox) {
const bookmarkview = this.get(chatbox.get('jid'));
if (_.isNil(bookmarkview)) {
// A chat box has been closed, but we don't have a
// bookmark for it, so nothing further to do here.
return;
if (bookmarkview) {
bookmarkview.render();
this.showOrHide();
}
bookmarkview.render();
this.showOrHide();
},
showOrHide (item) {
......
......@@ -23,7 +23,7 @@ const AvatarMixin = {
renderAvatar (el) {
el = el || this.el;
const avatar_el = el.querySelector('canvas.avatar, svg.avatar');
if (_.isNull(avatar_el)) {
if (avatar_el === null) {
return;
}
if (this.model.vcard) {
......@@ -91,7 +91,7 @@ converse.plugins.add('converse-chatboxviews', {
*/
if (!this.el) {
let el = _converse.root.querySelector('#conversejs');
if (_.isNull(el)) {
if (el === null) {
el = document.createElement('div');
el.setAttribute('id', 'conversejs');
u.addClass(`theme-${_converse.theme}`, el);
......
......@@ -589,7 +589,7 @@ converse.plugins.add('converse-chatview', {
},
addSpinner (append=false) {
if (_.isNull(this.el.querySelector('.spinner'))) {
if (this.el.querySelector('.spinner') === null) {
if (append) {
this.content.insertAdjacentHTML('beforeend', tpl_spinner());
this.scrollDown();
......@@ -615,14 +615,13 @@ converse.plugins.add('converse-chatview', {
* which specifies its creation date.
*/
insertDayIndicator (next_msg_el) {
const prev_msg_el = u.getPreviousElement(next_msg_el, ".message:not(.chat-state-notification)"),
prev_msg_date = _.isNull(prev_msg_el) ? null : prev_msg_el.getAttribute('data-isodate'),
next_msg_date = next_msg_el.getAttribute('data-isodate');
if (_.isNull(prev_msg_date) && _.isNull(next_msg_date)) {
const prev_msg_el = u.getPreviousElement(next_msg_el, ".message:not(.chat-state-notification)");
const prev_msg_date = (prev_msg_el === null) ? null : prev_msg_el.getAttribute('data-isodate');
const next_msg_date = next_msg_el.getAttribute('data-isodate');
if (prev_msg_date === null && next_msg_date === null) {
return;
}
if (_.isNull(prev_msg_date) || dayjs(next_msg_date).isAfter(prev_msg_date, 'day')) {
if ((prev_msg_date === null) || dayjs(next_msg_date).isAfter(prev_msg_date, 'day')) {
const day_date = dayjs(next_msg_date).startOf('day');
next_msg_el.insertAdjacentHTML('beforeBegin',
tpl_new_day({
......@@ -644,12 +643,12 @@ converse.plugins.add('converse-chatview', {
getLastMessageDate (cutoff) {
const first_msg = u.getFirstChildElement(this.content, '.message:not(.chat-state-notification)');
const oldest_date = first_msg ? first_msg.getAttribute('data-isodate') : null;
if (!_.isNull(oldest_date) && dayjs(oldest_date).isAfter(cutoff)) {
if (oldest_date !== null && dayjs(oldest_date).isAfter(cutoff)) {
return null;
}
const last_msg = u.getLastChildElement(this.content, '.message:not(.chat-state-notification)');
const most_recent_date = last_msg ? last_msg.getAttribute('data-isodate') : null;
if (_.isNull(most_recent_date)) {
if (most_recent_date === null) {
return null;
}
if (dayjs(most_recent_date).isBefore(cutoff)) {
......@@ -740,7 +739,7 @@ converse.plugins.add('converse-chatview', {
const current_msg_date = dayjs(view.model.get('time')).toDate() || new Date(),
previous_msg_date = this.getLastMessageDate(current_msg_date);
if (_.isNull(previous_msg_date)) {
if (previous_msg_date === null) {
this.content.insertAdjacentElement('afterbegin', view.el);
} else {
const previous_msg_el = sizzle(`[data-isodate="${previous_msg_date.toISOString()}"]:last`, this.content).pop();
......@@ -1040,14 +1039,14 @@ converse.plugins.add('converse-chatview', {
const textarea = this.el.querySelector('.chat-textarea');
if (textarea.value &&
(currently_correcting === null || currently_correcting.get('message') !== textarea.value)) {
((currently_correcting === null) || currently_correcting.get('message') !== textarea.value)) {
if (! confirm(__("You have an unsent message which will be lost if you continue. Are you sure?"))) {
return;
}
}
if (currently_correcting !== message) {
if (!_.isNil(currently_correcting)) {
if (currently_correcting !== null) {
currently_correcting.save('correcting', false);
}
message.save('correcting', true);
......@@ -1277,7 +1276,7 @@ converse.plugins.add('converse-chatview', {
insertEmojiPicker () {
var picker_el = this.el.querySelector('.emoji-picker');
if (!_.isNull(picker_el)) {
if (picker_el !== null) {
picker_el.innerHTML = '';
picker_el.appendChild(this.emoji_picker_view.el);
}
......@@ -1346,7 +1345,7 @@ converse.plugins.add('converse-chatview', {
hideNewMessagesIndicator () {
const new_msgs_indicator = this.el.querySelector('.new-msgs-indicator');
if (!_.isNull(new_msgs_indicator)) {
if (new_msgs_indicator !== null) {
new_msgs_indicator.classList.add('hidden');
}
},
......
......@@ -172,7 +172,7 @@ converse.plugins.add('converse-controlbox', {
}
},
onReconnection: _.noop
onReconnection: function noop () {}
});
......@@ -245,7 +245,7 @@ converse.plugins.add('converse-controlbox', {
insertBrandHeading () {
const heading_el = this.el.querySelector('.brand-heading-container');
if (_.isNull(heading_el)) {
if (heading_el === null) {
const el = this.el.querySelector('.controlbox-head');
el.insertAdjacentHTML('beforeend', this.createBrandHeadingHTML());
} else {
......@@ -255,7 +255,9 @@ converse.plugins.add('converse-controlbox', {
renderLoginPanel () {
this.el.classList.add("logged-out");
if (_.isNil(this.loginpanel)) {
if (this.loginpanel) {
this.loginpanel.render();
} else {
this.loginpanel = new _converse.LoginPanel({
'model': new _converse.LoginPanelModel()
});
......@@ -263,8 +265,6 @@ converse.plugins.add('converse-controlbox', {
panes.innerHTML = '';
panes.appendChild(this.loginpanel.render().el);
this.insertBrandHeading();
} else {
this.loginpanel.render();
}
this.loginpanel.initPopovers();
return this;
......
......@@ -221,7 +221,7 @@ converse.plugins.add('converse-dragresize', {
height = "";
}
const flyout_el = this.el.querySelector('.box-flyout');
if (!_.isNull(flyout_el)) {
if (flyout_el !== null) {
flyout_el.style.height = height;
}
},
......@@ -234,7 +234,7 @@ converse.plugins.add('converse-dragresize', {
}
this.el.style.width = width;
const flyout_el = this.el.querySelector('.box-flyout');
if (!_.isNull(flyout_el)) {
if (flyout_el !== null) {
flyout_el.style.width = width;
}
},
......
......@@ -112,8 +112,8 @@ converse.plugins.add('converse-headline', {
},
// Override to avoid the methods in converse-chatview.js
'renderMessageForm': _.noop,
'afterShown': _.noop
'renderMessageForm': function noop () {},
'afterShown': function noop () {}
});
async function onHeadlineMessage (message) {
......
......@@ -177,7 +177,7 @@ converse.plugins.add('converse-message-view', {
},
replaceElement (msg) {
if (!_.isNil(this.el.parentElement)) {
if (this.el.parentElement) {
this.el.parentElement.replaceChild(msg, this.el);
}
this.setElement(msg);
......
......@@ -28,11 +28,7 @@ converse.plugins.add('converse-modal', {
backdrop: 'static',
keyboard: true
});
this.el.addEventListener('hide.bs.modal', (event) => {
if (!_.isNil(this.trigger_el)) {
this.trigger_el.classList.remove('selected');
}
}, false);
this.el.addEventListener('hide.bs.modal', () => u.removeClass('selected', this.trigger_el), false);
},
insertIntoDOM () {
......
......@@ -1138,7 +1138,7 @@ converse.plugins.add('converse-muc-views', {
hideChatRoomContents () {
const container_el = this.el.querySelector('.chatroom-body');
if (!_.isNull(container_el)) {
if (container_el !== null) {
[].forEach.call(container_el.children, child => child.classList.add('hidden'));
}
},
......@@ -1248,7 +1248,7 @@ converse.plugins.add('converse-muc-views', {
getNotificationWithMessage (message) {
let el = this.content.lastElementChild;
while (!_.isNil(el)) {
while (el) {
const data = _.get(el, 'dataset', {});
if (!_.includes(_.get(el, 'classList', []), 'chat-info')) {
return;
......@@ -1342,10 +1342,10 @@ converse.plugins.add('converse-muc-views', {
if (data.leave === nick) {
let message;
if (_.isNil(stat)) {
message = __('%1$s has left and re-entered the groupchat', nick);
} else {
if (stat) {
message = __('%1$s has left and re-entered the groupchat. "%2$s"', nick, stat);
} else {
message = __('%1$s has left and re-entered the groupchat', nick);
}
const data = {
'data_name': 'leavejoin',
......@@ -1361,10 +1361,10 @@ converse.plugins.add('converse-muc-views', {
setTimeout(() => el.parentElement && el.parentElement.removeChild(el), 5500);
} else {
let message;
if (_.isNil(stat)) {
message = __('%1$s has entered the groupchat', nick);
} else {
if (stat) {
message = __('%1$s has entered the groupchat. "%2$s"', nick, stat);
} else {
message = __('%1$s has entered the groupchat', nick);
}
const data = {
'data_name': 'join',
......@@ -1397,10 +1397,10 @@ converse.plugins.add('converse-muc-views', {
if (dataset.join === nick) {
let message;
if (_.isNil(stat)) {
message = __('%1$s has entered and left the groupchat', nick);
} else {
if (stat) {
message = __('%1$s has entered and left the groupchat. "%2$s"', nick, stat);
} else {
message = __('%1$s has entered and left the groupchat', nick);
}
const data = {
'data_name': 'joinleave',
......@@ -1416,10 +1416,10 @@ converse.plugins.add('converse-muc-views', {
setTimeout(() => el.parentElement && el.parentElement.removeChild(el), 5500);
} else {
let message;
if (_.isNil(stat)) {
message = __('%1$s has left the groupchat', nick);
} else {
if (stat) {
message = __('%1$s has left the groupchat. "%2$s"', nick, stat);
} else {
message = __('%1$s has left the groupchat', nick);
}
const data = {
'message': message,
......@@ -1469,7 +1469,7 @@ converse.plugins.add('converse-muc-views', {
* list are both visible.
*/
const spinner = this.el.querySelector('.spinner');
if (!_.isNull(spinner)) {
if (spinner !== null) {
u.removeElement(spinner);
this.renderAfterTransition();
}
......@@ -1757,7 +1757,7 @@ converse.plugins.add('converse-muc-views', {
renderInviteWidget () {
const widget = this.el.querySelector('.room-invite');
if (this.shouldInviteWidgetBeShown()) {
if (_.isNull(widget)) {
if (widget === null) {
const heading = this.el.querySelector('.occupants-heading');
heading.insertAdjacentHTML(
'afterend',
......@@ -1768,7 +1768,7 @@ converse.plugins.add('converse-muc-views', {
);
this.initInviteWidget();
}
} else if (!_.isNull(widget)) {
} else if (widget !== null) {
widget.remove();
}
return this;
......@@ -1809,7 +1809,7 @@ converse.plugins.add('converse-muc-views', {
const form = this.el.querySelector('.room-invite form'),
input = form.querySelector('.invited-contact'),
error = form.querySelector('.error');
if (!_.isNull(error)) {
if (error !== null) {
error.parentNode.removeChild(error);
}
input.value = '';
......@@ -1844,7 +1844,7 @@ converse.plugins.add('converse-muc-views', {
initInviteWidget () {
const form = this.el.querySelector('.room-invite form');
if (_.isNull(form)) {
if (form === null) {
return;
}
form.addEventListener('submit', this.inviteFormSubmitted.bind(this), false);
......
......@@ -62,7 +62,7 @@ converse.plugins.add('converse-notification', {
}
const room = _converse.chatboxes.get(room_jid);
const body = message.querySelector('body');
if (_.isNull(body)) {
if (body === null) {
return false;
}
const mentioned = (new RegExp(`\\b${room.get('nick')}\\b`)).test(body.textContent);
......@@ -76,10 +76,9 @@ converse.plugins.add('converse-notification', {
_converse.isMessageToHiddenChat = function (message) {
if (_converse.isUniView()) {
const jid = Strophe.getBareJidFromJid(message.getAttribute('from')),
view = _converse.chatboxviews.get(jid);
if (!_.isNil(view)) {
const jid = Strophe.getBareJidFromJid(message.getAttribute('from'));
const view = _converse.chatboxviews.get(jid);
if (view) {
return view.model.get('hidden') || _converse.windowState === 'hidden' || !u.isVisible(view.el);
}
return true;
......@@ -89,7 +88,7 @@ converse.plugins.add('converse-notification', {
_converse.shouldNotifyOfMessage = function (message) {
const forwarded = message.querySelector('forwarded');
if (!_.isNull(forwarded)) {
if (forwarded !== null) {
return false;
} else if (message.getAttribute('type') === 'groupchat') {
return _converse.shouldNotifyOfGroupMessage(message);
......
......@@ -78,7 +78,7 @@ converse.plugins.add("converse-oauth", {
});
_converse.OAuthProviders = _converse.Collection.extend({
'sync': __.noop,
'sync': _function noop () {},
initialize () {
_.each(_converse.user_settings.oauth_providers, (provider) => {
......
......@@ -70,7 +70,7 @@ function parseBundle (bundle_el) {
converse.plugins.add('converse-omemo', {
enabled (_converse) {
return !_.isNil(window.libsignal) && !_converse.blacklisted_plugins.includes('converse-omemo') && _converse.config.get('trusted');
return window.libsignal && !_converse.blacklisted_plugins.includes('converse-omemo') && _converse.config.get('trusted');
},
dependencies: ["converse-chatview", "converse-pubsub"],
......@@ -696,7 +696,7 @@ converse.plugins.add('converse-omemo', {
},
isTrustedIdentity (identifier, identity_key, direction) {
if (_.isNil(identifier)) {
if (identifier === null || identifier === undefined) {
throw new Error("Can't check identity key for invalid key");
}
if (!(identity_key instanceof ArrayBuffer)) {
......@@ -710,14 +710,14 @@ converse.plugins.add('converse-omemo', {
},
loadIdentityKey (identifier) {
if (_.isNil(identifier)) {
if (identifier === null || identifier === undefined) {
throw new Error("Can't load identity_key for invalid identifier");
}
return Promise.resolve(u.base64ToArrayBuffer(this.get('identity_key'+identifier)));
},
saveIdentity (identifier, identity_key) {
if (_.isNil(identifier)) {
if (identifier === null || identifier === undefined) {
throw new Error("Can't save identity_key for invalid identifier");
}
const address = new libsignal.SignalProtocolAddress.fromString(identifier),
......@@ -1104,7 +1104,7 @@ converse.plugins.add('converse-omemo', {
async function fetchOwnDevices () {
await fetchDeviceLists();
let own_devicelist = _converse.devicelists.get(_converse.bare_jid);
if (_.isNil(own_devicelist)) {
if (!own_devicelist) {
own_devicelist = _converse.devicelists.create({'jid': _converse.bare_jid});
}
return own_devicelist.fetchDevices();
......
......@@ -108,7 +108,7 @@ converse.plugins.add('converse-register', {
showLoginOrRegisterForm () {
const { _converse } = this.__super__;
if (_.isNil(this.registerpanel)) {
if (!this.registerpanel) {
return;
}
if (this.model.get('active-form') == "register") {
......@@ -308,7 +308,7 @@ converse.plugins.add('converse-register', {
* other methods.
*/
if (ev && ev.preventDefault) { ev.preventDefault(); }
if (_.isNull(ev.target.querySelector('input[name=domain]'))) {
if (ev.target.querySelector('input[name=domain]') === null) {
this.submitRegistrationForm(ev.target);
} else {
this.onProviderChosen(ev.target);
......@@ -367,7 +367,7 @@ converse.plugins.add('converse-register', {
giveFeedback (message, klass) {
let feedback = this.el.querySelector('.reg-feedback');
if (!_.isNull(feedback)) {
if (feedback !== null) {
feedback.parentNode.removeChild(feedback);
}
const form = this.el.querySelector('form');
......@@ -513,10 +513,10 @@ converse.plugins.add('converse-register', {
showValidationError (message) {
const form = this.el.querySelector('form');
let flash = form.querySelector('.form-errors');
if (_.isNull(flash)) {
if (flash === null) {
flash = '<div class="form-errors hidden"></div>';
const instructions = form.querySelector('p.instructions');
if (_.isNull(instructions)) {
if (instructions === null) {
form.insertAdjacentHTML('afterbegin', flash);
} else {
instructions.insertAdjacentHTML('afterend', flash);
......
......@@ -66,26 +66,24 @@ 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': 'chatroom'}), 'attributes'));
this.reset(_.map(_converse.chatboxes.where({'type': _converse.CHATROOMS_TYPE}), 'attributes'));
},
onChatBoxAdded (item) {
if (item.get('type') === 'chatroom') {
if (item.get('type') === _converse.CHATROOMS_TYPE) {
this.create(item.attributes);
}
},
onChatBoxChanged (item) {
if (item.get('type') === 'chatroom') {
if (item.get('type') === _converse.CHATROOMS_TYPE) {
const room = this.get(item.get('jid'));
if (!_.isNil(room)) {
room.set(item.attributes);
}
room && room.set(item.attributes);
}
},
onChatBoxRemoved (item) {
if (item.get('type') === 'chatroom') {
if (item.get('type') === _converse.CHATROOMS_TYPE) {
const room = this.get(item.get('jid'))
this.remove(room);
}
......@@ -201,7 +199,7 @@ converse.plugins.add('converse-roomslist', {
const controlboxview = _converse.chatboxviews.get('controlbox');
if (controlboxview !== undefined && !u.rootContains(_converse.root, this.el)) {
const el = controlboxview.el.querySelector('.open-rooms-list');
if (!_.isNull(el)) {
if (el !== null) {
el.parentNode.replaceChild(this.el, el);
}
}
......
......@@ -648,13 +648,17 @@ converse.plugins.add('converse-rosterview', {
return matches;
},
/**
* Filter the group's contacts based on the query "q".
*
* If all contacts are filtered out (i.e. hidden), then the
* group must be filtered out as well.
* @private
* @param { string } q - The query to filter against
* @param { string } type
*/
filter (q, type) {
/* Filter the group's contacts based on the query "q".
*
* If all contacts are filtered out (i.e. hidden), then the
* group must be filtered out as well.
*/
if (_.isNil(q)) {
if (q === null || q === undefined) {
type = type || _converse.rosterview.filter_view.model.get('filter_type');
if (type === 'state') {
q = _converse.rosterview.filter_view.model.get('chat_state');
......
......@@ -231,10 +231,9 @@ converse.plugins.add('converse-bookmarks', {
window.sessionStorage.setItem(this.fetched_flag, true);
_converse.log('Error while fetching bookmarks', Strophe.LogLevel.ERROR);
_converse.log(iq.outerHTML, Strophe.LogLevel.DEBUG);
if (!_.isNil(deferred)) {
if (deferred) {
if (iq.querySelector('error[type="cancel"] item-not-found')) {
// Not an exception, the user simply doesn't have
// any bookmarks.
// Not an exception, the user simply doesn't have any bookmarks.
return deferred.resolve();
} else {
return deferred.reject(new Error("Could not fetch bookmarks"));
......
......@@ -154,7 +154,7 @@ converse.plugins.add('converse-chatboxes', {
*
* https://xmpp.org/extensions/xep-0363.html#request
*/
if (_.isNil(this.file)) {
if (!this.file) {
return Promise.reject(new Error("file is undefined"));
}
const iq = converse.env.$iq({
......@@ -853,7 +853,7 @@ converse.plugins.add('converse-chatboxes', {
},
isArchived (original_stanza) {
return !_.isNil(sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop());
return !!sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop();
},
getErrorMessage (stanza) {
......@@ -902,8 +902,8 @@ converse.plugins.add('converse-chatboxes', {
const attrs = Object.assign({
'chat_state': chat_state,
'is_archived': this.isArchived(original_stanza),
'is_delayed': !_.isNil(delay),
'is_spoiler': !_.isNil(spoiler),
'is_delayed': !!delay,
'is_spoiler': !!spoiler,
'is_single_emoji': text ? u.isSingleEmoji(text) : false,
'message': text,
'msgid': msgid,
......@@ -965,8 +965,9 @@ converse.plugins.add('converse-chatboxes', {
/* Given a newly received message, update the unread counter if
* necessary.
*/
if (!message) { return; }
if (_.isNil(message.get('message'))) { return; }
if (!message || !message.get('message')) {
return;
}
if (utils.isNewMessage(message) && this.isHidden()) {
this.save({'num_unread': this.get('num_unread') + 1});
_converse.incrementMsgCounter();
......@@ -998,7 +999,7 @@ converse.plugins.add('converse-chatboxes', {
_converse.connection.addHandler(stanza => {
// Message receipts are usually without the `type` attribute. See #1353
if (!_.isNull(stanza.getAttribute('type'))) {
if (stanza.getAttribute('type') !== null) {
// TODO: currently Strophe has no way to register a handler
// for stanzas without a `type` attribute.
// We could update it to accept null to mean no attribute,
......@@ -1096,7 +1097,7 @@ converse.plugins.add('converse-chatboxes', {
const forwarded = stanza.querySelector('forwarded');
const original_stanza = stanza;
if (!_.isNull(forwarded)) {
if (forwarded !== null) {
const xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
......@@ -1112,7 +1113,7 @@ converse.plugins.add('converse-chatboxes', {
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
const is_me = from_bare_jid === _converse.bare_jid;
if (is_me &&_.isNull(to_jid)) {
if (is_me && to_jid === null) {
return _converse.log(
`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`,
Strophe.LogLevel.ERROR
......@@ -1268,7 +1269,7 @@ converse.plugins.add('converse-chatboxes', {
attrs.fullname = _.get(contact, 'attributes.fullname');
}
const chatbox = _converse.chatboxes.getChatBox(jids, attrs, true);
if (_.isNil(chatbox)) {
if (!chatbox) {
_converse.log("Could not open chatbox for JID: "+jids, Strophe.LogLevel.ERROR);
return;
}
......
......@@ -477,9 +477,7 @@ function connect (credentials) {
BOSH_WAIT
);
} else if (_converse.authentication === _converse.LOGIN) {
const password = _.isNil(credentials)
? _converse.connection.pass || _converse.password
: credentials.password;
const password = credentials ? credentials.password : (_converse.connection.pass || _converse.password);
if (!password) {
if (_converse.auto_login) {
throw new Error("autoLogin: If you use auto_login and "+
......@@ -834,7 +832,7 @@ _converse.initialize = async function (settings, callback) {
// Module-level variables
// ----------------------
this.callback = callback || _.noop;
this.callback = callback || function noop () {};
/* When reloading the page:
* For new sessions, we need to send out a presence stanza to notify
* the server/network that we're online.
......@@ -1085,7 +1083,7 @@ _converse.initialize = async function (settings, callback) {
this.msg_counter += 1;
const unreadMsgCount = this.msg_counter;
let title = document.title;
if (_.isNil(title)) {
if (!title) {
return;
}
if (title.search(/^Messages \(\d+\) /) === -1) {
......@@ -1098,7 +1096,7 @@ _converse.initialize = async function (settings, callback) {
this.clearMsgCounter = function () {
this.msg_counter = 0;
let title = document.title;
if (_.isNil(title)) {
if (!title) {
return;
}
if (title.search(/^Messages \(\d+\) /) !== -1) {
......
......@@ -407,7 +407,7 @@ converse.plugins.add('converse-disco', {
*/
async getFeature (name, xmlns) {
await _converse.api.waitUntil('streamFeaturesAdded');
if (_.isNil(name) || _.isNil(xmlns)) {
if (!name || !xmlns) {
throw new Error("name and xmlns need to be provided when calling disco.stream.getFeature");
}
if (_converse.stream_features === undefined && !_converse.api.connection.connected()) {
......@@ -567,7 +567,7 @@ converse.plugins.add('converse-disco', {
*/
async get (jid, create=false) {
await _converse.api.waitUntil('discoInitialized');
if (_.isNil(jid)) {
if (!jid) {
return _converse.disco_entities;
}
if (_converse.disco_entities === undefined && !_converse.api.connection.connected()) {
......@@ -626,7 +626,7 @@ converse.plugins.add('converse-disco', {
* _converse.api.disco.features.get(Strophe.NS.MAM, _converse.bare_jid);
*/
async get (feature, jid) {
if (_.isNil(jid)) {
if (!jid) {
throw new TypeError('You need to provide an entity JID');
}
await _converse.api.waitUntil('discoInitialized');
......@@ -682,7 +682,7 @@ converse.plugins.add('converse-disco', {
* await _converse.api.disco.refreshFeatures('room@conference.example.org');
*/
async refreshFeatures (jid) {
if (_.isNil(jid)) {
if (!jid) {
throw new TypeError('api.disco.refreshFeatures: You need to provide an entity JID');
}
await _converse.api.waitUntil('discoInitialized');
......@@ -712,7 +712,7 @@ converse.plugins.add('converse-disco', {
* const features = await _converse.api.disco.getFeatures('room@conference.example.org');
*/
async getFeatures (jid) {
if (_.isNil(jid)) {
if (!jid) {
throw new TypeError('api.disco.getFeatures: You need to provide an entity JID');
}
await _converse.api.waitUntil('discoInitialized');
......@@ -733,7 +733,7 @@ converse.plugins.add('converse-disco', {
* const fields = await _converse.api.disco.getFields('room@conference.example.org');
*/
async getFields (jid) {
if (_.isNil(jid)) {
if (!jid) {
throw new TypeError('api.disco.getFields: You need to provide an entity JID');
}
await _converse.api.waitUntil('discoInitialized');
......@@ -765,10 +765,10 @@ converse.plugins.add('converse-disco', {
* @example
* _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then(
* function (identity) {
* if (_.isNil(identity)) {
* // The entity DOES NOT have this identity
* } else {
* if (identity) {
* // The entity DOES have this identity
* } else {
* // The entity DOES NOT have this identity
* }
* }
* ).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
......
......@@ -1027,8 +1027,8 @@ converse.plugins.add('converse-muc', {
*/
saveAffiliationAndRole (pres) {
const item = sizzle(`x[xmlns="${Strophe.NS.MUC_USER}"] item`, pres).pop();
const is_self = !_.isNull(pres.querySelector("status[code='110']"));
if (is_self && !_.isNil(item)) {
const is_self = (pres.querySelector("status[code='110']") !== null);
if (is_self && item) {
const affiliation = item.getAttribute('affiliation');
const role = item.getAttribute('role');
const changes = {};
......@@ -1848,7 +1848,7 @@ converse.plugins.add('converse-muc', {
incrementUnreadMsgCounter (message) {
if (!message) { return; }
const body = message.get('message');
if (_.isNil(body)) { return; }
if (!body) { return; }
if (u.isNewMessage(message) && this.isHidden()) {
const settings = {'num_unread_general': this.get('num_unread_general') + 1};
if (this.isUserMentioned(message)) {
......
......@@ -37,9 +37,7 @@ converse.plugins.add('converse-ping', {
//
// var feature = _converse.disco_entities[_converse.domain].features.findWhere({'var': Strophe.NS.PING});
_converse.lastStanzaDate = new Date();
if (_.isNil(jid)) {
jid = Strophe.getDomainFromJid(_converse.bare_jid);
}
jid = jid || Strophe.getDomainFromJid(_converse.bare_jid);
if (timeout === undefined ) { timeout = null; }
if (success === undefined ) { success = null; }
if (error === undefined ) { error = null; }
......
......@@ -191,7 +191,7 @@ converse.plugins.add('converse-roster', {
'name': name,
'priority': _.isNaN(parseInt(priority, 10)) ? 0 : parseInt(priority, 10),
'show': _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
'timestamp': _.isNil(delay) ? (new Date()).toISOString() : dayjs(delay.getAttribute('stamp')).toISOString()
'timestamp': delay ? dayjs(delay.getAttribute('stamp')).toISOString() : (new Date()).toISOString()
};
if (resource) {
resource.save(settings);
......
......@@ -65,7 +65,7 @@ converse.plugins.add('converse-vcard', {
async function onVCardData (jid, iq) {
const vcard = iq.querySelector('vCard');
let result = {};
if (!_.isNull(vcard)) {
if (vcard !== null) {
result = {
'stanza': iq,
'fullname': _.get(vcard.querySelector('FN'), 'textContent'),
......
......@@ -110,7 +110,7 @@ export default {
},
translate (str) {
if (_.isNil(jed_instance)) {
if (!jed_instance) {
return Jed.sprintf.apply(Jed, arguments);
}
const t = jed_instance.translate(str);
......
......@@ -21,10 +21,10 @@ const Strophe = strophe.default.Strophe;
const u = {};
u.logger = Object.assign({
'debug': _.get(console, 'log') ? console.log.bind(console) : _.noop,
'error': _.get(console, 'log') ? console.log.bind(console) : _.noop,
'info': _.get(console, 'log') ? console.log.bind(console) : _.noop,
'warn': _.get(console, 'log') ? console.log.bind(console) : _.noop
'debug': _.get(console, 'log') ? console.log.bind(console) : function noop () {},
'error': _.get(console, 'log') ? console.log.bind(console) : function noop () {},
'info': _.get(console, 'log') ? console.log.bind(console) : function noop () {},
'warn': _.get(console, 'log') ? console.log.bind(console) : function noop () {}
}, console);
u.isTagEqual = function (stanza, name) {
......@@ -144,9 +144,7 @@ u.isHeadlineMessage = function (_converse, message) {
if (chatbox && chatbox.get('type') === _converse.CHATROOMS_TYPE) {
return false;
}
if (message.getAttribute('type') !== 'error' &&
!_.isNil(from_jid) &&
!_.includes(from_jid, '@')) {
if (message.getAttribute('type') !== 'error' && from_jid && !_.includes(from_jid, '@')) {
// Some servers (I'm looking at you Prosody) don't set the message
// type to "headline" when sending server messages. For now we
// check if an @ signal is included, and if not, we assume it's
......
......@@ -34,10 +34,10 @@ function getAutoCompleteProperty (name, options) {
}
const logger = _.assign({
'debug': _.get(console, 'log') ? console.log.bind(console) : _.noop,
'error': _.get(console, 'log') ? console.log.bind(console) : _.noop,
'info': _.get(console, 'log') ? console.log.bind(console) : _.noop,
'warn': _.get(console, 'log') ? console.log.bind(console) : _.noop
'debug': _.get(console, 'log') ? console.log.bind(console) : function noop () {},
'error': _.get(console, 'log') ? console.log.bind(console) : function noop () {},
'info': _.get(console, 'log') ? console.log.bind(console) : function noop () {},
'warn': _.get(console, 'log') ? console.log.bind(console) : function noop () {}
}, console);
const XFORM_TYPE_MAP = {
......@@ -227,15 +227,15 @@ u.calculateElementHeight = function (el) {
u.getNextElement = function (el, selector='*') {
let next_el = el.nextElementSibling;
while (!_.isNull(next_el) && !sizzle.matchesSelector(next_el, selector)) {
while ((next_el instanceof Element) && !sizzle.matchesSelector(next_el, selector)) {
next_el = next_el.nextElementSibling;
}
return next_el;
}
u.getPreviousElement = function (el, selector='*') {
let prev_el = el.previousSibling;
while (!_.isNull(prev_el) && !sizzle.matchesSelector(prev_el, selector)) {
let prev_el = el.previousElementSibling;
while ((prev_el instanceof Element) && !sizzle.matchesSelector(prev_el, selector)) {
prev_el = prev_el.previousSibling
}
return prev_el;
......@@ -243,7 +243,7 @@ u.getPreviousElement = function (el, selector='*') {
u.getFirstChildElement = function (el, selector='*') {
let first_el = el.firstElementChild;
while (!_.isNull(first_el) && !sizzle.matchesSelector(first_el, selector)) {
while ((first_el instanceof Element) && !sizzle.matchesSelector(first_el, selector)) {
first_el = first_el.nextSibling
}
return first_el;
......@@ -251,33 +251,29 @@ u.getFirstChildElement = function (el, selector='*') {
u.getLastChildElement = function (el, selector='*') {
let last_el = el.lastElementChild;
while (!_.isNull(last_el) && !sizzle.matchesSelector(last_el, selector)) {
while ((last_el instanceof Element) && !sizzle.matchesSelector(last_el, selector)) {
last_el = last_el.previousSibling
}
return last_el;
}
u.hasClass = function (className, el) {
return el.classList.contains(className);
return (el instanceof Element) && el.classList.contains(className);
};
u.addClass = function (className, el) {
if (el instanceof Element) {
el.classList.add(className);
}
(el instanceof Element) && el.classList.add(className);
return el;
}
u.removeClass = function (className, el) {
if (el instanceof Element) {
el.classList.remove(className);
}
(el instanceof Element) && el.classList.remove(className);
return el;
}
u.removeElement = function (el) {
if (!_.isNil(el) && !_.isNil(el.parentNode)) {
el.parentNode.removeChild(el);
}
(el instanceof Element) && el.parentNode && el.parentNode.removeChild(el);
return el;
}
u.showElement = _.flow(
......@@ -286,15 +282,13 @@ u.showElement = _.flow(
)
u.hideElement = function (el) {
if (!_.isNil(el)) {
el.classList.add('hidden');
}
(el instanceof Element) && el.classList.add('hidden');
return el;
}
u.ancestor = function (el, selector) {
let parent = el;
while (!_.isNil(parent) && !sizzle.matchesSelector(parent, selector)) {
while ((parent instanceof Element) && !sizzle.matchesSelector(parent, selector)) {
parent = parent.parentElement;
}
return parent;
......@@ -304,7 +298,7 @@ u.nextUntil = function (el, selector, include_self=false) {
/* Return the element's siblings until one matches the selector. */
const matches = [];
let sibling_el = el.nextElementSibling;
while (!_.isNil(sibling_el) && !sibling_el.matches(selector)) {
while ((sibling_el instanceof Element) && !sibling_el.matches(selector)) {
matches.push(sibling_el);
sibling_el = sibling_el.nextElementSibling;
}
......@@ -398,8 +392,8 @@ u.slideToggleElement = function (el, duration) {
*/
u.slideOut = function (el, duration=200) {
return new Promise((resolve, reject) => {
if (_.isNil(el)) {
const err = "Undefined or null element passed into slideOut"
if (!el) {
const err = "An element needs to be passed in to slideOut"
logger.warn(err);
reject(new Error(err));
return;
......@@ -457,8 +451,8 @@ u.slideOut = function (el, duration=200) {
u.slideIn = function (el, duration=200) {
/* Hides/collapses an element by sliding it into itself. */
return new Promise((resolve, reject) => {
if (_.isNil(el)) {
const err = "Undefined or null element passed into slideIn";
if (!el) {
const err = "An element needs to be passed in to slideIn";
logger.warn(err);
return reject(new Error(err));
} else if (_.includes(el.classList, 'collapsed')) {
......@@ -518,8 +512,8 @@ u.isVisible = function (el) {
u.fadeIn = function (el, callback) {
if (_.isNil(el)) {
logger.warn("Undefined or null element passed into fadeIn");
if (!el) {
logger.warn("An element needs to be passed in to fadeIn");
}
if (window.converse_disable_effects) {
el.classList.remove('hidden');
......@@ -561,7 +555,7 @@ u.xForm2webForm = function (field, stanza, options) {
'value': value,
'label': option.getAttribute('label'),
'selected': _.includes(values, value),
'required': !_.isNil(field.querySelector('required'))
'required': !!field.querySelector('required')
})
}
);
......@@ -571,7 +565,7 @@ u.xForm2webForm = function (field, stanza, options) {
'label': field.getAttribute('label'),
'options': options.join(''),
'multiple': (field.getAttribute('type') === 'list-multi'),
'required': !_.isNil(field.querySelector('required'))
'required': !!field.querySelector('required')
});
} else if (field.getAttribute('type') === 'fixed') {
const text = _.get(field.querySelector('value'), 'textContent');
......@@ -581,7 +575,7 @@ u.xForm2webForm = function (field, stanza, options) {
'name': field.getAttribute('var'),
'label': field.getAttribute('label') || '',
'value': _.get(field.querySelector('value'), 'textContent'),
'required': !_.isNil(field.querySelector('required'))
'required': !!field.querySelector('required')
});
} else if (field.getAttribute('type') === 'boolean') {
return tpl_form_checkbox({
......@@ -589,7 +583,7 @@ u.xForm2webForm = function (field, stanza, options) {
'name': field.getAttribute('var'),
'label': field.getAttribute('label') || '',
'checked': _.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '',
'required': !_.isNil(field.querySelector('required'))
'required': !!field.querySelector('required')
});
} else if (field.getAttribute('var') === 'url') {
return tpl_form_url({
......@@ -603,7 +597,7 @@ u.xForm2webForm = function (field, stanza, options) {
'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'label': field.getAttribute('label') || '',
'value': _.get(field.querySelector('value'), 'textContent'),
'required': !_.isNil(field.querySelector('required'))
'required': !!field.querySelector('required')
});
} else if (field.getAttribute('var') === 'ocr') { // Captcha
const uri = field.querySelector('uri');
......@@ -613,7 +607,7 @@ u.xForm2webForm = function (field, stanza, options) {
'name': field.getAttribute('var'),
'data': _.get(el, 'textContent'),
'type': uri.getAttribute('type'),
'required': !_.isNil(field.querySelector('required'))
'required': !!field.querySelector('required')
});
} else {
const name = field.getAttribute('var');
......@@ -624,7 +618,7 @@ u.xForm2webForm = function (field, stanza, options) {
'fixed_username': options.fixed_username,
'autocomplete': getAutoCompleteProperty(name, options),
'placeholder': null,
'required': !_.isNil(field.querySelector('required')),
'required': !!field.querySelector('required'),
'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'value': _.get(field.querySelector('value'), 'textContent')
});
......
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