Commit fc2dfa8f authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 10066785 da1f1035
...@@ -643,7 +643,7 @@ ...@@ -643,7 +643,7 @@
.then(function () { .then(function () {
expect(_converse.api.vcard.get).toHaveBeenCalled(); expect(_converse.api.vcard.get).toHaveBeenCalled();
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return chatbox.get('fullname') === mock.cur_names[0]; return chatbox.get('fullname') === mock.cur_names[0];
}, 100); }, 100);
}).then(function () { }).then(function () {
done(); done();
...@@ -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,16 +1032,40 @@ ...@@ -1032,16 +1032,40 @@
'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(); .tree();
_converse.chatboxes.onMessage(msg); _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();
_converse.chatboxes.onMessage(msg);
var chatboxview = _converse.chatboxviews.get(sender_jid); var chatboxview = _converse.chatboxviews.get(sender_jid);
var $chat_content = $(chatboxview.el).find('.chat-content'); var $chat_content = $(chatboxview.el).find('.chat-content');
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)) {
...@@ -498,9 +504,8 @@ ...@@ -498,9 +504,8 @@
* attributes. * attributes.
*/ */
const current_msg_date = moment(attrs.time) || moment, const current_msg_date = moment(attrs.time) || moment,
prepend_html = _.bind(this.content.insertAdjacentHTML, this.content, 'afterbegin'), previous_msg_date = this.getLastMessageDate(current_msg_date),
previous_msg_date = this.getLastMessageDate(current_msg_date), message_el = this.renderMessage(attrs);
message_el = this.renderMessage(attrs);
if (_.isNull(previous_msg_date)) { if (_.isNull(previous_msg_date)) {
this.content.insertAdjacentElement('afterbegin', message_el); this.content.insertAdjacentElement('afterbegin', message_el);
...@@ -622,6 +627,7 @@ ...@@ -622,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 () {
...@@ -675,10 +681,13 @@ ...@@ -675,10 +681,13 @@
} }
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 {
this.handleTextMessage(message); if (message.get('chat_state')) {
this.handleChatStateMessage(message);
}
if (message.get('message')) {
this.handleTextMessage(message);
}
} }
_converse.emit('messageAdded', { _converse.emit('messageAdded', {
'message': message, 'message': message,
......
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