Merge pull request #62 from eepp/various-fixes

Various fixes
This commit is contained in:
David Cormier 2013-10-19 11:19:20 -07:00
commit caf3085594
1 changed files with 43 additions and 40 deletions

View File

@ -59,9 +59,9 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', functi
} }
var handleBufferLineAdded = function(message) { var handleBufferLineAdded = function(message) {
message['objects'][0]['content'].forEach(function(l) { message['objects'][0]['content'].forEach(function(l) {
handleLine(l, false); handleLine(l, false);
}); });
} }
var handleBufferOpened = function(message) { var handleBufferOpened = function(message) {
@ -93,31 +93,34 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', functi
* (lineinfo) messages are specified by this client. It is request after bufinfo completes * (lineinfo) messages are specified by this client. It is request after bufinfo completes
*/ */
var handleLineInfo = function(message) { var handleLineInfo = function(message) {
var lines = message['objects'][0]['content'].reverse(); var lines = message['objects'][0]['content'].reverse();
lines.forEach(function(l) { lines.forEach(function(l) {
handleLine(l, true); handleLine(l, true);
}); });
} }
/* /*
* Handle answers to hotlist request * Handle answers to hotlist request
*/ */
var handleHotlistInfo = function(message) { var handleHotlistInfo = function(message) {
var hotlist = message['objects'][0]['content']; if (message.objects.length == 0) {
hotlist.forEach(function(l) { return;
var buffer = models.getBuffer(l.buffer); }
// 1 is message var hotlist = message['objects'][0]['content'];
buffer.unread += l.count[1]; hotlist.forEach(function(l) {
// 2 is ? var buffer = models.getBuffer(l.buffer);
buffer.unread += l.count[2]; // 1 is message
// 3 is highlight buffer.unread += l.count[1];
buffer.notification += l.count[3]; // 2 is ?
/* Since there is unread messages, we can guess buffer.unread += l.count[2];
* what the last read line is and update it accordingly // 3 is highlight
*/ buffer.notification += l.count[3];
var unreadSum = _.reduce(l.count, function(memo, num){ return memo + num; }, 0); /* Since there is unread messages, we can guess
buffer.lastSeen = buffer.lines.length - 1 - unreadSum; * what the last read line is and update it accordingly
}); */
var unreadSum = _.reduce(l.count, function(memo, num){ return memo + num; }, 0);
buffer.lastSeen = buffer.lines.length - 1 - unreadSum;
});
} }
var handleEvent = function(event) { var handleEvent = function(event) {
@ -251,7 +254,7 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
$rootScope.connected = true; $rootScope.connected = true;
}); });
}); });
} }
websocket.onclose = function (evt) { websocket.onclose = function (evt) {
$log.info("Disconnected from relay"); $log.info("Disconnected from relay");
@ -290,8 +293,8 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
} }
var disconnect = function() { var disconnect = function() {
console.log(this.websocket); console.log(this.websocket);
this.websocket.close(); this.websocket.close();
} }
var sendMessage = function(message) { var sendMessage = function(message) {
@ -451,18 +454,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
}; };
$scope.hasUnread = function(buffer) { $scope.hasUnread = function(buffer) {
// if search is set, return every buffer // if search is set, return every buffer
if($scope.search && $scope.search != "") { if($scope.search && $scope.search != "") {
return true;
}
if($scope.onlyUnread) {
// Always show current buffer in list
if (models.getActiveBuffer() == buffer) {
return true; return true;
} }
return buffer.unread > 0 || buffer.notification > 0; if($scope.onlyUnread) {
} // Always show current buffer in list
return true; if (models.getActiveBuffer() == buffer) {
return true;
}
return buffer.unread > 0 || buffer.notification > 0;
}
return true;
}; };
$rootScope.switchToActivityBuffer = function() { $rootScope.switchToActivityBuffer = function() {
@ -515,13 +518,13 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
var code = $event.keyCode ? $event.keyCode : $event.charCode; var code = $event.keyCode ? $event.keyCode : $event.charCode;
// Handle escape // Handle escape
if(code == 27) { if(code == 27) {
$event.preventDefault(); $event.preventDefault();
$scope.search = ''; $scope.search = '';
} // Handle enter } // Handle enter
else if (code == 13) { else if (code == 13) {
$event.preventDefault(); $event.preventDefault();
// TODO Switch to first matching buffer and reset query // TODO Switch to first matching buffer and reset query
$scope.search = ''; $scope.search = '';
} }
} }