Unread chat messages now appear on the minimized chat view.
This commit is contained in:
parent
0d3c101cbf
commit
e2d494f0ad
45
converse.js
45
converse.js
@ -942,17 +942,6 @@
|
|||||||
this.scrollDown();
|
this.scrollDown();
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUnreadMessagesCounter: function () {
|
|
||||||
/* If the chatbox is minimized, we show a counter with the
|
|
||||||
* number of unread messages.
|
|
||||||
*/
|
|
||||||
var $count = this.$el.find('.chat-head-message-count');
|
|
||||||
var count = parseInt($count.data('count') || 0, 10) + 1;
|
|
||||||
$count.html(count).data('count', count);
|
|
||||||
if (!$count.is(':visible')) { $count.show('fast'); }
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
clearChatRoomMessages: function (ev) {
|
clearChatRoomMessages: function (ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var result = confirm(__("Are you sure you want to clear the messages from this room?"));
|
var result = confirm(__("Are you sure you want to clear the messages from this room?"));
|
||||||
@ -987,9 +976,6 @@
|
|||||||
'extra_classes': msg_dict.delayed && 'delayed' || ''
|
'extra_classes': msg_dict.delayed && 'delayed' || ''
|
||||||
});
|
});
|
||||||
$content.append($(message).children('.chat-message-content').first().text(text).addHyperlinks().addEmoticons().parent());
|
$content.append($(message).children('.chat-message-content').first().text(text).addHyperlinks().addEmoticons().parent());
|
||||||
if (this.model.get('minimized') && (!msg_time.isBefore(this.model.get('time_minimized')))) {
|
|
||||||
this.updateUnreadMessagesCounter();
|
|
||||||
}
|
|
||||||
this.scrollDown();
|
this.scrollDown();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -2609,18 +2595,45 @@
|
|||||||
'click .restore-chat': 'restore'
|
'click .restore-chat': 'restore'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
initialize: function () {
|
||||||
|
this.model.messages.on('add', function (msg) {
|
||||||
|
this.updateUnreadMessagesCounter(_.clone(msg.attributes));
|
||||||
|
}, this);
|
||||||
|
this.model.on('showSentOTRMessage', this.updateUnreadMessagesCounter, this);
|
||||||
|
this.model.on('showReceivedOTRMessage', this.updateUnreadMessagesCounter, this);
|
||||||
|
this.model.on('change:minimized', this.clearUnreadMessagesCounter, this);
|
||||||
|
},
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
var data = this.model.toJSON();
|
var data = this.model.toJSON();
|
||||||
if (this.model.get('chatroom')) {
|
if (this.model.get('chatroom')) {
|
||||||
data['title'] = this.model.get('name');
|
data.title = this.model.get('name');
|
||||||
this.$el.addClass('chat-head-chatroom');
|
this.$el.addClass('chat-head-chatroom');
|
||||||
} else {
|
} else {
|
||||||
data['title'] = this.model.get('fullname');
|
data.title = this.model.get('fullname');
|
||||||
this.$el.addClass('chat-head-chatbox');
|
this.$el.addClass('chat-head-chatbox');
|
||||||
}
|
}
|
||||||
return this.$el.html(converse.templates.trimmed_chat(data));
|
return this.$el.html(converse.templates.trimmed_chat(data));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearUnreadMessagesCounter: function () {
|
||||||
|
if (!this.model.get('minimized')) {
|
||||||
|
this.$el.find('.chat-head-message-count').html(0).data('count', 0).hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateUnreadMessagesCounter: function (msg_dict) {
|
||||||
|
var count, $count;
|
||||||
|
var msg_time = (typeof msg_dict === 'object' && moment(msg_dict.time)) || moment;
|
||||||
|
if (this.model.get('minimized') && (!msg_time.isBefore(this.model.get('time_minimized')))) {
|
||||||
|
$count = this.$el.find('.chat-head-message-count');
|
||||||
|
count = parseInt($count.data('count') || 0, 10) + 1;
|
||||||
|
$count.html(count).data('count', count);
|
||||||
|
if (!$count.is(':visible')) { $count.show('fast'); }
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
close: function (ev) {
|
close: function (ev) {
|
||||||
if (ev && ev.preventDefault) {
|
if (ev && ev.preventDefault) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
@ -841,8 +841,8 @@ dl.add-converse-contact {
|
|||||||
text-shadow: 1px 1px 0 #ccc;
|
text-shadow: 1px 1px 0 #ccc;
|
||||||
color: darkred;
|
color: darkred;
|
||||||
border-radius: 20%;
|
border-radius: 20%;
|
||||||
padding: 1px 3px;
|
padding: 2px 4px;
|
||||||
font-size: 13px;
|
font-size: 15px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -920,8 +920,8 @@ dl.add-converse-contact {
|
|||||||
text-shadow: 1px 1px 0 #ccc;
|
text-shadow: 1px 1px 0 #ccc;
|
||||||
color: darkred;
|
color: darkred;
|
||||||
border-radius: 20%;
|
border-radius: 20%;
|
||||||
padding: 1px 3px;
|
padding: 2px 4px;
|
||||||
font-size: 13px;
|
font-size: 15px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -488,11 +488,10 @@
|
|||||||
}, converse));
|
}, converse));
|
||||||
waits(50);
|
waits(50);
|
||||||
runs($.proxy(function () {
|
runs($.proxy(function () {
|
||||||
var chatview = this.chatboxviews.get(contact_jid);
|
|
||||||
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
|
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
|
||||||
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
||||||
var $count = trimmedview.$el.find('.chat-head-message-count');
|
var $count = trimmedview.$el.find('.chat-head-message-count');
|
||||||
expect(chatview.model.get('minimized')).toBeTruthy();
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
||||||
expect($count.is(':visible')).toBeTruthy();
|
expect($count.is(':visible')).toBeTruthy();
|
||||||
expect($count.data('count')).toBe(1);
|
expect($count.data('count')).toBe(1);
|
||||||
expect($count.html()).toBe('1');
|
expect($count.html()).toBe('1');
|
||||||
@ -508,21 +507,23 @@
|
|||||||
}, converse));
|
}, converse));
|
||||||
waits(50);
|
waits(50);
|
||||||
runs($.proxy(function () {
|
runs($.proxy(function () {
|
||||||
var chatview = this.chatboxviews.get(contact_jid);
|
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
|
||||||
var $count = chatview.$el.find('.chat-head-message-count');
|
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
||||||
expect(chatview.model.get('minimized')).toBeTruthy();
|
var $count = trimmedview.$el.find('.chat-head-message-count');
|
||||||
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
||||||
expect($count.is(':visible')).toBeTruthy();
|
expect($count.is(':visible')).toBeTruthy();
|
||||||
expect($count.data('count')).toBe(2);
|
expect($count.data('count')).toBe(2);
|
||||||
expect($count.html()).toBe('2');
|
expect($count.html()).toBe('2');
|
||||||
chatview.$el.find('.toggle-chatbox-button').click();
|
trimmedview.$el.find('.restore-chat').click();
|
||||||
}, converse));
|
}, converse));
|
||||||
waits(50);
|
waits(50);
|
||||||
runs($.proxy(function () {
|
runs($.proxy(function () {
|
||||||
var chatview = this.chatboxviews.get(contact_jid);
|
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
|
||||||
var $count = chatview.$el.find('.chat-head-message-count');
|
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
||||||
expect(chatview.model.get('minimized')).toBeFalsy();
|
var $count = trimmedview.$el.find('.chat-head-message-count');
|
||||||
|
expect(trimmedview.model.get('minimized')).toBeFalsy();
|
||||||
expect($count.is(':visible')).toBeFalsy();
|
expect($count.is(':visible')).toBeFalsy();
|
||||||
expect($count.data('count')).toBe(0);
|
expect($count.data('count')).toBeFalsy();
|
||||||
expect($count.html()).toBe('0');
|
expect($count.html()).toBe('0');
|
||||||
}, converse));
|
}, converse));
|
||||||
}, converse));
|
}, converse));
|
||||||
|
Loading…
Reference in New Issue
Block a user