\r
// Event managers for plugins\r
components: {\r
- EventComponent: function(event_source) {\r
+ EventComponent: function(event_source, proxy_event_name) {\r
function proxyEvent(event_name, event_data) {\r
+ if (proxy_event_name !== 'all') {\r
+ event_data = event_name.event_data;\r
+ event_name = event_name.event_name\r
+ }\r
+//console.log(proxy_event_name, event_name, event_data);\r
this.trigger(event_name, event_data);\r
}\r
\r
+ // The event we are to proxy\r
+ proxy_event_name = proxy_event_name || 'all';\r
+\r
+\r
_.extend(this, Backbone.Events);\r
this._source = event_source;\r
\r
// Proxy the events to this dispatcher\r
- event_source.on('all', proxyEvent, this);\r
+ event_source.on(proxy_event_name, proxyEvent, this);\r
\r
// Clean up this object\r
this.dispose = function () {\r
- event_source.off('all', proxyEvent);\r
+ event_source.off(proxy_event_name, proxyEvent);\r
this.off();\r
delete this.event_source;\r
};\r
},\r
\r
- Network: function() {\r
- var obj = new this.EventComponent(_kiwi.gateway);\r
+ Network: function(connection_id) {\r
+ var connection_event;\r
+\r
+ if (typeof connection_id !== 'undefined') {\r
+ connection_event = 'connection:' + connection_id.toString();\r
+ }\r
+\r
+ var obj = new this.EventComponent(_kiwi.gateway, connection_event);\r
var funcs = {\r
kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic',\r
part: 'part', join: 'join', action: 'action', ctcp: 'ctcp',\r
__dirname + '/app.js',\r
__dirname + '/model_application.js',\r
__dirname + '/model_gateway.js',\r
+ __dirname + '/model_network.js',\r
__dirname + '/model_member.js',\r
__dirname + '/model_memberlist.js',\r
__dirname + '/model_panel.js',\r
\r
// Best guess at where the kiwi server is\r
this.detectKiwiServer();\r
+\r
+ // Holds instances of model_network\r
+ this.connections = [];\r
+\r
+ // The active network (reference to a this.connections element)\r
+ this.active_connection = null;\r
};\r
\r
this.start = function () {\r
this.view = new _kiwi.view.Application({model: this, el: this.get('container')});\r
\r
/**\r
- * Set the UI components up\r
+ * This is temporary.\r
+ * While multiple server support is being worked on,\r
+ * we will keep this single server variable here until\r
+ * It all gets moved over\r
*/\r
- this.panels = new _kiwi.model.PanelList();\r
+ _kiwi.app.connections[0] = new _kiwi.model.Network(0);\r
+ this.panels = _kiwi.app.connections[0].panels;\r
\r
+ /**\r
+ * Set the UI components up\r
+ */\r
this.controlbox = new _kiwi.view.ControlBox({el: $('#controlbox')[0]});\r
this.bindControllboxCommands(this.controlbox);\r
\r
\r
\r
this.bindGatewayCommands = function (gw) {\r
- gw.on('onmotd', function (event) {\r
- that.panels.server.addMsg(_kiwi.gateway.get('name'), event.msg, 'motd');\r
- });\r
-\r
-\r
gw.on('onconnect', function (event) {\r
that.view.barsShow();\r
- \r
+\r
if (auto_connect_details.channel) {\r
that.controlbox.processInput('/JOIN ' + auto_connect_details.channel + ' ' + auto_connect_details.channel_key);\r
}\r
});\r
})();\r
\r
-\r
- gw.on('onjoin', function (event) {\r
- var c, members, user;\r
- c = that.panels.getByName(event.channel);\r
- if (!c) {\r
- c = new _kiwi.model.Channel({name: event.channel});\r
- that.panels.add(c);\r
- }\r
-\r
- members = c.get('members');\r
- if (!members) return;\r
-\r
- user = new _kiwi.model.Member({nick: event.nick, ident: event.ident, hostname: event.hostname});\r
- members.add(user);\r
- // TODO: highlight the new channel in some way\r
- });\r
-\r
-\r
- gw.on('onpart', function (event) {\r
- var channel, members, user,\r
- part_options = {};\r
-\r
- part_options.type = 'part';\r
- part_options.message = event.message || '';\r
-\r
- channel = that.panels.getByName(event.channel);\r
- if (!channel) return;\r
-\r
- // If this is us, close the panel\r
- if (event.nick === _kiwi.gateway.get('nick')) {\r
- channel.close();\r
- return;\r
- }\r
-\r
- members = channel.get('members');\r
- if (!members) return;\r
-\r
- user = members.getByNick(event.nick);\r
- if (!user) return;\r
-\r
- members.remove(user, part_options);\r
- });\r
-\r
-\r
- gw.on('onquit', function (event) {\r
- var member, members,\r
- quit_options = {};\r
-\r
- quit_options.type = 'quit';\r
- quit_options.message = event.message || '';\r
-\r
- $.each(that.panels.models, function (index, panel) {\r
- if (!panel.isChannel()) return;\r
-\r
- member = panel.get('members').getByNick(event.nick);\r
- if (member) {\r
- panel.get('members').remove(member, quit_options);\r
- }\r
- });\r
- });\r
-\r
-\r
- gw.on('onkick', function (event) {\r
- var channel, members, user,\r
- part_options = {};\r
-\r
- part_options.type = 'kick';\r
- part_options.by = event.nick;\r
- part_options.message = event.message || '';\r
-\r
- channel = that.panels.getByName(event.channel);\r
- if (!channel) return;\r
-\r
- members = channel.get('members');\r
- if (!members) return;\r
-\r
- user = members.getByNick(event.kicked);\r
- if (!user) return;\r
-\r
- members.remove(user, part_options);\r
-\r
- if (event.kicked === _kiwi.gateway.get('nick')) {\r
- members.reset([]);\r
- }\r
- \r
- });\r
-\r
-\r
- gw.on('onmsg', function (event) {\r
- var panel,\r
- is_pm = (event.channel == _kiwi.gateway.get('nick'));\r
-\r
- // An ignored user? don't do anything with it\r
- if (gw.isNickIgnored(event.nick)) {\r
- return;\r
- }\r
-\r
- if (is_pm) {\r
- // If a panel isn't found for this PM, create one\r
- panel = that.panels.getByName(event.nick);\r
- if (!panel) {\r
- panel = new _kiwi.model.Query({name: event.nick});\r
- that.panels.add(panel);\r
- }\r
-\r
- } else {\r
- // If a panel isn't found for this channel, reroute to the\r
- // server panel\r
- panel = that.panels.getByName(event.channel);\r
- if (!panel) {\r
- panel = that.panels.server;\r
- }\r
- }\r
-\r
- panel.addMsg(event.nick, event.msg);\r
- });\r
-\r
-\r
- gw.on('onctcp_request', function (event) {\r
- // An ignored user? don't do anything with it\r
- if (gw.isNickIgnored(event.nick)) {\r
- return;\r
- }\r
-\r
- // Reply to a TIME ctcp\r
- if (event.msg.toUpperCase() === 'TIME') {\r
- gw.ctcp(false, event.type, event.nick, (new Date()).toString());\r
- }\r
- });\r
-\r
-\r
- gw.on('onctcp_response', function (event) {\r
- // An ignored user? don't do anything with it\r
- if (gw.isNickIgnored(event.nick)) {\r
- return;\r
- }\r
- \r
- that.panels.server.addMsg('[' + event.nick + ']', 'CTCP ' + event.msg);\r
- });\r
-\r
-\r
- gw.on('onnotice', function (event) {\r
- var panel;\r
-\r
- // An ignored user? don't do anything with it\r
- if (event.nick && gw.isNickIgnored(event.nick)) {\r
- return;\r
- }\r
-\r
- // Find a panel for the destination(channel) or who its from\r
- panel = that.panels.getByName(event.target) || that.panels.getByName(event.nick);\r
- if (!panel) {\r
- panel = that.panels.server;\r
- }\r
-\r
- panel.addMsg('[' + (event.nick||'') + ']', event.msg);\r
- });\r
-\r
-\r
- gw.on('onaction', function (event) {\r
- var panel,\r
- is_pm = (event.channel == _kiwi.gateway.get('nick'));\r
-\r
- // An ignored user? don't do anything with it\r
- if (gw.isNickIgnored(event.nick)) {\r
- return;\r
- }\r
-\r
- if (is_pm) {\r
- // If a panel isn't found for this PM, create one\r
- panel = that.panels.getByName(event.nick);\r
- if (!panel) {\r
- panel = new _kiwi.model.Channel({name: event.nick});\r
- that.panels.add(panel);\r
- }\r
-\r
- } else {\r
- // If a panel isn't found for this channel, reroute to the\r
- // server panel\r
- panel = that.panels.getByName(event.channel);\r
- if (!panel) {\r
- panel = that.panels.server;\r
- }\r
- }\r
-\r
- panel.addMsg('', '* ' + event.nick + ' ' + event.msg, 'action');\r
- });\r
-\r
-\r
- gw.on('ontopic', function (event) {\r
- var c;\r
- c = that.panels.getByName(event.channel);\r
- if (!c) return;\r
-\r
- // Set the channels topic\r
- c.set('topic', event.topic);\r
-\r
- // If this is the active channel, update the topic bar too\r
- if (c.get('name') === _kiwi.app.panels.active.get('name')) {\r
- that.topicbar.setCurrentTopic(event.topic);\r
- }\r
- });\r
-\r
-\r
- gw.on('ontopicsetby', function (event) {\r
- var c, when;\r
- c = that.panels.getByName(event.channel);\r
- if (!c) return;\r
-\r
- when = formatDate(new Date(event.when * 1000));\r
- c.addMsg('', 'Topic set by ' + event.nick + ' at ' + when, 'topic');\r
- });\r
-\r
-\r
- gw.on('onuserlist', function (event) {\r
- var channel;\r
- channel = that.panels.getByName(event.channel);\r
-\r
- // If we didn't find a channel for this, may aswell leave\r
- if (!channel) return;\r
-\r
- channel.temp_userlist = channel.temp_userlist || [];\r
- _.each(event.users, function (item) {\r
- var user = new _kiwi.model.Member({nick: item.nick, modes: item.modes});\r
- channel.temp_userlist.push(user);\r
- });\r
- });\r
-\r
-\r
- gw.on('onuserlist_end', function (event) {\r
- var channel;\r
- channel = that.panels.getByName(event.channel);\r
-\r
- // If we didn't find a channel for this, may aswell leave\r
- if (!channel) return;\r
-\r
- // Update the members list with the new list\r
- channel.get('members').reset(channel.temp_userlist || []);\r
-\r
- // Clear the temporary userlist\r
- delete channel.temp_userlist;\r
- });\r
-\r
-\r
- gw.on('onmode', function (event) {\r
- var channel, i, prefixes, members, member, find_prefix;\r
- \r
- // Build a nicely formatted string to be displayed to a regular human\r
- function friendlyModeString (event_modes, alt_target) {\r
- var modes = {}, return_string;\r
-\r
- // If no default given, use the main event info\r
- if (!event_modes) {\r
- event_modes = event.modes;\r
- alt_target = event.target;\r
- }\r
-\r
- // Reformat the mode object to make it easier to work with\r
- _.each(event_modes, function (mode){\r
- var param = mode.param || alt_target || '';\r
-\r
- // Make sure we have some modes for this param\r
- if (!modes[param]) {\r
- modes[param] = {'+':'', '-':''};\r
- }\r
-\r
- modes[param][mode.mode[0]] += mode.mode.substr(1);\r
- });\r
-\r
- // Put the string together from each mode\r
- return_string = [];\r
- _.each(modes, function (modeset, param) {\r
- var str = '';\r
- if (modeset['+']) str += '+' + modeset['+'];\r
- if (modeset['-']) str += '-' + modeset['-'];\r
- return_string.push(str + ' ' + param);\r
- });\r
- return_string = return_string.join(', ');\r
-\r
- return return_string;\r
- }\r
-\r
-\r
- channel = that.panels.getByName(event.target);\r
- if (channel) {\r
- prefixes = _kiwi.gateway.get('user_prefixes');\r
- find_prefix = function (p) {\r
- return event.modes[i].mode[1] === p.mode;\r
- };\r
- for (i = 0; i < event.modes.length; i++) {\r
- if (_.any(prefixes, find_prefix)) {\r
- if (!members) {\r
- members = channel.get('members');\r
- }\r
- member = members.getByNick(event.modes[i].param);\r
- if (!member) {\r
- console.log('MODE command recieved for unknown member %s on channel %s', event.modes[i].param, event.target);\r
- return;\r
- } else {\r
- if (event.modes[i].mode[0] === '+') {\r
- member.addMode(event.modes[i].mode[1]);\r
- } else if (event.modes[i].mode[0] === '-') {\r
- member.removeMode(event.modes[i].mode[1]);\r
- }\r
- members.sort();\r
- //channel.addMsg('', '== ' + event.nick + ' set mode ' + event.modes[i].mode + ' ' + event.modes[i].param, 'action mode');\r
- }\r
- } else {\r
- // Channel mode being set\r
- // TODO: Store this somewhere?\r
- //channel.addMsg('', 'CHANNEL === ' + event.nick + ' set mode ' + event.modes[i].mode + ' on ' + event.target, 'action mode');\r
- }\r
- }\r
-\r
- channel.addMsg('', '== ' + event.nick + ' sets mode ' + friendlyModeString(), 'action mode');\r
- } else {\r
- // This is probably a mode being set on us.\r
- if (event.target.toLowerCase() === _kiwi.gateway.get("nick").toLowerCase()) {\r
- that.panels.server.addMsg('', '== ' + event.nick + ' set mode ' + friendlyModeString(), 'action mode');\r
- } else {\r
- console.log('MODE command recieved for unknown target %s: ', event.target, event);\r
- }\r
- }\r
- });\r
-\r
-\r
- gw.on('onnick', function (event) {\r
- var member;\r
-\r
- $.each(that.panels.models, function (index, panel) {\r
- if (!panel.isChannel()) return;\r
-\r
- member = panel.get('members').getByNick(event.nick);\r
- if (member) {\r
- member.set('nick', event.newnick);\r
- panel.addMsg('', '== ' + event.nick + ' is now known as ' + event.newnick, 'action nick');\r
- }\r
- });\r
- });\r
-\r
-\r
- gw.on('onwhois', function (event) {\r
- /*globals secondsToTime */\r
- var logon_date, idle_time = '', panel;\r
-\r
- if (event.end) {\r
- return;\r
- }\r
-\r
- if (typeof event.idle !== 'undefined') {\r
- idle_time = secondsToTime(parseInt(event.idle, 10));\r
- idle_time = idle_time.h.toString().lpad(2, "0") + ':' + idle_time.m.toString().lpad(2, "0") + ':' + idle_time.s.toString().lpad(2, "0");\r
- }\r
-\r
- panel = _kiwi.app.panels.active;\r
- if (event.ident) {\r
- panel.addMsg(event.nick, event.nick + ' [' + event.nick + '!' + event.ident + '@' + event.host + '] * ' + event.msg, 'whois');\r
- } else if (event.chans) {\r
- panel.addMsg(event.nick, 'Channels: ' + event.chans, 'whois');\r
- } else if (event.irc_server) {\r
- panel.addMsg(event.nick, 'Connected to server: ' + event.irc_server, 'whois');\r
- } else if (event.msg) {\r
- panel.addMsg(event.nick, event.msg, 'whois');\r
- } else if (event.logon) {\r
- logon_date = new Date();\r
- logon_date.setTime(event.logon * 1000);\r
- logon_date = formatDate(logon_date);\r
-\r
- panel.addMsg(event.nick, 'idle for ' + idle_time + ', signed on ' + logon_date, 'whois');\r
- } else {\r
- panel.addMsg(event.nick, 'idle for ' + idle_time, 'whois');\r
- }\r
- });\r
-\r
- gw.on('onaway', function (event) {\r
- $.each(that.panels.models, function (index, panel) {\r
- if (!panel.isChannel()) return;\r
-\r
- member = panel.get('members').getByNick(event.nick);\r
- if (member) {\r
- member.set('away', !(!event.trailing));\r
- }\r
- });\r
- });\r
-\r
-\r
- gw.on('onlist_start', function (data) {\r
- if (_kiwi.app.channel_list) {\r
- _kiwi.app.channel_list.close();\r
- delete _kiwi.app.channel_list;\r
- }\r
-\r
- var panel = new _kiwi.model.Applet(),\r
- applet = new _kiwi.applets.Chanlist();\r
-\r
- panel.load(applet);\r
- \r
- _kiwi.app.panels.add(panel);\r
- panel.view.show();\r
- \r
- _kiwi.app.channel_list = applet;\r
- });\r
-\r
-\r
- gw.on('onlist_channel', function (data) {\r
- // TODO: Put this listener within the applet itself\r
- _kiwi.app.channel_list.addChannel(data.chans);\r
- });\r
-\r
-\r
- gw.on('onlist_end', function (data) {\r
- // TODO: Put this listener within the applet itself\r
- delete _kiwi.app.channel_list;\r
- });\r
-\r
-\r
- gw.on('onirc_error', function (data) {\r
- var panel, tmp;\r
-\r
- if (data.channel !== undefined && !(panel = _kiwi.app.panels.getByName(data.channel))) {\r
- panel = _kiwi.app.panels.server;\r
- }\r
-\r
- switch (data.error) {\r
- case 'banned_from_channel':\r
- panel.addMsg(' ', '== You are banned from ' + data.channel + '. ' + data.reason, 'status');\r
- _kiwi.app.message.text('You are banned from ' + data.channel + '. ' + data.reason);\r
- break;\r
- case 'bad_channel_key':\r
- panel.addMsg(' ', '== Bad channel key for ' + data.channel, 'status');\r
- _kiwi.app.message.text('Bad channel key or password for ' + data.channel);\r
- break;\r
- case 'invite_only_channel':\r
- panel.addMsg(' ', '== ' + data.channel + ' is invite only.', 'status');\r
- _kiwi.app.message.text(data.channel + ' is invite only');\r
- break;\r
- case 'channel_is_full':\r
- panel.addMsg(' ', '== ' + data.channel + ' is full.', 'status');\r
- _kiwi.app.message.text(data.channel + ' is full');\r
- break;\r
- case 'chanop_privs_needed':\r
- panel.addMsg(' ', '== ' + data.reason, 'status');\r
- _kiwi.app.message.text(data.reason + ' (' + data.channel + ')');\r
- break;\r
- case 'no_such_nick':\r
- tmp = _kiwi.app.panels.getByName(data.nick);\r
- if (tmp) {\r
- tmp.addMsg(' ', '== ' + data.nick + ': ' + data.reason, 'status');\r
- } else {\r
- _kiwi.app.panels.server.addMsg(' ', '== ' + data.nick + ': ' + data.reason, 'status');\r
- }\r
- break;\r
- case 'nickname_in_use':\r
- _kiwi.app.panels.server.addMsg(' ', '== The nickname ' + data.nick + ' is already in use. Please select a new nickname', 'status');\r
- if (_kiwi.app.panels.server !== _kiwi.app.panels.active) {\r
- _kiwi.app.message.text('The nickname "' + data.nick + '" is already in use. Please select a new nickname');\r
- }\r
-\r
- // Only show the nickchange component if the controlbox is open\r
- if (that.controlbox.$el.css('display') !== 'none') {\r
- (new _kiwi.view.NickChangeBox()).render();\r
- }\r
-\r
- case 'password_mismatch':\r
- _kiwi.app.panels.server.addMsg(' ', '== Incorrect password given', 'status');\r
- break;\r
- default:\r
- // We don't know what data contains, so don't do anything with it.\r
- //_kiwi.front.tabviews.server.addMsg(null, ' ', '== ' + data, 'status');\r
- }\r
- });\r
};\r
\r
\r
*/\r
this.parse = function (command, data) {\r
//console.log('gateway event', command, data);\r
+\r
if (command !== undefined) {\r
that.trigger('on' + command, data);\r
\r
break;\r
\r
case 'connect':\r
+ //if (!_kiwi.app.connections[data.server]) {\r
+ // _kiwi.app.connections[data.server] = new _kiwi.model.Network(data.server);\r
+ //}\r
that.set('nick', data.nick);\r
break;\r
\r
break;\r
}\r
}\r
+\r
+\r
+ if (typeof data.server !== 'undefined') {\r
+ that.trigger('connection:' + data.server.toString(), {\r
+ event_name: command,\r
+ event_data: data\r
+ });\r
+ }\r
};\r
\r
/**\r
--- /dev/null
+(function () {
+
+ _kiwi.model.Network = Backbone.Model.extend({
+ defaults: {
+ connection_id: 0,
+ /**
+ * The name of the network
+ * @type String
+ */
+ name: 'Network',
+
+ /**
+ * The address (URL) of the network
+ * @type String
+ */
+ address: '',
+
+ /**
+ * The current nickname
+ * @type String
+ */
+ nick: '',
+
+ /**
+ * The channel prefix for this network
+ * @type String
+ */
+ channel_prefix: '#',
+
+ /**
+ * The user prefixes for channel owner/admin/op/voice etc. on this network
+ * @type Array
+ */
+ user_prefixes: ['~', '&', '@', '+']
+ },
+
+
+ initialize: function () {
+ this.gateway = _kiwi.global.components.Network(this.get('connection_id'));
+ this.bindGatewayEvents();
+
+ this.panels = new _kiwi.model.PanelList();
+ },
+
+
+ bindGatewayEvents: function () {
+ //this.gateway.on('all', function() {console.log('ALL', arguments);});
+
+ this.gateway.on('connect', function(event) {
+ this.set('nick', event.nick);
+ }, this);
+
+ this.gateway.on('nick', function(event) {
+ if (event.nick === event.get('nick')) {
+ this.set('nick', event.newnick);
+ }
+ }, this);
+
+ this.gateway.on('options', onOptions, this);
+ this.gateway.on('motd', onMotd, this);
+ this.gateway.on('join', onJoin, this);
+ this.gateway.on('part', onPart, this);
+ this.gateway.on('quit', onQuit, this);
+ this.gateway.on('kick', onKick, this);
+ this.gateway.on('msg', onMsg, this);
+ this.gateway.on('ctcp_request', onCtcpRequest, this);
+ this.gateway.on('ctcp_response', onCtcpResponse, this);
+ this.gateway.on('notice', onNotice, this);
+ this.gateway.on('action', onAction, this);
+ this.gateway.on('topic', onTopic, this);
+ this.gateway.on('topicsetby', onTopicSetBy, this);
+ this.gateway.on('userlist', onUserlist, this);
+ this.gateway.on('userlist_end', onUserlistEnd, this);
+ this.gateway.on('mode', onMode, this);
+ this.gateway.on('whois', onWhois, this);
+ this.gateway.on('away', onAway, this);
+ this.gateway.on('list_start', onListStart, this);
+ this.gateway.on('list_channel', onListChannel, this);
+ this.gateway.on('list_end', onListEnd, this);
+ }
+ });
+
+
+
+ function onOptions(event) {
+ var that = this;
+
+ $.each(event.options, function (name, value) {
+ switch (name) {
+ case 'CHANTYPES':
+ that.set('channel_prefix', value.join(''));
+ break;
+ case 'NETWORK':
+ that.set('name', value);
+ break;
+ case 'PREFIX':
+ that.set('user_prefixes', value);
+ break;
+ }
+ });
+
+ this.set('cap', event.cap);
+ }
+
+
+
+ function onMotd(event) {
+ this.panels.server.addMsg(this.get('name'), event.msg, 'motd');
+ }
+
+
+
+ function onJoin(event) {
+ var c, members, user;
+ c = this.panels.getByName(event.channel);
+ if (!c) {
+ c = new _kiwi.model.Channel({name: event.channel});
+ this.panels.add(c);
+ }
+
+ members = c.get('members');
+ if (!members) return;
+
+ user = new _kiwi.model.Member({nick: event.nick, ident: event.ident, hostname: event.hostname});
+ members.add(user);
+ }
+
+
+
+ function onPart(event) {
+ var channel, members, user,
+ part_options = {};
+
+ part_options.type = 'part';
+ part_options.message = event.message || '';
+
+ channel = this.panels.getByName(event.channel);
+ if (!channel) return;
+
+ // If this is us, close the panel
+ if (event.nick === this.get('nick')) {
+ channel.close();
+ return;
+ }
+
+ members = channel.get('members');
+ if (!members) return;
+
+ user = members.getByNick(event.nick);
+ if (!user) return;
+
+ members.remove(user, part_options);
+ }
+
+
+
+ function onQuit(event) {
+ var member, members,
+ quit_options = {};
+
+ quit_options.type = 'quit';
+ quit_options.message = event.message || '';
+
+ $.each(this.panels.models, function (index, panel) {
+ if (!panel.isChannel()) return;
+
+ member = panel.get('members').getByNick(event.nick);
+ if (member) {
+ panel.get('members').remove(member, quit_options);
+ }
+ });
+ }
+
+
+
+ function onKick(event) {
+ var channel, members, user,
+ part_options = {};
+
+ part_options.type = 'kick';
+ part_options.by = event.nick;
+ part_options.message = event.message || '';
+
+ channel = this.panels.getByName(event.channel);
+ if (!channel) return;
+
+ members = channel.get('members');
+ if (!members) return;
+
+ user = members.getByNick(event.kicked);
+ if (!user) return;
+
+ members.remove(user, part_options);
+
+ if (event.kicked === this.get('nick')) {
+ members.reset([]);
+ }
+ }
+
+
+
+ function onMsg(event) {
+ var panel,
+ is_pm = (event.channel == this.get('nick'));
+
+ // An ignored user? don't do anything with it
+ if (_kiwi.gateway.isNickIgnored(event.nick)) {
+ return;
+ }
+
+ if (is_pm) {
+ // If a panel isn't found for this PM, create one
+ panel = this.panels.getByName(event.nick);
+ if (!panel) {
+ panel = new _kiwi.model.Query({name: event.nick});
+ this.panels.add(panel);
+ }
+
+ } else {
+ // If a panel isn't found for this channel, reroute to the
+ // server panel
+ panel = this.panels.getByName(event.channel);
+ if (!panel) {
+ panel = this.panels.server;
+ }
+ }
+
+ panel.addMsg(event.nick, event.msg);
+ }
+
+
+
+ function onCtcpRequest(event) {
+ // An ignored user? don't do anything with it
+ if (_kiwi.gateway.isNickIgnored(event.nick)) {
+ return;
+ }
+
+ // Reply to a TIME ctcp
+ if (event.msg.toUpperCase() === 'TIME') {
+ this.gateway.ctcp(false, event.type, event.nick, (new Date()).toString());
+ }
+ }
+
+
+
+ function onCtcpResponse(event) {
+ // An ignored user? don't do anything with it
+ if (_kiwi.gateway.isNickIgnored(event.nick)) {
+ return;
+ }
+
+ this.panels.server.addMsg('[' + event.nick + ']', 'CTCP ' + event.msg);
+ }
+
+
+
+ function onNotice(event) {
+ var panel;
+
+ // An ignored user? don't do anything with it
+ if (event.nick && _kiwi.gateway.isNickIgnored(event.nick)) {
+ return;
+ }
+
+ // Find a panel for the destination(channel) or who its from
+ panel = this.panels.getByName(event.target) || this.panels.getByName(event.nick);
+ if (!panel) {
+ panel = this.panels.server;
+ }
+
+ panel.addMsg('[' + (event.nick||'') + ']', event.msg);
+ }
+
+
+
+ function onAction(event) {
+ var panel,
+ is_pm = (event.channel == this.get('nick'));
+
+ // An ignored user? don't do anything with it
+ if (_kiwi.gateway.isNickIgnored(event.nick)) {
+ return;
+ }
+
+ if (is_pm) {
+ // If a panel isn't found for this PM, create one
+ panel = this.panels.getByName(event.nick);
+ if (!panel) {
+ panel = new _kiwi.model.Channel({name: event.nick});
+ this.panels.add(panel);
+ }
+
+ } else {
+ // If a panel isn't found for this channel, reroute to the
+ // server panel
+ panel = this.panels.getByName(event.channel);
+ if (!panel) {
+ panel = this.panels.server;
+ }
+ }
+
+ panel.addMsg('', '* ' + event.nick + ' ' + event.msg, 'action');
+ }
+
+
+
+ function onTopic(event) {
+ var c;
+ c = this.panels.getByName(event.channel);
+ if (!c) return;
+
+ // Set the channels topic
+ c.set('topic', event.topic);
+
+ // If this is the active channel, update the topic bar too
+ if (c.get('name') === this.panels.active.get('name')) {
+ _kiwi.app.topicbar.setCurrentTopic(event.topic);
+ }
+ }
+
+
+
+ function onTopicSetBy(event) {
+ var c, when;
+ c = this.panels.getByName(event.channel);
+ if (!c) return;
+
+ when = formatDate(new Date(event.when * 1000));
+ c.addMsg('', 'Topic set by ' + event.nick + ' at ' + when, 'topic');
+ }
+
+
+
+ function onUserlist(event) {
+ var channel;
+ channel = this.panels.getByName(event.channel);
+
+ // If we didn't find a channel for this, may aswell leave
+ if (!channel) return;
+
+ channel.temp_userlist = channel.temp_userlist || [];
+ _.each(event.users, function (item) {
+ var user = new _kiwi.model.Member({nick: item.nick, modes: item.modes});
+ channel.temp_userlist.push(user);
+ });
+ }
+
+
+
+ function onUserlistEnd(event) {
+ var channel;
+ channel = this.panels.getByName(event.channel);
+
+ // If we didn't find a channel for this, may aswell leave
+ if (!channel) return;
+
+ // Update the members list with the new list
+ channel.get('members').reset(channel.temp_userlist || []);
+
+ // Clear the temporary userlist
+ delete channel.temp_userlist;
+ }
+
+
+
+ function onMode(event) {
+ var channel, i, prefixes, members, member, find_prefix;
+
+ // Build a nicely formatted string to be displayed to a regular human
+ function friendlyModeString (event_modes, alt_target) {
+ var modes = {}, return_string;
+
+ // If no default given, use the main event info
+ if (!event_modes) {
+ event_modes = event.modes;
+ alt_target = event.target;
+ }
+
+ // Reformat the mode object to make it easier to work with
+ _.each(event_modes, function (mode){
+ var param = mode.param || alt_target || '';
+
+ // Make sure we have some modes for this param
+ if (!modes[param]) {
+ modes[param] = {'+':'', '-':''};
+ }
+
+ modes[param][mode.mode[0]] += mode.mode.substr(1);
+ });
+
+ // Put the string together from each mode
+ return_string = [];
+ _.each(modes, function (modeset, param) {
+ var str = '';
+ if (modeset['+']) str += '+' + modeset['+'];
+ if (modeset['-']) str += '-' + modeset['-'];
+ return_string.push(str + ' ' + param);
+ });
+ return_string = return_string.join(', ');
+
+ return return_string;
+ }
+
+
+ channel = this.panels.getByName(event.target);
+ if (channel) {
+ prefixes = this.get('user_prefixes');
+ find_prefix = function (p) {
+ return event.modes[i].mode[1] === p.mode;
+ };
+ for (i = 0; i < event.modes.length; i++) {
+ if (_.any(prefixes, find_prefix)) {
+ if (!members) {
+ members = channel.get('members');
+ }
+ member = members.getByNick(event.modes[i].param);
+ if (!member) {
+ console.log('MODE command recieved for unknown member %s on channel %s', event.modes[i].param, event.target);
+ return;
+ } else {
+ if (event.modes[i].mode[0] === '+') {
+ member.addMode(event.modes[i].mode[1]);
+ } else if (event.modes[i].mode[0] === '-') {
+ member.removeMode(event.modes[i].mode[1]);
+ }
+ members.sort();
+ //channel.addMsg('', '== ' + event.nick + ' set mode ' + event.modes[i].mode + ' ' + event.modes[i].param, 'action mode');
+ }
+ } else {
+ // Channel mode being set
+ // TODO: Store this somewhere?
+ //channel.addMsg('', 'CHANNEL === ' + event.nick + ' set mode ' + event.modes[i].mode + ' on ' + event.target, 'action mode');
+ }
+ }
+
+ channel.addMsg('', '== ' + event.nick + ' sets mode ' + friendlyModeString(), 'action mode');
+ } else {
+ // This is probably a mode being set on us.
+ if (event.target.toLowerCase() === this.get("nick").toLowerCase()) {
+ this.panels.server.addMsg('', '== ' + event.nick + ' set mode ' + friendlyModeString(), 'action mode');
+ } else {
+ console.log('MODE command recieved for unknown target %s: ', event.target, event);
+ }
+ }
+ }
+
+
+
+ function onWhois(event) {
+ var logon_date, idle_time = '', panel;
+
+ if (event.end)
+ return;
+
+ if (typeof event.idle !== 'undefined') {
+ idle_time = secondsToTime(parseInt(event.idle, 10));
+ idle_time = idle_time.h.toString().lpad(2, "0") + ':' + idle_time.m.toString().lpad(2, "0") + ':' + idle_time.s.toString().lpad(2, "0");
+ }
+
+ panel = _kiwi.app.panels.active;
+ if (event.ident) {
+ panel.addMsg(event.nick, event.nick + ' [' + event.nick + '!' + event.ident + '@' + event.host + '] * ' + event.msg, 'whois');
+ } else if (event.chans) {
+ panel.addMsg(event.nick, 'Channels: ' + event.chans, 'whois');
+ } else if (event.irc_server) {
+ panel.addMsg(event.nick, 'Connected to server: ' + event.irc_server, 'whois');
+ } else if (event.msg) {
+ panel.addMsg(event.nick, event.msg, 'whois');
+ } else if (event.logon) {
+ logon_date = new Date();
+ logon_date.setTime(event.logon * 1000);
+ logon_date = formatDate(logon_date);
+
+ panel.addMsg(event.nick, 'idle for ' + idle_time + ', signed on ' + logon_date, 'whois');
+ } else {
+ panel.addMsg(event.nick, 'idle for ' + idle_time, 'whois');
+ }
+ }
+
+
+
+ function onAway(event) {
+ $.each(this.panels.models, function (index, panel) {
+ if (!panel.isChannel()) return;
+
+ member = panel.get('members').getByNick(event.nick);
+ if (member) {
+ member.set('away', !(!event.trailing));
+ }
+ });
+ }
+
+
+
+ function onListStart(event) {
+ if (_kiwi.app.channel_list) {
+ _kiwi.app.channel_list.close();
+ delete _kiwi.app.channel_list;
+ }
+
+ var panel = new _kiwi.model.Applet(),
+ applet = new _kiwi.applets.Chanlist();
+
+ panel.load(applet);
+
+ _kiwi.app.panels.add(panel);
+ panel.view.show();
+
+ _kiwi.app.channel_list = applet;
+ }
+
+
+
+ function onListChannel(event) {
+ // TODO: Put this listener within the applet itself
+ _kiwi.app.channel_list.addChannel(event.chans);
+ }
+
+
+
+ function onListEnd(event) {
+ // TODO: Put this listener within the applet itself
+ delete _kiwi.app.channel_list;
+ }
+
+
+
+ function onIrcError(event) {
+ var panel, tmp;
+
+ if (event.channel !== undefined && !(panel = _kiwi.app.panels.getByName(event.channel))) {
+ panel = this.panels.server;
+ }
+
+ switch (event.error) {
+ case 'banned_from_channel':
+ panel.addMsg(' ', '== You are banned from ' + event.channel + '. ' + event.reason, 'status');
+ _kiwi.app.message.text('You are banned from ' + event.channel + '. ' + event.reason);
+ break;
+ case 'bad_channel_key':
+ panel.addMsg(' ', '== Bad channel key for ' + event.channel, 'status');
+ _kiwi.app.message.text('Bad channel key or password for ' + event.channel);
+ break;
+ case 'invite_only_channel':
+ panel.addMsg(' ', '== ' + event.channel + ' is invite only.', 'status');
+ _kiwi.app.message.text(event.channel + ' is invite only');
+ break;
+ case 'channel_is_full':
+ panel.addMsg(' ', '== ' + event.channel + ' is full.', 'status');
+ _kiwi.app.message.text(event.channel + ' is full');
+ break;
+ case 'chanop_privs_needed':
+ panel.addMsg(' ', '== ' + event.reason, 'status');
+ _kiwi.app.message.text(event.reason + ' (' + event.channel + ')');
+ break;
+ case 'no_such_nick':
+ tmp = this.panels.getByName(event.nick);
+ if (tmp) {
+ tmp.addMsg(' ', '== ' + event.nick + ': ' + event.reason, 'status');
+ } else {
+ this.panels.server.addMsg(' ', '== ' + event.nick + ': ' + event.reason, 'status');
+ }
+ break;
+ case 'nickname_in_use':
+ this.panels.server.addMsg(' ', '== The nickname ' + event.nick + ' is already in use. Please select a new nickname', 'status');
+ if (this.panels.server !== thia.panels.active) {
+ _kiwi.app.message.text('The nickname "' + event.nick + '" is already in use. Please select a new nickname');
+ }
+
+ // Only show the nickchange component if the controlbox is open
+ if (that.controlbox.$el.css('display') !== 'none') {
+ (new _kiwi.view.NickChangeBox()).render();
+ }
+
+ break;
+
+ case 'password_mismatch':
+ this.panels.server.addMsg(' ', '== Incorrect password given', 'status');
+ break;
+ default:
+ // We don't know what data contains, so don't do anything with it.
+ //_kiwi.front.tabviews.server.addMsg(null, ' ', '== ' + data, 'status');
+ }
+ }
+}
+
+)();
\ No newline at end of file
model: _kiwi.model.Panel,\r
\r
comparator: function (chan) {\r
- return chan.get("name");\r
+ return chan.get('name');\r
},\r
initialize: function () {\r
- this.view = new _kiwi.view.Tabs({"el": $('#tabs')[0], "model": this});\r
+ this.view = new _kiwi.view.Tabs({el: $('#tabs')[0], model: this});\r
\r
// Automatically create a server tab\r
- this.add(new _kiwi.model.Server({'name': _kiwi.gateway.get('name')}));\r
- this.server = this.getByName(_kiwi.gateway.get('name'));\r
+ var server_panel = new _kiwi.model.Server({name: 'Server'});\r
+\r
+ this.add(server_panel);\r
+ this.server = server_panel;\r
\r
// Holds the active panel\r
this.active = null;\r
}, this);\r
\r
},\r
+\r
+\r
+\r
getByName: function (name) {\r
if (typeof name !== 'string') return;\r
+\r
return this.find(function (c) {\r
return name.toLowerCase() === c.get('name').toLowerCase();\r
});\r