From 404f8c8cba9072fc5b9629bc5d8adf0bc18fffc8 Mon Sep 17 00:00:00 2001 From: Tor Hveem <tor@hveem.no> Date: Sat, 26 Oct 2013 22:19:13 +0200 Subject: [PATCH] Implement nicklist --- css/glowingbear.css | 17 +++++++++++--- index.html | 9 +++++++- js/models.js | 40 +++++++++++++++++++++++++++++++++ js/websockets.js | 54 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/css/glowingbear.css b/css/glowingbear.css index 22fccc9..05ecc80 100644 --- a/css/glowingbear.css +++ b/css/glowingbear.css @@ -169,6 +169,16 @@ input[type=text], input[type=password], .badge { border-radius: 0; margin-right: -15px; } +#nicklist { + position: fixed; + width: 100px; + min-height: 100%; + height: 100%; + overflow-y: auto; + right: 0; + top: 0; + padding-top: 35px; /* topbar */ + } .nav-pills > li > a { border-radius: 0; color: #ddd; @@ -186,7 +196,8 @@ input[type=text], input[type=password], .badge { position: relative; height: 99%; overflow-y: auto; - margin-left: 14%; + margin-left: 14%; /* sidebar */ + margin-right: 100px; /* nicklist */ width: auto; top: 25px; /* topbar */ padding-bottom: 10px; @@ -202,7 +213,7 @@ input[type=text], input[type=password], .badge { background-color: #181818; } @media (max-width: 968px) { - #sidebar, #bufferlines { + #sidebar, #bufferlines, #nicklist { position: relative; min-height: 0; margin-left: 0; @@ -210,7 +221,7 @@ input[type=text], input[type=password], .badge { max-width: 100%; border: 0; } - #sidebar { + #sidebar, #nicklist { width: 100%; text-align: center; } diff --git a/index.html b/index.html index bed3b9f..b94c537 100644 --- a/index.html +++ b/index.html @@ -213,7 +213,14 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel </li> </ul> </div> - <div id="bufferlines"> + <div id="nicklist" class=""> + <ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist | toArray"> + <li class="" ng-repeat="nick in group.nicks"> + <a ng-click="nickAction(nick)"><span ng-class="nick.prefix_color">{{nick.prefix}}</span><span ng-class="color">{{nick.name}}</span></a> + </li> + </ul> + </div> + <div id="bufferlines" class="vertical-line"> <table> <tbody> <tr class="bufferline" ng-repeat-start="bufferline in (bufferlines = activeBuffer().lines)"> diff --git a/js/models.js b/js/models.js index dc722f4..c44823c 100644 --- a/js/models.js +++ b/js/models.js @@ -18,6 +18,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) var local_variables = message['local_vars']; var notify = 3 // Default 3 == message var lines = [] + var nicklist = {} var active = false var notification = 0 var unread = 0 @@ -38,6 +39,12 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) lines.push(line); } + /* + * Adds a nick to nicklist + */ + var addNick = function(nick) { + } + return { id: pointer, fullName: fullName, @@ -51,6 +58,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) notification: notification, localvars: local_variables, notify: notify, + nicklist: nicklist } } @@ -129,7 +137,39 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) } } + /* + * Nick class + */ + this.Nick = function(message) { + var prefix = message['prefix']; + var visible = message['visible']; + var name = message['name']; + var prefix_color = message['prefix_color']; + var color = message['color']; + return { + prefix: prefix, + visible: visible, + name: name, + prefix_color: prefix_color, + color: color + } + } + /* + * Nicklist Group class + */ + this.NickGroup = function(message) { + var name = message['name']; + var visible = message['visible']; + var nicks = []; + + return { + name: name, + visible: visible, + nicks: nicks + } + } + var BufferList = [] activeBuffer = null; diff --git a/js/websockets.js b/js/websockets.js index 5a515bd..573f180 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -114,6 +114,47 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc }); } + /* + * Handle nicklist event + */ + var handleNicklist = function(message) { + var nicklist = message['objects'][0]['content']; + var group = 'root'; + nicklist.forEach(function(n) { + var buffer = models.getBuffer(n.pointers[0]); + if(n.group == 1) { + var g = new models.NickGroup(n); + group = g.name; + buffer.nicklist[group] = g; + }else{ + var nick = new models.Nick(n); + buffer.nicklist[group].nicks.push(nick); + } + }); + } + /* + * Handle nicklist diff event + */ + var handleNicklistDiff = function(message) { + var nicklist = message['objects'][0]['content']; + var group; + nicklist.forEach(function(n) { + var buffer = models.getBuffer(n.pointers[0]); + var d = n['_diff']; + if(n.group == 1) { + group = buffer.nicklist[n.name]; + } + if(d == 43) { // + + var nick = new models.Nick(n); + buffer.nicklist[group].nicks.push(nick); + }else if (d == 45) { // - + var nick = new models.Nick(n); + }else if (d == 42) { // * + var nick = new models.Nick(n); + } + }); + } + var handleEvent = function(event) { if (_.has(eventHandlers, event['id'])) { @@ -127,13 +168,16 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc _buffer_line_added: handleBufferLineAdded, _buffer_opened: handleBufferOpened, _buffer_title_changed: handleBufferTitleChanged, - _buffer_renamed: handleBufferRenamed + _buffer_renamed: handleBufferRenamed, + _nicklist: handleNicklist, + _nicklist_diff: handleNicklistDiff } return { handleEvent: handleEvent, handleLineInfo: handleLineInfo, - handleHotlistInfo: handleHotlistInfo + handleHotlistInfo: handleHotlistInfo, + handleNicklist: handleNicklist } }]); @@ -237,6 +281,12 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers', })).then(function(hdata) { handlers.handleHotlistInfo(hdata) }); + }).then(function() { + $log.info("Requesting nicklist"); + doSendWithCallback(weeChat.Protocol.formatNicklist({ + })).then(function(nicklistdata) { + handlers.handleNicklist(nicklistdata) + }); }).then(function() { doSend(weeChat.Protocol.formatSync({})); $log.info("Synced");