From 147e62d00094f794b44ecc45067408c875e4495b Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 30 Oct 2014 11:48:58 +0100 Subject: [PATCH] Don't increment unread msgs counter for chat state. Also update release notes. updates #267 --- converse.js | 15 ++++++++++----- docs/CHANGES.rst | 1 + spec/minchats.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/converse.js b/converse.js index 4240fd3c7..241edaa3d 100644 --- a/converse.js +++ b/converse.js @@ -909,6 +909,9 @@ if (!body) { if (composing.length || paused.length) { + // FIXME: use one attribute for chat states (e.g. + // chatstate) instead of saving 'paused' and + // 'composing' separately. this.messages.add({ fullname: fullname, sender: 'them', @@ -3043,12 +3046,14 @@ }, initialize: function () { - this.model.messages.on('add', function(msg) { - if (!msg.attributes.composing) {this.updateUnreadMessagesCounter();} - } , this); - this.model.on('showSentOTRMessage', this.updateUnreadMessagesCounter, this); - this.model.on('showReceivedOTRMessage', this.updateUnreadMessagesCounter, this); + this.model.messages.on('add', function (m) { + if (!(m.get('composing') || m.get('paused'))) { + this.updateUnreadMessagesCounter(); + } + }, this); this.model.on('change:minimized', this.clearUnreadMessagesCounter, this); + this.model.on('showReceivedOTRMessage', this.updateUnreadMessagesCounter, this); + this.model.on('showSentOTRMessage', this.updateUnreadMessagesCounter, this); }, render: function () { diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index daba6fb05..11542c7d2 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -17,6 +17,7 @@ Changelog * #151 Browser locks/freezes with many roster users. [jcbrand] * #251 Non-minified builds for debugging. [jcbrand] * #264 Remove unnecessary commas for ie8 compatibility. [Deuteu] +* #267 Unread messages counter wrongly gets incremented by chat state notifications. [Deuteu] 0.8.3 (2014-09-22) ------------------ diff --git a/spec/minchats.js b/spec/minchats.js index 1f94c7b77..2449f4b59 100644 --- a/spec/minchats.js +++ b/spec/minchats.js @@ -84,6 +84,42 @@ expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy(); expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i+1).toString()); } + // Chat state notifications don't increment the unread messages counter + // state + this.chatboxes.onMessage($msg({ + from: contact_jid, + to: this.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('composing', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()); + expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString()); + + // state + this.chatboxes.onMessage($msg({ + from: contact_jid, + to: this.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()); + expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString()); + + // state + this.chatboxes.onMessage($msg({ + from: contact_jid, + to: this.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('gone', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()); + expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString()); + + // state + this.chatboxes.onMessage($msg({ + from: contact_jid, + to: this.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('inactive', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()); + expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString()); }, converse)); }, converse, mock, test_utils));