From af03387c667d408b311f60d5e43437b5a00d93ba Mon Sep 17 00:00:00 2001 From: Darren Date: Thu, 14 Aug 2014 10:52:51 +0100 Subject: [PATCH] Activity counters stored in channel model --- client/src/views/channel.js | 19 +++---------------- client/src/views/panel.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/client/src/views/channel.js b/client/src/views/channel.js index 836455e..f3d1ac9 100644 --- a/client/src/views/channel.js +++ b/client/src/views/channel.js @@ -107,8 +107,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ // Only inrement the counters if we're not the active panel if (this.model.isActive()) return; - var $act = this.model.tab.find('.activity'), - count_all_activity = _kiwi.global.settings.get('count_all_activity'), + var count_all_activity = _kiwi.global.settings.get('count_all_activity'), exclude_message_types, new_count; // Set the default config value @@ -127,21 +126,9 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ ]; if (count_all_activity || _.indexOf(exclude_message_types, msg.type) === -1) { - new_count = $act.data('unread_counter') || 0; + new_count = this.model.get('activity_counter') || 0; new_count++; - $act.data('unread_counter', new_count); - - if (new_count > 999) { - $act.text('999+'); - } else { - $act.text(new_count); - } - - if (new_count === 0) { - $act.addClass('zero'); - } else { - $act.removeClass('zero'); - } + this.model.set('activity_counter', new_count); } }).apply(this); diff --git a/client/src/views/panel.js b/client/src/views/panel.js index 4b641a0..25406a7 100644 --- a/client/src/views/panel.js +++ b/client/src/views/panel.js @@ -25,6 +25,22 @@ _kiwi.view.Panel = Backbone.View.extend({ this.alert_level = 0; this.model.set({"view": this}, {"silent": true}); + + this.listenTo(this.model, 'change:activity_counter', function(model, new_count) { + var $act = this.model.tab.find('.activity'); + + if (new_count > 999) { + $act.text('999+'); + } else { + $act.text(new_count); + } + + if (new_count === 0) { + $act.addClass('zero'); + } else { + $act.removeClass('zero'); + } + }); }, render: function () { @@ -49,7 +65,7 @@ _kiwi.view.Panel = Backbone.View.extend({ // Remove any alerts and activity counters for this panel this.alert('none'); - this.model.tab.find('.activity').text('0').addClass('zero'); + this.model.set('activity_counter', 0); _kiwi.app.panels.trigger('active', this.model, _kiwi.app.panels().active); this.model.trigger('active', this.model); -- 2.25.1