Commit c9ecd3cd authored by JC Brand's avatar JC Brand

Only initiate OTR for new messages.

parent eef002f2
......@@ -1432,13 +1432,6 @@
return this.messages.create(this.getMessageAttributes.apply(this, arguments));
},
isNewMessage: function (stanza) {
/* Given a message stanza, determine whether it's a new
* message, i.e. not an archived one.
*/
return !(sizzle('result[xmlns="'+Strophe.NS.MAM+'"]', stanza).length);
},
newMessageWillBeHidden: function () {
/* Returns a boolean to indicate whether a newly received
* message will be visible to the user or not.
......@@ -1456,7 +1449,7 @@
if (_.isNull(stanza.querySelector('body'))) {
return; // The message has no text
}
if (this.isNewMessage(stanza) && this.newMessageWillBeHidden()) {
if (utils.isNewMessage(stanza) && this.newMessageWillBeHidden()) {
this.save({'num_unread': this.get('num_unread') + 1});
_converse.incrementMsgCounter();
}
......
......@@ -93,24 +93,22 @@
if ((!text) || (!_converse.allow_otr)) {
return this.__super__.createMessage.apply(this, arguments);
}
if (text.match(/^\?OTRv23?/)) {
this.initiateOTR(text);
} else {
if (_.includes([UNVERIFIED, VERIFIED], this.get('otr_status'))) {
this.otr.receiveMsg(text);
} else {
if (text.match(/^\?OTR/)) {
if (!this.otr) {
this.initiateOTR(text);
} else {
this.otr.receiveMsg(text);
}
if (utils.isNewMessage(original_stanza)) {
if (text.match(/^\?OTRv23?/)) {
return this.initiateOTR(text);
} else if (_.includes([UNVERIFIED, VERIFIED], this.get('otr_status'))) {
return this.otr.receiveMsg(text);
} else if (text.match(/^\?OTR/)) {
if (!this.otr) {
return this.initiateOTR(text);
} else {
// Normal unencrypted message.
return this.__super__.createMessage.apply(this, arguments);
return this.otr.receiveMsg(text);
}
}
}
// Normal unencrypted message (or archived message)
return this.__super__.createMessage.apply(this, arguments);
},
generatePrivateKey: function (instance_tag) {
......
......@@ -955,7 +955,7 @@
return; // The message has no text
}
if (chatbox.get('type') !== 'chatroom' &&
chatbox.isNewMessage(data.stanza) &&
utils.isNewMessage(data.stanza) &&
chatbox.newMessageWillBeHidden()) {
var contact = _.head(_converse.roster.where({'jid': chatbox.get('jid')}));
......
......@@ -2,10 +2,12 @@
(function (root, factory) {
define([
"jquery.noconflict",
"sizzle",
"jquery.browser",
"lodash.noconflict",
"locales",
"moment_with_locales",
"strophe",
"tpl!field",
"tpl!select_option",
"tpl!form_select",
......@@ -16,7 +18,8 @@
"tpl!form_captcha"
], factory);
}(this, function (
$, dummy, _, locales, moment,
$, sizzle, dummy, _, locales, moment,
Strophe,
tpl_field,
tpl_select_option,
tpl_form_select,
......@@ -28,6 +31,7 @@
) {
"use strict";
locales = locales || {};
Strophe = Strophe.Strophe;
var XFORM_TYPE_MAP = {
'text-private': 'password',
......@@ -221,6 +225,13 @@
}
},
isNewMessage: function (stanza) {
/* Given a stanza, determine whether it's a new
* message, i.e. not a MAM archived one.
*/
return !(sizzle('result[xmlns="'+Strophe.NS.MAM+'"]', stanza).length);
},
isOTRMessage: function (message) {
var body = message.querySelector('body'),
text = (!_.isNull(body) ? body.textContent: undefined);
......
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