Refactor onMessage to use const instead of let

This commit is contained in:
JC Brand 2019-05-03 14:12:26 +02:00
parent 52ea8d5ab6
commit 273b9584c0
3 changed files with 56 additions and 89 deletions

46
dist/converse.js vendored
View File

@ -63055,17 +63055,13 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return true;
}
let from_jid = stanza.getAttribute('from'),
is_carbon = false,
is_mam = false;
const forwarded = stanza.querySelector('forwarded'),
original_stanza = stanza;
let is_carbon = false;
const forwarded = stanza.querySelector('forwarded');
const original_stanza = stanza;
if (!_.isNull(forwarded)) {
const forwarded_message = forwarded.querySelector('message'),
forwarded_from = forwarded_message.getAttribute('from'),
xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, stanza).length > 0;
const xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
// Prevent message forging via carbons
@ -63073,28 +63069,19 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return true;
}
is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).length > 0;
stanza = forwarded_message;
from_jid = stanza.getAttribute('from');
stanza = forwarded.querySelector('message');
to_jid = stanza.getAttribute('to');
}
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
from_resource = Strophe.getResourceFromJid(from_jid),
is_me = from_bare_jid === _converse.bare_jid;
let contact_jid;
const from_jid = stanza.getAttribute('from');
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
const is_me = from_bare_jid === _converse.bare_jid;
if (is_me) {
// I am the sender, so this must be a forwarded message...
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;
if (is_me && _.isNull(to_jid)) {
return _converse.log(`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`, Strophe.LogLevel.ERROR);
}
const contact_jid = is_me ? Strophe.getBareJidFromJid(to_jid) : from_bare_jid;
const contact = await _converse.api.contacts.get(contact_jid);
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
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 has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0;
const roster_nick = _.get(contact, 'attributes.nickname');
const chatbox = this.getChatBox(contact_jid, {
'nickname': roster_nick
}, has_body);
if (chatbox) {
const is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).length > 0;
const message = await chatbox.getDuplicateMessage(stanza);
if (message) {

View File

@ -403,7 +403,7 @@ converse.plugins.add('converse-chatboxes', {
'msgid': id
});
},
sendMarker(to_jid, id, type) {
const stanza = $msg({
'from': _converse.connection.jid,
@ -931,47 +931,33 @@ converse.plugins.add('converse-chatboxes', {
return true;
}
let from_jid = stanza.getAttribute('from'),
is_carbon = false,
is_mam = false;
const forwarded = stanza.querySelector('forwarded'),
original_stanza = stanza;
let is_carbon = false;
const forwarded = stanza.querySelector('forwarded');
const original_stanza = stanza;
if (!_.isNull(forwarded)) {
const forwarded_message = forwarded.querySelector('message'),
forwarded_from = forwarded_message.getAttribute('from'),
xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, stanza).length > 0;
const xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
// Prevent message forging via carbons
// https://xmpp.org/extensions/xep-0280.html#security
return true;
}
is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).length > 0;
stanza = forwarded_message;
from_jid = stanza.getAttribute('from');
stanza = forwarded.querySelector('message');
to_jid = stanza.getAttribute('to');
}
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
from_resource = Strophe.getResourceFromJid(from_jid),
is_me = from_bare_jid === _converse.bare_jid;
const from_jid = stanza.getAttribute('from');
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
const is_me = from_bare_jid === _converse.bare_jid;
let contact_jid;
if (is_me) {
// I am the sender, so this must be a forwarded message...
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;
if (is_me &&_.isNull(to_jid)) {
return _converse.log(
`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`,
Strophe.LogLevel.ERROR
);
}
const contact_jid = is_me ? Strophe.getBareJidFromJid(to_jid) : from_bare_jid;
const contact = await _converse.api.contacts.get(contact_jid);
const is_roster_contact = !_.isUndefined(contact);
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
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0,
roster_nick = _.get(contact, 'attributes.nickname'),
chatbox = this.getChatBox(contact_jid, {'nickname': roster_nick}, has_body);
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0;
const roster_nick = _.get(contact, 'attributes.nickname');
const chatbox = this.getChatBox(contact_jid, {'nickname': roster_nick}, has_body);
if (chatbox) {
const is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).length > 0;
const message = await chatbox.getDuplicateMessage(stanza);
if (message) {
chatbox.updateMessage(message, original_stanza);

View File

@ -41303,17 +41303,13 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return true;
}
let from_jid = stanza.getAttribute('from'),
is_carbon = false,
is_mam = false;
const forwarded = stanza.querySelector('forwarded'),
original_stanza = stanza;
let is_carbon = false;
const forwarded = stanza.querySelector('forwarded');
const original_stanza = stanza;
if (!_.isNull(forwarded)) {
const forwarded_message = forwarded.querySelector('message'),
forwarded_from = forwarded_message.getAttribute('from'),
xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, stanza).length > 0;
const xmlns = Strophe.NS.CARBONS;
is_carbon = sizzle(`received[xmlns="${xmlns}"]`, original_stanza).length > 0;
if (is_carbon && original_stanza.getAttribute('from') !== _converse.bare_jid) {
// Prevent message forging via carbons
@ -41321,28 +41317,19 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return true;
}
is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).length > 0;
stanza = forwarded_message;
from_jid = stanza.getAttribute('from');
stanza = forwarded.querySelector('message');
to_jid = stanza.getAttribute('to');
}
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
from_resource = Strophe.getResourceFromJid(from_jid),
is_me = from_bare_jid === _converse.bare_jid;
let contact_jid;
const from_jid = stanza.getAttribute('from');
const from_bare_jid = Strophe.getBareJidFromJid(from_jid);
const is_me = from_bare_jid === _converse.bare_jid;
if (is_me) {
// I am the sender, so this must be a forwarded message...
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;
if (is_me && _.isNull(to_jid)) {
return _converse.log(`Don't know how to handle message stanza without 'to' attribute. ${stanza.outerHTML}`, Strophe.LogLevel.ERROR);
}
const contact_jid = is_me ? Strophe.getBareJidFromJid(to_jid) : from_bare_jid;
const contact = await _converse.api.contacts.get(contact_jid);
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
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 has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0;
const roster_nick = _.get(contact, 'attributes.nickname');
const chatbox = this.getChatBox(contact_jid, {
'nickname': roster_nick
}, has_body);
if (chatbox) {
const is_mam = sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).length > 0;
const message = await chatbox.getDuplicateMessage(stanza);
if (message) {