Commit da1f1035 authored by JC Brand's avatar JC Brand

Bugfix. Don't include .chat-events, to avoid null reference

parent 2c7a942f
...@@ -972,7 +972,7 @@ ...@@ -972,7 +972,7 @@
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'from': sender_jid, 'from': sender_jid,
'type': 'chat'}) 'type': 'chat'})
.c('body').t("message from today") .c('body').t("message")
.tree(); .tree();
_converse.chatboxes.onMessage(msg); _converse.chatboxes.onMessage(msg);
...@@ -996,7 +996,7 @@ ...@@ -996,7 +996,7 @@
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'from': sender_jid, 'from': sender_jid,
'type': 'chat'}) 'type': 'chat'})
.c('body').t("Inbetween message") .c('body').t("Inbetween message").up()
.tree(); .tree();
_converse.chatboxes.onMessage(msg); _converse.chatboxes.onMessage(msg);
...@@ -1020,7 +1020,7 @@ ...@@ -1020,7 +1020,7 @@
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'from': sender_jid, 'from': sender_jid,
'type': 'chat'}) 'type': 'chat'})
.c('body').t("An earlier message today") .c('body').t("An earlier message on the next day")
.tree(); .tree();
_converse.chatboxes.onMessage(msg); _converse.chatboxes.onMessage(msg);
...@@ -1032,7 +1032,31 @@ ...@@ -1032,7 +1032,31 @@
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'from': sender_jid, 'from': sender_jid,
'type': 'chat'}) 'type': 'chat'})
.c('body').t("newer message from today") .c('body').t("newer message from the next day")
.tree();
_converse.chatboxes.onMessage(msg);
// Insert <composing> message, to also check that
// text messages are inserted correctly with
// temporary chat events in the chat contents.
msg = $msg({
'id': 'aeb219',
'to': _converse.bare_jid,
'xmlns': 'jabber:client',
'from': sender_jid,
'type': 'chat'})
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
.tree();
_converse.chatboxes.onMessage(msg);
msg = $msg({
'id': 'aeb220',
'to': _converse.bare_jid,
'xmlns': 'jabber:client',
'from': sender_jid,
'type': 'chat'})
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
.c('body').t("latest message")
.tree(); .tree();
_converse.chatboxes.onMessage(msg); _converse.chatboxes.onMessage(msg);
...@@ -1041,7 +1065,7 @@ ...@@ -1041,7 +1065,7 @@
chatboxview.clearSpinner(); //cleanup chatboxview.clearSpinner(); //cleanup
var $time = $chat_content.find('time'); var $time = $chat_content.find('time');
expect($time.length).toEqual(3); expect($time.length).toEqual(4);
$time = $chat_content.find('time:first'); $time = $chat_content.find('time:first');
expect($time.data('isodate')).toEqual('2017-12-31T00:00:00+00:00'); expect($time.data('isodate')).toEqual('2017-12-31T00:00:00+00:00');
...@@ -1058,15 +1082,19 @@ ...@@ -1058,15 +1082,19 @@
$el = $chat_content.find('.chat-message:eq(2)'); $el = $chat_content.find('.chat-message:eq(2)');
expect($el.find('.chat-msg-content').text()).toEqual('another inbetween message'); expect($el.find('.chat-msg-content').text()).toEqual('another inbetween message');
$time = $chat_content.find('time:last'); $time = $chat_content.find('time:nth(2)');
expect($time.data('isodate')).toEqual('2018-01-02T00:00:00+00:00'); expect($time.data('isodate')).toEqual('2018-01-02T00:00:00+00:00');
expect($time[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toBe('An earlier message today'); expect($time[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toBe('An earlier message on the next day');
$el = $chat_content.find('.chat-message:eq(3)'); $el = $chat_content.find('.chat-message:eq(3)');
expect($el.find('.chat-msg-content').text()).toEqual('An earlier message today'); expect($el.find('.chat-msg-content').text()).toEqual('An earlier message on the next day');
$el = $chat_content.find('.chat-message:eq(4)'); $el = $chat_content.find('.chat-message:eq(4)');
expect($el.find('.chat-msg-content').text()).toEqual('message from today'); expect($el.find('.chat-msg-content').text()).toEqual('message');
expect($el[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toEqual('newer message from today'); expect($el[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toEqual('newer message from the next day');
$time = $chat_content.find('time:last');
expect($time.data('isodate')).toEqual(moment().startOf('day').format());
expect($time[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toBe('latest message');
done(); done();
}); });
})); }));
......
...@@ -468,8 +468,14 @@ ...@@ -468,8 +468,14 @@
if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) { if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) {
return most_recent_date; return most_recent_date;
} }
/* XXX: Besides .chat-message and .chat-date elements, there are also
* .chat-event elements. These are however temporary and
* removed once a new element is inserted into the chat
* area, so we don't query for them here, otherwise we get
* a null reference later upon element insertion.
*/
const msg_dates = _.invokeMap( const msg_dates = _.invokeMap(
sizzle('.message, .chat-info', this.content), sizzle('.chat-message, .chat-date', this.content),
Element.prototype.getAttribute, 'data-isodate' Element.prototype.getAttribute, 'data-isodate'
) )
if (_.isObject(cutoff)) { if (_.isObject(cutoff)) {
...@@ -621,6 +627,7 @@ ...@@ -621,6 +627,7 @@
} else if (message.get('chat_state') === _converse.GONE) { } else if (message.get('chat_state') === _converse.GONE) {
this.showStatusNotification(message.get('fullname')+' '+__('has gone away')); this.showStatusNotification(message.get('fullname')+' '+__('has gone away'));
} }
return message;
}, },
shouldShowOnTextMessage () { shouldShowOnTextMessage () {
...@@ -674,11 +681,14 @@ ...@@ -674,11 +681,14 @@
} }
if (message.get('type') === 'error') { if (message.get('type') === 'error') {
this.handleErrorMessage(message); this.handleErrorMessage(message);
} else if (!message.get('message')) {
this.handleChatStateMessage(message);
} else { } else {
if (message.get('chat_state')) {
this.handleChatStateMessage(message);
}
if (message.get('message')) {
this.handleTextMessage(message); this.handleTextMessage(message);
} }
}
_converse.emit('messageAdded', { _converse.emit('messageAdded', {
'message': message, 'message': message,
'chatbox': this.model 'chatbox': this.model
......
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