From a9b1c5d6e4d27b7e72c96338200abf90d0e4a757 Mon Sep 17 00:00:00 2001 From: Darren Date: Tue, 12 Aug 2014 14:14:30 +0100 Subject: [PATCH] Network components get/set --- client/src/app.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/client/src/app.js b/client/src/app.js index add00f1..afc76a0 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -94,22 +94,36 @@ _kiwi.global = { Network: function(connection_id) { var connection_event; + // If no connection id given, use all connections if (typeof connection_id !== 'undefined') { connection_event = 'connection:' + connection_id.toString(); } else { connection_event = 'connection'; } + // Helper to get the network object + var getNetwork = function() { + var network = typeof connection_id === 'undefined' ? + _kiwi.app.connections.active_connection : + _kiwi.app.connections.getByConnectionId(connection_id); + + return network ? + network : + undefined; + }; + + // Create the return object (events proxy from the gateway) var obj = new this.EventComponent(_kiwi.gateway, connection_event); + + // Proxy several gateway functions onto the return object var funcs = { kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic', part: 'part', join: 'join', action: 'action', ctcp: 'ctcp', ctcpRequest: 'ctcpRequest', ctcpResponse: 'ctcpResponse', notice: 'notice', msg: 'privmsg', changeNick: 'changeNick', - channelInfo: 'channelInfo', mode: 'mode', quit: 'quit' + channelInfo: 'channelInfo', mode: 'mode', quit: 'quit', }; - // Proxy each gateway method _.each(funcs, function(gateway_fn, func_name) { obj[func_name] = function() { var fn_name = gateway_fn; @@ -123,6 +137,25 @@ _kiwi.global = { }; }); + // Add the networks getters/setters + obj.get = function() { + var network = getNetwork(); + if (!network) { + return; + } + + return network.get.apply(network, arguments); + }; + + obj.set = function() { + var network = getNetwork(); + if (!network) { + return; + } + + return network.set.apply(network, arguments); + }; + return obj; }, -- 2.25.1