Activity counters stored in channel model
authorDarren <darren@darrenwhitlen.com>
Thu, 14 Aug 2014 09:52:51 +0000 (10:52 +0100)
committerDarren <darren@darrenwhitlen.com>
Thu, 14 Aug 2014 09:52:51 +0000 (10:52 +0100)
client/src/views/channel.js
client/src/views/panel.js

index 836455e61e794d704e3bd7f193f33e03d74c5fc5..f3d1ac955a723b0b0dcf198199112446326ebc0e 100644 (file)
@@ -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);
index 4b641a04bc79d8eaa18728a44599c588bdc541c1..25406a751113d780d555bea2772759218b635c5a 100644 (file)
@@ -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);