From 60f834882a6d498912377a7be4f1f884d335f550 Mon Sep 17 00:00:00 2001 From: Jeremy Mahieu Date: Thu, 12 Dec 2019 00:39:17 +0100 Subject: [PATCH 1/2] Remove nicklist when weechat clears it and bring is back if it's filled again --- js/glowingbear.js | 5 ++++- js/handlers.js | 15 +++++++++++++++ js/models.js | 13 +++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index f8bc47b..6b46756 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -149,6 +149,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', }, false); } + $rootScope.$on('nickListChanged', function() { + $scope.updateShowNicklist(); + }); $rootScope.$on('activeBufferChanged', function(event, unreadSum) { var ab = models.getActiveBuffer(); @@ -776,7 +779,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.updateShowNicklist = function() { var ab = models.getActiveBuffer(); // Check whether buffer exists and nicklist is non-empty - if (!ab || ab.isNicklistEmpty()) { + if (!ab || !ab.nicklistRequested() || ab.isNicklistEmpty()) { $scope.showNicklist = false; return false; } diff --git a/js/handlers.js b/js/handlers.js index 77c5e91..9891e8f 100644 --- a/js/handlers.js +++ b/js/handlers.js @@ -431,12 +431,24 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific /* * Handle nicklist event + * + * This event can either fill or clear a nicklist. It is always a complete nicklist. */ var handleNicklist = function(message) { var nicklist = message.objects[0].content; var group = 'root'; + + //clear the nicklists in case we are clearing + if (nicklist.length==1) + { + models.getBuffer(nicklist[0].pointers[0]).clearNicklist(); + } + + //fill the nicklist nicklist.forEach(function(n) { var buffer = models.getBuffer(n.pointers[0]); + + //buffer nicklist if (n.group === 1) { var g = new models.NickGroup(n); group = g.name; @@ -446,6 +458,9 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific buffer.addNick(group, nick); } }); + + //check if nicklist should be hidden or not + $rootScope.$emit('nickListChanged'); }; /* * Handle nicklist diff event diff --git a/js/models.js b/js/models.js index ed3e6f1..b19c0f1 100644 --- a/js/models.js +++ b/js/models.js @@ -154,6 +154,18 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo } */ }; + /* + * Clear the nicklist + */ + var clearNicklist = function() { + //only keep the root node + for (var obj in nicklist) { + if (obj !== 'root') { + delete nicklist[obj] + } + } + }; + /* * Updates a nick in nicklist */ @@ -325,6 +337,7 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo nicklist: nicklist, addNick: addNick, delNick: delNick, + clearNicklist: clearNicklist, updateNick: updateNick, getNicklistByTime: getNicklistByTime, serverSortKey: serverSortKey, From fdb24447c42b29f57749c4e0bbabf17da9243d67 Mon Sep 17 00:00:00 2001 From: Jeremy Mahieu Date: Thu, 12 Dec 2019 00:52:52 +0100 Subject: [PATCH 2/2] Missing semicolon --- js/models.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/models.js b/js/models.js index b19c0f1..469bdaf 100644 --- a/js/models.js +++ b/js/models.js @@ -161,7 +161,7 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo //only keep the root node for (var obj in nicklist) { if (obj !== 'root') { - delete nicklist[obj] + delete nicklist[obj]; } } };