Maintained cached flatnicklist, maintain shownicklist cached value for
template
This commit is contained in:
parent
a415a3ec3c
commit
e8e44d85ce
3 changed files with 58 additions and 13 deletions
|
@ -225,8 +225,8 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="bufferlines" class="monospace" ng-class="{'withnicklist': nonicklist==false}">
|
<div id="bufferlines" class="monospace" ng-class="{'withnicklist': showNicklist}">
|
||||||
<div id="nicklist" ng-hide="nonicklist" class="vertical-line-left">
|
<div id="nicklist" ng-show="showNicklist" class="vertical-line-left">
|
||||||
<ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist">
|
<ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist">
|
||||||
<li class="" ng-repeat="nick in group.nicks|orderBy:'nick.name'">
|
<li class="" ng-repeat="nick in group.nicks|orderBy:'nick.name'">
|
||||||
<a ng-click="nickAction(nick)"><span ng-class="nick.prefixClasses">{{nick.prefix}}</span><span ng-class="nick.nameClasses">{{nick.name}}</span></a>
|
<a ng-click="nickAction(nick)"><span ng-class="nick.prefixClasses">{{nick.prefix}}</span><span ng-class="nick.nameClasses">{{nick.name}}</span></a>
|
||||||
|
@ -268,7 +268,7 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
|
||||||
<div class="push"></div>
|
<div class="push"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="footer" ng-show="connected">
|
<div id="footer" ng-show="connected">
|
||||||
<div class="navbar navbar-inverse navbar-fixed-bottom" ng-class="{'withnicklist': nonicklist==false}">
|
<div class="navbar navbar-inverse navbar-fixed-bottom" ng-class="{'withnicklist': showNicklist}">
|
||||||
<form class="form form-horizontal" ng-submit="sendMessage()">
|
<form class="form form-horizontal" ng-submit="sendMessage()">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input id="sendMessage" type="text" class="form-control monospace" autocomplete="off" ng-model="command" autofocus>
|
<input id="sendMessage" type="text" class="form-control monospace" autocomplete="off" ng-model="command" autofocus>
|
||||||
|
|
27
js/models.js
27
js/models.js
|
@ -19,6 +19,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
var notify = 3 // Default 3 == message
|
var notify = 3 // Default 3 == message
|
||||||
var lines = []
|
var lines = []
|
||||||
var nicklist = {}
|
var nicklist = {}
|
||||||
|
var flatnicklist = []
|
||||||
var active = false
|
var active = false
|
||||||
var notification = 0
|
var notification = 0
|
||||||
var unread = 0
|
var unread = 0
|
||||||
|
@ -44,6 +45,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
*/
|
*/
|
||||||
var addNick = function(group, nick) {
|
var addNick = function(group, nick) {
|
||||||
nicklist[group].nicks.push(nick);
|
nicklist[group].nicks.push(nick);
|
||||||
|
flatnicklist = getFlatNicklist();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Deletes a nick from nicklist
|
* Deletes a nick from nicklist
|
||||||
|
@ -51,6 +53,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
var delNick = function(group, nick) {
|
var delNick = function(group, nick) {
|
||||||
var group = nicklist[group];
|
var group = nicklist[group];
|
||||||
group.nicks = _.filter(group.nicks, function(n) { return n.name != nick.name});
|
group.nicks = _.filter(group.nicks, function(n) { return n.name != nick.name});
|
||||||
|
flatnicklist = getFlatNicklist();
|
||||||
/*
|
/*
|
||||||
for(i in group.nicks) {
|
for(i in group.nicks) {
|
||||||
if(group.nicks[i].name == nick.name) {
|
if(group.nicks[i].name == nick.name) {
|
||||||
|
@ -71,8 +74,29 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
flatnicklist = getFlatNicklist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Maintain a cached version of a flat sorted nicklist
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
var getFlatNicklist = function() {
|
||||||
|
var newlist = [];
|
||||||
|
_.each(nicklist, function(nickGroup) {
|
||||||
|
_.each(nickGroup.nicks, function(nickObj) {
|
||||||
|
newlist.push(nickObj.name);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
newlist.sort(function(a, b) {
|
||||||
|
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
|
||||||
|
});
|
||||||
|
return newlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
var flatNicklist = function() {
|
||||||
|
return flatnicklist;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: pointer,
|
id: pointer,
|
||||||
|
@ -90,7 +114,8 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
nicklist: nicklist,
|
nicklist: nicklist,
|
||||||
addNick: addNick,
|
addNick: addNick,
|
||||||
delNick: delNick,
|
delNick: delNick,
|
||||||
updateNick: updateNick
|
updateNick: updateNick,
|
||||||
|
flatNicklist: flatNicklist
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
|
||||||
buffer.nicklist[group] = g;
|
buffer.nicklist[group] = g;
|
||||||
}else{
|
}else{
|
||||||
var nick = new models.Nick(n);
|
var nick = new models.Nick(n);
|
||||||
buffer.nicklist[group].nicks.push(nick);
|
buffer.addNick(group, nick);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -416,6 +416,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
|
|
||||||
// Clear search term on buffer change
|
// Clear search term on buffer change
|
||||||
$scope.search = '';
|
$scope.search = '';
|
||||||
|
|
||||||
|
// Check if we should show nicklist or not
|
||||||
|
$scope.showNicklist = $scope.updateShowNicklist();
|
||||||
});
|
});
|
||||||
$rootScope.$on('notificationChanged', function() {
|
$rootScope.$on('notificationChanged', function() {
|
||||||
var notifications = _.reduce(models.model.buffers, function(memo, num) { return (memo||0) + num.notification;});
|
var notifications = _.reduce(models.model.buffers, function(memo, num) { return (memo||0) + num.notification;});
|
||||||
|
@ -558,6 +561,30 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Watch model and update show setting when it changes
|
||||||
|
$scope.$watch('nonicklist', function() {
|
||||||
|
$scope.showNicklist = $scope.updateShowNicklist();
|
||||||
|
});
|
||||||
|
$scope.showNicklist = false;
|
||||||
|
// Utility function that template can use to check if nicklist should
|
||||||
|
// be displayed for current buffer or not
|
||||||
|
// is called on buffer switch
|
||||||
|
$scope.updateShowNicklist = function() {
|
||||||
|
var ab = models.getActiveBuffer();
|
||||||
|
if(!ab) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check if option no nicklist is set
|
||||||
|
if($scope.nonicklist) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Use flat nicklist to check if empty
|
||||||
|
if(ab.flatNicklist().length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$rootScope.switchToActivityBuffer = function() {
|
$rootScope.switchToActivityBuffer = function() {
|
||||||
// Find next buffer with activity and switch to it
|
// Find next buffer with activity and switch to it
|
||||||
for(i in $scope.buffers) {
|
for(i in $scope.buffers) {
|
||||||
|
@ -583,18 +610,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
var caretPos = inputNode.selectionStart;
|
var caretPos = inputNode.selectionStart;
|
||||||
|
|
||||||
// create flat array of nicks
|
// create flat array of nicks
|
||||||
// TODO: compute this elsewhere since it doesn't change often
|
|
||||||
var activeBuffer = models.getActiveBuffer();
|
var activeBuffer = models.getActiveBuffer();
|
||||||
var flatNickList = [];
|
|
||||||
_.each(activeBuffer.nicklist, function(nickGroup) {
|
|
||||||
_.each(nickGroup.nicks, function(nickObj) {
|
|
||||||
flatNickList.push(nickObj.name);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// complete nick
|
// complete nick
|
||||||
var nickComp = IrcUtils.completeNick(inputText, caretPos,
|
var nickComp = IrcUtils.completeNick(inputText, caretPos,
|
||||||
$rootScope.iterCandidate, flatNickList, ':');
|
$rootScope.iterCandidate, activeBuffer.flatNicklist(), ':');
|
||||||
|
|
||||||
// remember iteration candidate
|
// remember iteration candidate
|
||||||
$rootScope.iterCandidate = nickComp.iterCandidate;
|
$rootScope.iterCandidate = nickComp.iterCandidate;
|
||||||
|
|
Loading…
Reference in a new issue