Merge pull request #796 from torhve/resync
Periodic hotlist sync. Fixes #692
This commit is contained in:
commit
afe03fd9ea
|
@ -151,21 +151,33 @@ weechat.factory('connection',
|
||||||
_requestHotlist().then(function(hotlist) {
|
_requestHotlist().then(function(hotlist) {
|
||||||
handlers.handleHotlistInfo(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
|
// Fetch weechat time format for displaying timestamps
|
||||||
fetchConfValue('weechat.look.buffer_time_format',
|
fetchConfValue('weechat.look.buffer_time_format',
|
||||||
function() {
|
function() {
|
||||||
|
// Will set models.wconfig['weechat.look.buffer_time_format']
|
||||||
_parseWeechatTimeFormat();
|
_parseWeechatTimeFormat();
|
||||||
});
|
});
|
||||||
// Will set models.wconfig['weechat.look.buffer_time_format']
|
|
||||||
|
|
||||||
_requestSync();
|
_requestSync();
|
||||||
$log.info("Connected to relay");
|
$log.info("Connected to relay");
|
||||||
$rootScope.connected = true;
|
$rootScope.connected = true;
|
||||||
|
if (successCallback) {
|
||||||
|
successCallback();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
handleWrongPassword();
|
handleWrongPassword();
|
||||||
|
|
|
@ -340,23 +340,33 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
|
||||||
* Handle answers to hotlist request
|
* Handle answers to hotlist request
|
||||||
*/
|
*/
|
||||||
var handleHotlistInfo = function(message) {
|
var handleHotlistInfo = function(message) {
|
||||||
if (message.objects.length === 0) {
|
// Hotlist includes only buffers with unread counts so first we
|
||||||
return;
|
// 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;
|
// the unread badges in the bufferlist doesn't update if we don't do this
|
||||||
hotlist.forEach(function(l) {
|
setTimeout(function() {
|
||||||
var buffer = models.getBuffer(l.buffer);
|
$rootScope.$apply();
|
||||||
// 1 is message
|
$rootScope.$emit('notificationChanged');
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue