Simplify updateShowNicklist

This commit is contained in:
Lorenz Hübschle-Schneider 2017-04-17 18:04:30 +02:00 committed by Lorenz Hübschle-Schneider
parent 9c28ec4055
commit 89bfac964e

View file

@ -168,13 +168,13 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Send a request for the nicklist if it hasn't been loaded yet // Send a request for the nicklist if it hasn't been loaded yet
if (!ab.nicklistRequested()) { if (!ab.nicklistRequested()) {
connection.requestNicklist(ab.id, function() { connection.requestNicklist(ab.id, function() {
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
// Scroll after nicklist has been loaded, as it may break long lines // Scroll after nicklist has been loaded, as it may break long lines
$rootScope.scrollWithBuffer(true); $rootScope.scrollWithBuffer(true);
}); });
} else { } else {
// Check if we should show nicklist or not // Check if we should show nicklist or not
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
} }
if (ab.requestedLines < $scope.lines_per_screen) { if (ab.requestedLines < $scope.lines_per_screen) {
@ -340,11 +340,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} else if ($scope.swipeStatus === -1) { } else if ($scope.swipeStatus === -1) {
// hide nicklist // hide nicklist
$scope.swipeStatus = 0; $scope.swipeStatus = 0;
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
} else { } else {
console.log("Weird swipe status:", $scope.swipeStatus); console.log("Weird swipe status:", $scope.swipeStatus);
$scope.swipeStatus = 0; // restore sanity $scope.swipeStatus = 0; // restore sanity
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
$scope.hideSidebar(); $scope.hideSidebar();
} }
}; };
@ -356,13 +356,13 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} else if ($scope.swipeStatus === 0) { } else if ($scope.swipeStatus === 0) {
// show nicklist // show nicklist
$scope.swipeStatus = -1; $scope.swipeStatus = -1;
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
} else if ($scope.swipeStatus === -1) { } else if ($scope.swipeStatus === -1) {
/* do nothing */ /* do nothing */
} else { } else {
console.log("Weird swipe status:", $scope.swipeStatus); console.log("Weird swipe status:", $scope.swipeStatus);
$scope.swipeStatus = 0; // restore sanity $scope.swipeStatus = 0; // restore sanity
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
$scope.hideSidebar(); $scope.hideSidebar();
} }
}; };
@ -572,7 +572,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Wrap in a condition so we save ourselves the $apply if nothing changes (50ms or more) // Wrap in a condition so we save ourselves the $apply if nothing changes (50ms or more)
if ($scope.wasMobileUi && !utils.isMobileUi()) { if ($scope.wasMobileUi && !utils.isMobileUi()) {
$scope.showSidebar(); $scope.showSidebar();
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
} }
$scope.wasMobileUi = utils.isMobileUi(); $scope.wasMobileUi = utils.isMobileUi();
$scope.calculateNumLines(); $scope.calculateNumLines();
@ -749,7 +749,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Watch model and update show setting when it changes // Watch model and update show setting when it changes
settings.addCallback('nonicklist', function() { settings.addCallback('nonicklist', function() {
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
// restore bottom view // restore bottom view
if ($rootScope.connected && $rootScope.bufferBottom) { if ($rootScope.connected && $rootScope.bufferBottom) {
$timeout(function(){ $timeout(function(){
@ -758,30 +758,29 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} }
}); });
settings.addCallback('alwaysnicklist', function() { settings.addCallback('alwaysnicklist', function() {
$scope.showNicklist = $scope.updateShowNicklist(); $scope.updateShowNicklist();
}); });
$scope.showNicklist = false; $scope.showNicklist = false;
// Utility function that template can use to check if nicklist should // Utility function that template can use to check if nicklist should
// be displayed for current buffer or not // be displayed for current buffer or not
// is called on buffer switch // is called on buffer switch and certain swipe actions
$scope.updateShowNicklist = function() { $scope.updateShowNicklist = function() {
var ab = models.getActiveBuffer(); $scope.showNicklist = (function() {
if (!ab) { var ab = models.getActiveBuffer();
return false; // Check whether buffer exists and nicklist is non-empty
} if (!ab || ab.isNicklistEmpty()) {
// Check if option no nicklist is set (ignored on mobile) return false;
if (!utils.isMobileUi() && settings.nonicklist && !settings.alwaysnicklist) { }
return false; // Check if nicklist is disabled in settings (ignored on mobile)
} if (!utils.isMobileUi() && settings.nonicklist) {
// Check if nicklist is empty return false;
if (ab.isNicklistEmpty()) { }
return false; // mobile: hide nicklist unless overriden by setting or swipe action
} if (utils.isMobileUi() && !settings.alwaysnicklist && $scope.swipeStatus !== -1) {
// Check whether to show nicklist on mobile return false;
if (utils.isMobileUi() && !settings.alwaysnicklist && $scope.swipeStatus !== -1) { }
return false; return true;
} })();
return true;
}; };
//XXX not sure whether this belongs here //XXX not sure whether this belongs here