Consider delayed, non-archived messages as "new"

New in the sense that we haven't seen them before
This commit is contained in:
JC Brand 2018-06-07 12:45:53 +02:00
parent ec65bb3512
commit 083f191ead
6 changed files with 33 additions and 29 deletions

21
dist/converse.js vendored
View File

@ -62532,21 +62532,22 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
* that contains the message stanza, if it was
* contained, otherwise it's the message stanza itself.
*/
delay = delay || message.querySelector('delay');
const _converse = this.__super__._converse,
__ = _converse.__,
spoiler = message.querySelector(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`),
archive = sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop(),
spoiler = sizzle(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`, original_stanza).pop(),
delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop(),
chat_state = message.getElementsByTagName(_converse.COMPOSING).length && _converse.COMPOSING || message.getElementsByTagName(_converse.PAUSED).length && _converse.PAUSED || message.getElementsByTagName(_converse.INACTIVE).length && _converse.INACTIVE || message.getElementsByTagName(_converse.ACTIVE).length && _converse.ACTIVE || message.getElementsByTagName(_converse.GONE).length && _converse.GONE;
const attrs = {
'type': message.getAttribute('type'),
'chat_state': chat_state,
'delayed': !_.isNull(delay),
'is_archived': !_.isNil(archive),
'is_delayed': !_.isNil(delay),
'is_spoiler': !_.isNil(spoiler),
'message': this.getMessageBody(message) || undefined,
'msgid': message.getAttribute('id'),
'time': delay ? delay.getAttribute('stamp') : moment().format(),
'is_spoiler': !_.isNull(spoiler)
'type': message.getAttribute('type')
};
if (attrs.type === 'groupchat') {
@ -62589,7 +62590,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
const attrs = this.getMessageAttributesFromStanza(message, original_stanza);
const is_csn = u.isOnlyChatStateNotification(attrs);
if (is_csn && (attrs.delayed || attrs.type === 'groupchat' && Strophe.getResourceFromJid(attrs.from) == this.get('nick'))) {
if (is_csn && (attrs.is_delayed || attrs.type === 'groupchat' && Strophe.getResourceFromJid(attrs.from) == this.get('nick'))) {
// XXX: MUC leakage
// No need showing delayed or our own CSN messages
return;
@ -68427,7 +68428,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
},
getExtraMessageClasses() {
let extra_classes = this.model.get('delayed') && 'delayed' || '';
let extra_classes = this.model.get('is_delayed') && 'delayed' || '';
if (this.model.get('type') === 'groupchat' && this.model.get('sender') === 'them') {
if (this.model.collection.chatbox.isUserMentioned(this.model.get('message'))) {
@ -80775,9 +80776,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
* message, i.e. not a MAM archived one.
*/
if (message instanceof Element) {
return !sizzle('result[xmlns="' + Strophe.NS.MAM + '"]', message).length && !sizzle('delay[xmlns="' + Strophe.NS.DELAY + '"]', message).length;
return !(sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, message).length && sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, message).length);
} else {
return !message.get('delayed');
return !(message.get('is_delayed') && message.get('is_archived'));
}
};

View File

@ -745,7 +745,7 @@
expect(chatbox.messages.length).toEqual(1);
var msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
var $chat_content = $(chatboxview.el).find('.chat-content');
var status_text = $chat_content.find('.chat-info.chat-state-notification').text();
expect(status_text).toBe('Typing from another device');
@ -893,7 +893,7 @@
expect(chatbox.messages.length).toEqual(1);
var msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
var $chat_content = $(chatboxview.el).find('.chat-content');
var status_text = $chat_content.find('.chat-info.chat-state-notification').text();
expect(status_text).toBe('Stopped typing on the other device');

View File

@ -60,7 +60,7 @@
expect(msg_obj.get('message')).toEqual(message);
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[0]);
expect(msg_obj.get('sender')).toEqual('them');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
// Now check that the message appears inside the chatbox in the DOM
var chat_content = chatboxview.el.querySelector('.chat-content');
expect(chat_content.querySelector('.chat-msg .chat-msg-text').textContent).toEqual(message);
@ -176,7 +176,7 @@
expect(msg_obj.get('message')).toEqual(message);
expect(msg_obj.get('fullname')).toEqual(undefined);
expect(msg_obj.get('sender')).toEqual('them');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
// Now check that the message appears inside the chatbox in the DOM
var chat_content = chatboxview.el.querySelector('.chat-content');
expect(chat_content.querySelector('.chat-msg .chat-msg-text').textContent).toEqual(message);
@ -690,7 +690,7 @@
expect(msg_obj.get('message')).toEqual(msgtext);
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[1]);
expect(msg_obj.get('sender')).toEqual('them');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
// Now check that the message appears inside the chatbox in the DOM
var chat_content = chatboxview.el.querySelector('.chat-content');
expect(chat_content.querySelector('.chat-msg .chat-msg-text').textContent).toEqual(msgtext);
@ -743,7 +743,7 @@
expect(msg_obj.get('message')).toEqual(msgtext);
expect(msg_obj.get('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
// Now check that the message appears inside the chatbox in the DOM
var $chat_content = $(chatboxview.el).find('.chat-content');
var msg_txt = $chat_content.find('.chat-msg').find('.chat-msg-text').text();
@ -899,7 +899,7 @@
expect(msg_obj.get('message')).toEqual(message);
expect(msg_obj.get('fullname')).toEqual(contact_name);
expect(msg_obj.get('sender')).toEqual('them');
expect(msg_obj.get('delayed')).toEqual(true);
expect(msg_obj.get('is_delayed')).toEqual(true);
return test_utils.waitUntil(() => chatbox.vcard.get('fullname') === 'Candice van der Knijff')
.then(function () {
@ -945,7 +945,7 @@
expect(msg_obj.get('message')).toEqual(message);
expect(msg_obj.get('fullname')).toEqual(contact_name);
expect(msg_obj.get('sender')).toEqual('them');
expect(msg_obj.get('delayed')).toEqual(false);
expect(msg_obj.get('is_delayed')).toEqual(false);
msg_txt = $chat_content.find('.chat-msg').last().find('.chat-msg-text').text();
expect(msg_txt).toEqual(message);

View File

@ -439,11 +439,11 @@
* that contains the message stanza, if it was
* contained, otherwise it's the message stanza itself.
*/
delay = delay || message.querySelector('delay');
const { _converse } = this.__super__,
{ __ } = _converse,
spoiler = message.querySelector(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`),
archive = sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop(),
spoiler = sizzle(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`, original_stanza).pop(),
delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop(),
chat_state = message.getElementsByTagName(_converse.COMPOSING).length && _converse.COMPOSING ||
message.getElementsByTagName(_converse.PAUSED).length && _converse.PAUSED ||
message.getElementsByTagName(_converse.INACTIVE).length && _converse.INACTIVE ||
@ -451,13 +451,14 @@
message.getElementsByTagName(_converse.GONE).length && _converse.GONE;
const attrs = {
'type': message.getAttribute('type'),
'chat_state': chat_state,
'delayed': !_.isNull(delay),
'is_archived': !_.isNil(archive),
'is_delayed': !_.isNil(delay),
'is_spoiler': !_.isNil(spoiler),
'message': this.getMessageBody(message) || undefined,
'msgid': message.getAttribute('id'),
'time': delay ? delay.getAttribute('stamp') : moment().format(),
'is_spoiler': !_.isNull(spoiler)
'type': message.getAttribute('type')
};
if (attrs.type === 'groupchat') {
attrs.from = message.getAttribute('from');
@ -493,7 +494,7 @@
*/
const attrs = this.getMessageAttributesFromStanza(message, original_stanza);
const is_csn = u.isOnlyChatStateNotification(attrs);
if (is_csn && (attrs.delayed || (attrs.type === 'groupchat' && Strophe.getResourceFromJid(attrs.from) == this.get('nick')))) {
if (is_csn && (attrs.is_delayed || (attrs.type === 'groupchat' && Strophe.getResourceFromJid(attrs.from) == this.get('nick')))) {
// XXX: MUC leakage
// No need showing delayed or our own CSN messages
return;

View File

@ -225,7 +225,7 @@
},
getExtraMessageClasses () {
let extra_classes = this.model.get('delayed') && 'delayed' || '';
let extra_classes = this.model.get('is_delayed') && 'delayed' || '';
if (this.model.get('type') === 'groupchat' && this.model.get('sender') === 'them') {
if (this.model.collection.chatbox.isUserMentioned(this.model.get('message'))) {
// Add special class to mark groupchat messages

View File

@ -483,10 +483,12 @@
* message, i.e. not a MAM archived one.
*/
if (message instanceof Element) {
return !sizzle('result[xmlns="'+Strophe.NS.MAM+'"]', message).length &&
!sizzle('delay[xmlns="'+Strophe.NS.DELAY+'"]', message).length;
return !(
sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, message).length &&
sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, message).length
);
} else {
return !message.get('delayed');
return !(message.get('is_delayed') && message.get('is_archived'));
}
};