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

Stop using certain lodash methods.

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