Open query when clicking nick in the sidebar

This commit is contained in:
Lorenz H-S 2013-12-14 14:40:11 +00:00
parent 706b5838a1
commit 9368f2480d
3 changed files with 36 additions and 11 deletions

View File

@ -247,7 +247,7 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
<div id="nicklist" ng-show="showNicklist" 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:'name'"> <li class="" ng-repeat="nick in group.nicks|orderBy:'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" ng-click="openQuery(nick.name)">{{nick.name}}</span></a>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -323,12 +323,27 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
* Deactivates the previous current buffer. * Deactivates the previous current buffer.
* *
* @param bufferId id of the new active buffer * @param bufferId id of the new active buffer
* @return undefined * @return true on success, false if buffer was not found
*/ */
this.setActiveBuffer = function(bufferId) { this.setActiveBuffer = function(bufferId, key) {
if (typeof(key) === 'undefined') {
key = 'id';
}
var previousBuffer = this.getActiveBuffer(); var previousBuffer = this.getActiveBuffer();
activeBuffer = _.find(this.model['buffers'], function(buffer) {
if (buffer[key] == bufferId) {
return buffer;
}
});
if (typeof(activeBuffer) === 'undefined') {
// Buffer not found, undo assignment
activeBuffer = previousBuffer;
return false;
}
if (previousBuffer) { if (previousBuffer) {
// turn off the active status for the previous buffer // turn off the active status for the previous buffer
previousBuffer.active = false; previousBuffer.active = false;
@ -336,18 +351,13 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
previousBuffer.lastSeen = previousBuffer.lines.length-1; previousBuffer.lastSeen = previousBuffer.lines.length-1;
} }
activeBuffer = _.find(this.model['buffers'], function(buffer) {
if (buffer['id'] == bufferId) {
return buffer;
}
});
activeBuffer.active = true; activeBuffer.active = true;
activeBuffer.unread = 0; activeBuffer.unread = 0;
activeBuffer.notification = 0; activeBuffer.notification = 0;
$rootScope.$emit('activeBufferChanged'); $rootScope.$emit('activeBufferChanged');
$rootScope.$emit('notificationChanged'); $rootScope.$emit('notificationChanged');
return true;
} }
/* /*

View File

@ -63,6 +63,11 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
var bufferMessage = message['objects'][0]['content'][0]; var bufferMessage = message['objects'][0]['content'][0];
var buffer = new models.Buffer(bufferMessage); var buffer = new models.Buffer(bufferMessage);
models.addBuffer(buffer); models.addBuffer(buffer);
if ($rootScope.waitForQueryWindow === buffer.fullName) {
// We're waiting for a query window
models.setActiveBuffer(buffer.id);
$rootScope.waitForQueryWindow = "";
}
} }
var handleBufferTitleChanged = function(message) { var handleBufferTitleChanged = function(message) {
@ -540,10 +545,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number'; $rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number';
$scope.setActiveBuffer = function(key) { $scope.setActiveBuffer = function(bufferId, key) {
models.setActiveBuffer(key); return models.setActiveBuffer(bufferId, key);
}; };
$scope.openQuery = function(nick) {
var buffName = models.getActiveBuffer()['fullName'];
buffName = buffName.substring(0, buffName.lastIndexOf('.')) + '.' + nick;
if (!$scope.setActiveBuffer(buffName, 'fullName')) {
$rootScope.waitForQueryWindow = buffName;
connection.sendMessage('/query ' + nick);
}
}
$rootScope.scrollToBottom = function() { $rootScope.scrollToBottom = function() {
// FIXME doesn't work if the settimeout runs without a short delay // FIXME doesn't work if the settimeout runs without a short delay
var scroll = function() { var scroll = function() {