From 902f344d252c41918eade0c6071efa1c5145a8c0 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Sun, 27 Oct 2013 00:26:17 +0200 Subject: [PATCH] move logic into models, attempt at sorting --- index.html | 4 ++-- js/models.js | 36 ++++++++++++++++++++++++++++++++++-- js/websockets.js | 27 +++++++++------------------ 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index a8cf746..319e62b 100644 --- a/index.html +++ b/index.html @@ -225,8 +225,8 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
-
    -
  • + diff --git a/js/models.js b/js/models.js index cae12fa..9d0073c 100644 --- a/js/models.js +++ b/js/models.js @@ -42,8 +42,37 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) /* * Adds a nick to nicklist */ - var addNick = function(nick) { + var addNick = function(group, nick) { + nicklist[group].nicks.push(nick); } + /* + * Deletes a nick from nicklist + */ + var delNick = function(group, nick) { + var group = nicklist[group]; + group.nicks = _.filter(group.nicks, function(n) { return n.name != nick.name}); + /* + for(i in group.nicks) { + if(group.nicks[i].name == nick.name) { + delete group.nicks[i]; + break; + } + } + */ + } + /* + * Updates a nick in nicklist + */ + var updateNick = function(group, nick) { + var group = nicklist[group]; + for(i in group.nicks) { + if(group.nicks[i].name == nick.name) { + group.nicks[i] = nick; + break; + } + } + } + return { id: pointer, @@ -58,7 +87,10 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) notification: notification, localvars: local_variables, notify: notify, - nicklist: nicklist + nicklist: nicklist, + addNick: addNick, + delNick: delNick, + updateNick: updateNick } } diff --git a/js/websockets.js b/js/websockets.js index 183db35..8df5c4e 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -142,30 +142,21 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc var buffer = models.getBuffer(n.pointers[0]); var d = n['_diff']; if(n.group == 1) { - group = buffer.nicklist[n.name]; + group = n.name; if(group==undefined) { var g = new models.NickGroup(n); buffer.nicklist[group] = g; - group = buffer.nicklist[g.name]; + group = g.name; } } - if(d == 43) { // + + else { var nick = new models.Nick(n); - group.nicks.push(nick); - }else if (d == 45) { // - - for(i in group.nicks) { - if(group.nicks[i].name == n.name) { - delete group.nicks[i]; - break; - } - } - }else if (d == 42) { // * - var nick = new models.Nick(n); - for(i in group.nicks) { - if(group.nicks[i].name == n.name) { - group.nicks[i] = n; - break; - } + if(d == 43) { // + + buffer.addNick(group, nick); + }else if (d == 45) { // - + buffer.delNick(group, nick); + }else if (d == 42) { // * + buffer.updateNick(group, nick); } } });