Use new command for "syncing" hotlist.

This patch also implements parsing version message and using that to
check that the WeeChat is new enough to use the new command.
This commit is contained in:
Tor Hveem 2015-03-21 14:08:09 +01:00
parent 703e67a221
commit c71ce1b404
4 changed files with 28 additions and 8 deletions

View File

@ -78,7 +78,8 @@ weechat.factory('connection',
// a version command. If it fails, it means the we
// did not provide the proper password.
_initializeConnection(passwd).then(
function() {
function(version) {
handlers.handleVersionInfo(version);
// Connection is successful
// Send all the other commands required for initialization
_requestBufferInfos().then(function(bufinfo) {

View File

@ -213,13 +213,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$timeout(function() {
$rootScope.scrollWithBuffer(true);
});
// If user wants to sync hotlist with weechat
// we will send a /buffer bufferName command every time
// the user switches a buffer. This will ensure that notifications
// are cleared in the buffer the user switches to
if (settings.hotlistsync && ab.fullName) {
connection.sendCoreCommand('/buffer ' + ab.fullName);
}
// Clear search term on buffer change
$scope.search = '';
@ -232,6 +225,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
document.getElementById('sendMessage').focus();
}, 0);
}
// Do this part last since it's not important for the UI
if (settings.hotlistsync && ab.fullName) {
if (parseInt(models.version.charAt(0)) >= 1) {
// WeeChat >= 1 supports clearing hotlist with this command
connection.sendMessage('/buffer set hotlist -1');
} else {
// If user wants to sync hotlist with weechat
// we will send a /buffer bufferName command every time
// the user switches a buffer. This will ensure that notifications
// are cleared in the buffer the user switches to
connection.sendCoreCommand('/buffer ' + ab.fullName);
}
}
});
$rootScope.favico = new Favico({animation: 'none'});

View File

@ -5,6 +5,14 @@ var weechat = angular.module('weechat');
weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notifications', function($rootScope, $log, models, plugins, notifications) {
var handleVersionInfo = function(message) {
console.log(message.objects[0]);
var content = message.objects[0].content;
var version = content.value;
// Store the WeeChat version in models
models.version = version;
};
var handleBufferClosing = function(message) {
var bufferMessage = message.objects[0].content[0];
var bufferId = bufferMessage.pointers[0];
@ -260,6 +268,7 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
};
return {
handleVersionInfo: handleVersionInfo,
handleEvent: handleEvent,
handleLineInfo: handleLineInfo,
handleHotlistInfo: handleHotlistInfo,

View File

@ -8,6 +8,9 @@
var models = angular.module('weechatModels', []);
models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) {
// WeeChat version
this.version = null;
var parseRichText = function(text) {
var textElements = weeChat.Protocol.rawText2Rich(text),
typeToClassPrefixFg = {