Periodic hotlist sync. Fixes #692
There is a bug in WeeChat when hdata is null, which happens when the hotlist is empty (meaning all buffers are read). Our websocket callback machinery expects every command with id to return data, so this code in current versions of WeeChat will lead to a slow leak. But I think lots of things in our code will do this already so I'm not entirely sure it's too problematic to let this patch go by. We could use infolists instead of hdata, but that is cumbersome to parse and less performant for WeeChat, and sends more data over the wire. I propose we make a separate attempt at cleaning up the callbacks. Since we store time on them we could have a cleanuptask that looks through them and deletes old callbacks. Maybe @dcormier could have a look?
This commit is contained in:
parent
bc117aa8ce
commit
a527428763
2 changed files with 43 additions and 21 deletions
|
@ -151,21 +151,33 @@ weechat.factory('connection',
|
|||
_requestHotlist().then(function(hotlist) {
|
||||
handlers.handleHotlistInfo(hotlist);
|
||||
|
||||
if (successCallback) {
|
||||
successCallback();
|
||||
}
|
||||
});
|
||||
// Schedule hotlist syncing every so often so that this
|
||||
// client will have unread counts (mostly) in sync with
|
||||
// other clients or terminal usage directly.
|
||||
setInterval(function() {
|
||||
if ($rootScope.connected) {
|
||||
_requestHotlist().then(function(hotlist) {
|
||||
handlers.handleHotlistInfo(hotlist);
|
||||
|
||||
});
|
||||
}
|
||||
}, 60000); // Sync hotlist every 60 second
|
||||
|
||||
|
||||
// Fetch weechat time format for displaying timestamps
|
||||
fetchConfValue('weechat.look.buffer_time_format',
|
||||
function() {
|
||||
// Will set models.wconfig['weechat.look.buffer_time_format']
|
||||
_parseWeechatTimeFormat();
|
||||
});
|
||||
// Will set models.wconfig['weechat.look.buffer_time_format']
|
||||
});
|
||||
|
||||
_requestSync();
|
||||
$log.info("Connected to relay");
|
||||
$rootScope.connected = true;
|
||||
if (successCallback) {
|
||||
successCallback();
|
||||
}
|
||||
},
|
||||
function() {
|
||||
handleWrongPassword();
|
||||
|
|
|
@ -340,23 +340,33 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
|
|||
* Handle answers to hotlist request
|
||||
*/
|
||||
var handleHotlistInfo = function(message) {
|
||||
if (message.objects.length === 0) {
|
||||
return;
|
||||
// Hotlist includes only buffers with unread counts so first we
|
||||
// iterate all our buffers and resets the counts.
|
||||
_.each(models.getBuffers(), function(buffer) {
|
||||
buffer.unread = 0;
|
||||
buffer.notification = 0;
|
||||
});
|
||||
if (message.objects.length > 0) {
|
||||
var hotlist = message.objects[0].content;
|
||||
hotlist.forEach(function(l) {
|
||||
var buffer = models.getBuffer(l.buffer);
|
||||
// 1 is message
|
||||
buffer.unread = l.count[1];
|
||||
// 2 is private
|
||||
buffer.notification = l.count[2];
|
||||
// 3 is highlight
|
||||
buffer.notification = l.count[3];
|
||||
/* Since there is unread messages, we can guess
|
||||
* 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 hotlist = message.objects[0].content;
|
||||
hotlist.forEach(function(l) {
|
||||
var buffer = models.getBuffer(l.buffer);
|
||||
// 1 is message
|
||||
buffer.unread += l.count[1];
|
||||
// 2 is private
|
||||
buffer.notification += l.count[2];
|
||||
// 3 is highlight
|
||||
buffer.notification += l.count[3];
|
||||
/* Since there is unread messages, we can guess
|
||||
* 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;
|
||||
// the unread badges in the bufferlist doesn't update if we don't do this
|
||||
setTimeout(function() {
|
||||
$rootScope.$apply();
|
||||
$rootScope.$emit('notificationChanged');
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue