From 78b33798c6fca5650ea45ee67f7c4cf9d0014c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Thu, 26 Mar 2015 11:02:06 +0100 Subject: [PATCH 1/2] Fix commands for buffers whose fullname contain whitespace Use pointers if Weechat version is recent enough (1.0+). Otherwise, not marking stuff as read is probably the lesser evil than crashing weechat... --- js/connection.js | 2 +- js/models.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/js/connection.js b/js/connection.js index 48d5cab..70c0065 100644 --- a/js/connection.js +++ b/js/connection.js @@ -246,7 +246,7 @@ weechat.factory('connection', */ var sendMessage = function(message) { ngWebsockets.send(weeChat.Protocol.formatInput({ - buffer: models.getActiveBuffer().fullName, + buffer: models.getActiveBufferReference(), data: message })); }; diff --git a/js/models.js b/js/models.js index 4b7d1c7..7521764 100644 --- a/js/models.js +++ b/js/models.js @@ -451,6 +451,22 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) return activeBuffer; }; + /* + * Returns a reference to the currently active buffer that + * WeeChat understands without crashing, even if it's invalid + * + * @return active buffer pointer (WeeChat 1.0+) or fullname (older versions) + */ + this.getActiveBufferReference = function() { + if (this.version !== null && parseInt(this.version.charAt(0)) >= 1) { + // pointers are being validated, they're more reliable than + // fullName (e.g. if fullName contains spaces) + return activeBuffer.id; + } else { + return activeBuffer.fullName; + } + }; + /* * Returns the previous current active buffer * From 97b937f0156d381fed539282d0eb57e3a898aad3 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Thu, 26 Mar 2015 13:45:53 +0100 Subject: [PATCH 2/2] Use correct pointer string --- js/models.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/models.js b/js/models.js index 7521764..6860918 100644 --- a/js/models.js +++ b/js/models.js @@ -461,7 +461,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) if (this.version !== null && parseInt(this.version.charAt(0)) >= 1) { // pointers are being validated, they're more reliable than // fullName (e.g. if fullName contains spaces) - return activeBuffer.id; + return "0x"+activeBuffer.id; } else { return activeBuffer.fullName; }