Refactor onMessage to use const
instead of let
This commit is contained in:
parent
52ea8d5ab6
commit
273b9584c0
46
dist/converse.js
vendored
46
dist/converse.js
vendored
@ -63055,17 +63055,13 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let from_jid = stanza.getAttribute('from'),
|
let is_carbon = false;
|
||||||
is_carbon = false,
|
const forwarded = stanza.querySelector('forwarded');
|
||||||
is_mam = false;
|
const original_stanza = stanza;
|
||||||
const forwarded = stanza.querySelector('forwarded'),
|
|
||||||
original_stanza = stanza;
|
|
||||||
|
|
||||||
if (!_.isNull(forwarded)) {
|
if (!_.isNull(forwarded)) {
|
||||||
const forwarded_message = forwarded.querySelector('message'),
|
const xmlns = Strophe.NS.CARBONS;
|
||||||
forwarded_from = forwarded_message.getAttribute('from'),
|
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
|
||||||
xmlns = Strophe.NS.CARBONS;
|
|
||||||
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, stanza).length > 0;
|
|
||||||
|
|
||||||
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
|
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
|
||||||
// Prevent message forging via carbons
|
// Prevent message forging via carbons
|
||||||
@ -63073,28 +63069,19 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).length > 0;
|
stanza = forwarded.querySelector('message');
|
||||||
stanza = forwarded_message;
|
|
||||||
from_jid = stanza.getAttribute('from');
|
|
||||||
to_jid = stanza.getAttribute('to');
|
to_jid = stanza.getAttribute('to');
|
||||||
}
|
}
|
||||||
|
|
||||||
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
|
const from_jid = stanza.getAttribute('from');
|
||||||
from_resource = Strophe.getResourceFromJid(from_jid),
|
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
|
||||||
is_me = from_bare_jid === _converse.bare_jid;
|
const is_me = from_bare_jid === _converse.bare_jid;
|
||||||
let contact_jid;
|
|
||||||
|
|
||||||
if (is_me) {
|
if (is_me && _.isNull(to_jid)) {
|
||||||
// I am the sender, so this must be a forwarded message...
|
return _converse.log(`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`, Strophe.LogLevel.ERROR);
|
||||||
if (_.isNull(to_jid)) {
|
|
||||||
return _converse.log(`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`, Strophe.LogLevel.ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
contact_jid = Strophe.getBareJidFromJid(to_jid);
|
|
||||||
} else {
|
|
||||||
contact_jid = from_bare_jid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contact_jid = is_me ? Strophe.getBareJidFromJid(to_jid) : from_bare_jid;
|
||||||
const contact = await _converse.api.contacts.get(contact_jid);
|
const contact = await _converse.api.contacts.get(contact_jid);
|
||||||
const is_roster_contact = !_.isUndefined(contact);
|
const is_roster_contact = !_.isUndefined(contact);
|
||||||
|
|
||||||
@ -63103,13 +63090,16 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
|
|||||||
} // Get chat box, but only create when the message has something to show to the user
|
} // Get chat box, but only create when the message has something to show to the user
|
||||||
|
|
||||||
|
|
||||||
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0,
|
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0;
|
||||||
roster_nick = _.get(contact, 'attributes.nickname'),
|
|
||||||
chatbox = this.getChatBox(contact_jid, {
|
const roster_nick = _.get(contact, 'attributes.nickname');
|
||||||
|
|
||||||
|
const chatbox = this.getChatBox(contact_jid, {
|
||||||
'nickname': roster_nick
|
'nickname': roster_nick
|
||||||
}, has_body);
|
}, has_body);
|
||||||
|
|
||||||
if (chatbox) {
|
if (chatbox) {
|
||||||
|
const is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).length > 0;
|
||||||
const message = await chatbox.getDuplicateMessage(stanza);
|
const message = await chatbox.getDuplicateMessage(stanza);
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
|
@ -403,7 +403,7 @@ converse.plugins.add('converse-chatboxes', {
|
|||||||
'msgid': id
|
'msgid': id
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMarker(to_jid, id, type) {
|
sendMarker(to_jid, id, type) {
|
||||||
const stanza = $msg({
|
const stanza = $msg({
|
||||||
'from': _converse.connection.jid,
|
'from': _converse.connection.jid,
|
||||||
@ -931,47 +931,33 @@ converse.plugins.add('converse-chatboxes', {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let from_jid = stanza.getAttribute('from'),
|
let is_carbon = false;
|
||||||
is_carbon = false,
|
const forwarded = stanza.querySelector('forwarded');
|
||||||
is_mam = false;
|
const original_stanza = stanza;
|
||||||
|
|
||||||
const forwarded = stanza.querySelector('forwarded'),
|
|
||||||
original_stanza = stanza;
|
|
||||||
|
|
||||||
if (!_.isNull(forwarded)) {
|
if (!_.isNull(forwarded)) {
|
||||||
const forwarded_message = forwarded.querySelector('message'),
|
const xmlns = Strophe.NS.CARBONS;
|
||||||
forwarded_from = forwarded_message.getAttribute('from'),
|
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
|
||||||
xmlns = Strophe.NS.CARBONS;
|
|
||||||
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, stanza).length > 0;
|
|
||||||
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
|
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
|
||||||
// Prevent message forging via carbons
|
// Prevent message forging via carbons
|
||||||
// https://xmpp.org/extensions/xep-0280.html#security
|
// https://xmpp.org/extensions/xep-0280.html#security
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).length > 0;
|
stanza = forwarded.querySelector('message');
|
||||||
stanza = forwarded_message;
|
|
||||||
from_jid = stanza.getAttribute('from');
|
|
||||||
to_jid = stanza.getAttribute('to');
|
to_jid = stanza.getAttribute('to');
|
||||||
}
|
}
|
||||||
|
|
||||||
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
|
const from_jid = stanza.getAttribute('from');
|
||||||
from_resource = Strophe.getResourceFromJid(from_jid),
|
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
|
||||||
is_me = from_bare_jid === _converse.bare_jid;
|
const is_me = from_bare_jid === _converse.bare_jid;
|
||||||
|
|
||||||
let contact_jid;
|
if (is_me &&_.isNull(to_jid)) {
|
||||||
if (is_me) {
|
return _converse.log(
|
||||||
// I am the sender, so this must be a forwarded message...
|
`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`,
|
||||||
if (_.isNull(to_jid)) {
|
Strophe.LogLevel.ERROR
|
||||||
return _converse.log(
|
);
|
||||||
`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`,
|
|
||||||
Strophe.LogLevel.ERROR
|
|
||||||
);
|
|
||||||
}
|
|
||||||
contact_jid = Strophe.getBareJidFromJid(to_jid);
|
|
||||||
} else {
|
|
||||||
contact_jid = from_bare_jid;
|
|
||||||
}
|
}
|
||||||
|
const contact_jid = is_me ? Strophe.getBareJidFromJid(to_jid) : from_bare_jid;
|
||||||
const contact = await _converse.api.contacts.get(contact_jid);
|
const contact = await _converse.api.contacts.get(contact_jid);
|
||||||
const is_roster_contact = !_.isUndefined(contact);
|
const is_roster_contact = !_.isUndefined(contact);
|
||||||
if (!is_me && !is_roster_contact && !_converse.allow_non_roster_messaging) {
|
if (!is_me && !is_roster_contact && !_converse.allow_non_roster_messaging) {
|
||||||
@ -979,11 +965,12 @@ converse.plugins.add('converse-chatboxes', {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get chat box, but only create when the message has something to show to the user
|
// Get chat box, but only create when the message has something to show to the user
|
||||||
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0,
|
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0;
|
||||||
roster_nick = _.get(contact, 'attributes.nickname'),
|
const roster_nick = _.get(contact, 'attributes.nickname');
|
||||||
chatbox = this.getChatBox(contact_jid, {'nickname': roster_nick}, has_body);
|
const chatbox = this.getChatBox(contact_jid, {'nickname': roster_nick}, has_body);
|
||||||
|
|
||||||
if (chatbox) {
|
if (chatbox) {
|
||||||
|
const is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).length > 0;
|
||||||
const message = await chatbox.getDuplicateMessage(stanza);
|
const message = await chatbox.getDuplicateMessage(stanza);
|
||||||
if (message) {
|
if (message) {
|
||||||
chatbox.updateMessage(message, original_stanza);
|
chatbox.updateMessage(message, original_stanza);
|
||||||
|
46
src/headless/dist/converse-headless.js
vendored
46
src/headless/dist/converse-headless.js
vendored
@ -41303,17 +41303,13 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let from_jid = stanza.getAttribute('from'),
|
let is_carbon = false;
|
||||||
is_carbon = false,
|
const forwarded = stanza.querySelector('forwarded');
|
||||||
is_mam = false;
|
const original_stanza = stanza;
|
||||||
const forwarded = stanza.querySelector('forwarded'),
|
|
||||||
original_stanza = stanza;
|
|
||||||
|
|
||||||
if (!_.isNull(forwarded)) {
|
if (!_.isNull(forwarded)) {
|
||||||
const forwarded_message = forwarded.querySelector('message'),
|
const xmlns = Strophe.NS.CARBONS;
|
||||||
forwarded_from = forwarded_message.getAttribute('from'),
|
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
|
||||||
xmlns = Strophe.NS.CARBONS;
|
|
||||||
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, stanza).length > 0;
|
|
||||||
|
|
||||||
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
|
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
|
||||||
// Prevent message forging via carbons
|
// Prevent message forging via carbons
|
||||||
@ -41321,28 +41317,19 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).length > 0;
|
stanza = forwarded.querySelector('message');
|
||||||
stanza = forwarded_message;
|
|
||||||
from_jid = stanza.getAttribute('from');
|
|
||||||
to_jid = stanza.getAttribute('to');
|
to_jid = stanza.getAttribute('to');
|
||||||
}
|
}
|
||||||
|
|
||||||
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
|
const from_jid = stanza.getAttribute('from');
|
||||||
from_resource = Strophe.getResourceFromJid(from_jid),
|
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
|
||||||
is_me = from_bare_jid === _converse.bare_jid;
|
const is_me = from_bare_jid === _converse.bare_jid;
|
||||||
let contact_jid;
|
|
||||||
|
|
||||||
if (is_me) {
|
if (is_me && _.isNull(to_jid)) {
|
||||||
// I am the sender, so this must be a forwarded message...
|
return _converse.log(`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`, Strophe.LogLevel.ERROR);
|
||||||
if (_.isNull(to_jid)) {
|
|
||||||
return _converse.log(`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`, Strophe.LogLevel.ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
contact_jid = Strophe.getBareJidFromJid(to_jid);
|
|
||||||
} else {
|
|
||||||
contact_jid = from_bare_jid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contact_jid = is_me ? Strophe.getBareJidFromJid(to_jid) : from_bare_jid;
|
||||||
const contact = await _converse.api.contacts.get(contact_jid);
|
const contact = await _converse.api.contacts.get(contact_jid);
|
||||||
const is_roster_contact = !_.isUndefined(contact);
|
const is_roster_contact = !_.isUndefined(contact);
|
||||||
|
|
||||||
@ -41351,13 +41338,16 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
|
|||||||
} // Get chat box, but only create when the message has something to show to the user
|
} // Get chat box, but only create when the message has something to show to the user
|
||||||
|
|
||||||
|
|
||||||
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0,
|
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0;
|
||||||
roster_nick = _.get(contact, 'attributes.nickname'),
|
|
||||||
chatbox = this.getChatBox(contact_jid, {
|
const roster_nick = _.get(contact, 'attributes.nickname');
|
||||||
|
|
||||||
|
const chatbox = this.getChatBox(contact_jid, {
|
||||||
'nickname': roster_nick
|
'nickname': roster_nick
|
||||||
}, has_body);
|
}, has_body);
|
||||||
|
|
||||||
if (chatbox) {
|
if (chatbox) {
|
||||||
|
const is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).length > 0;
|
||||||
const message = await chatbox.getDuplicateMessage(stanza);
|
const message = await chatbox.getDuplicateMessage(stanza);
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
|
Loading…
Reference in New Issue
Block a user