Simplify/clean up the unread and notification code

with-route-provider
Tor Hveem 12 years ago
parent a9dcc68af2
commit 2617dadb65
  1. 2
      index.html
  2. 12
      js/models.js
  3. 14
      js/websockets.js

@ -100,7 +100,7 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
</li> </li>
<li class="label" ng-class="{'active': content.active }" ng-repeat="(key, content) in buffers | toArray | filter:search | filter:hasUnread | orderBy:'content.number':true"> <li class="label" ng-class="{'active': content.active }" ng-repeat="(key, content) in buffers | toArray | filter:search | filter:hasUnread | orderBy:'content.number':true">
<a href="#" ng-click="setActiveBuffer(content.id)" title="{{ content.fullName }}"> <a href="#" ng-click="setActiveBuffer(content.id)" title="{{ content.fullName }}">
<span class="badge pull-right" ng-hide="content.notification" ng-bind="content.unread"></span> <span class="badge pull-right" ng-hide="content.notification" ng-if="content.unread" ng-bind="content.unread"></span>
<span class="badge pull-right danger" ng-show="content.notification" ng-bind="content.notification"></span> <span class="badge pull-right danger" ng-show="content.notification" ng-bind="content.notification"></span>
{{ content.shortName }}<span ng-hide="content.shortName">{{ content.fullName }}</span> {{ content.shortName }}<span ng-hide="content.shortName">{{ content.fullName }}</span>
</a> </a>

@ -16,10 +16,10 @@ models.service('models', ['$rootScope', 'colors', function($rootScope, colors) {
var number = message['number'] var number = message['number']
var pointer = message['pointers'][0] var pointer = message['pointers'][0]
var lines = [] var lines = []
var active = false; var active = false
var notification = ''; var notification = 0
var unread = ''; var unread = 0
var lastSeen = -2; var lastSeen = -2
/* /*
* Adds a line to this buffer * Adds a line to this buffer
@ -40,6 +40,8 @@ models.service('models', ['$rootScope', 'colors', function($rootScope, colors) {
lines: lines, lines: lines,
addLine: addLine, addLine: addLine,
lastSeen: lastSeen, lastSeen: lastSeen,
unread: unread,
notification: notification,
} }
} }
@ -100,6 +102,8 @@ models.service('models', ['$rootScope', 'colors', function($rootScope, colors) {
var BufferList = [] var BufferList = []
activeBuffer = null; activeBuffer = null;
unreads = 0;
notifications = 0;
this.model = { 'buffers': {} } this.model = { 'buffers': {} }

@ -200,20 +200,12 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', functi
if (!initial) { if (!initial) {
if (!buffer.active && _.contains(message.tags, 'notify_message') && !_.contains(message.tags, 'notify_none')) { if (!buffer.active && _.contains(message.tags, 'notify_message') && !_.contains(message.tags, 'notify_none')) {
if (buffer.unread == '' || buffer.unread == undefined) {
buffer.unread = 1;
}else {
buffer.unread++; buffer.unread++;
} }
}
if(message.highlight || _.contains(message.tags, 'notify_private') ) { if(message.highlight || _.contains(message.tags, 'notify_private') ) {
$rootScope.createHighlight(buffer, message);
if (buffer.notification == '' || buffer.notification == undefined) {
buffer.notification = 1;
}else {
buffer.notification++; buffer.notification++;
} $rootScope.createHighlight(buffer, message);
} }
} }
} }
@ -523,10 +515,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Find next buffer with activity and switch to it // Find next buffer with activity and switch to it
for(i in $scope.buffers) { for(i in $scope.buffers) {
var buffer = $scope.buffers[i]; var buffer = $scope.buffers[i];
if((parseInt(buffer.notification) || 0) > 0) { if(buffer.notification > 0) {
$scope.setActiveBuffer(buffer.id); $scope.setActiveBuffer(buffer.id);
break; break;
}else if((parseInt(buffer.unread) || 0) > 0) { }else if(buffer.unread > 0) {
$scope.setActiveBuffer(buffer.id); $scope.setActiveBuffer(buffer.id);
break; break;
} }

Loading…
Cancel
Save