//this.gateway.on('all', function() {console.log('ALL', this.get('connection_id'), arguments);});
this.gateway.on('connect', onConnect, this);
+ this.gateway.on('disconnect', onDisconnect, this);
this.gateway.on('nick', function(event) {
if (event.nick === this.get('nick')) {
this.gateway.on('quit', onQuit, this);
this.gateway.on('kick', onKick, this);
this.gateway.on('msg', onMsg, this);
+ this.gateway.on('nick', onNick, this);
this.gateway.on('ctcp_request', onCtcpRequest, this);
this.gateway.on('ctcp_response', onCtcpResponse, this);
this.gateway.on('notice', onNotice, this);
this.gateway.on('whois', onWhois, this);
this.gateway.on('away', onAway, this);
this.gateway.on('list_start', onListStart, this);
+ },
+
+
+ /**
+ * Create panels and join the channel
+ * This will not wait for the join event to create a panel. This
+ * increases responsiveness in case of network lag
+ */
+ createAndJoinChannels: function (channels) {
+ var that = this,
+ panels = [];
+
+ // Multiple channels may come as comma-delimited
+ if (typeof channels === 'string') {
+ channels = channels.split(',');
+ }
+
+ $.each(channels, function (index, channel_name_key) {
+ // We may have a channel key so split it off
+ var spli = channel_name_key.trim().split(' '),
+ channel_name = spli[0],
+ channel_key = spli[1] || '';
+
+ // Trim any whitespace off the name
+ channel_name = channel_name.trim();
+
+ // If not a valid channel name, display a warning
+ if (!_kiwi.app.isChannelName(channel_name)) {
+ that.panels.server.addMsg('', channel_name + ' is not a valid channel name');
+ _kiwi.app.message.text(channel_name + ' is not a valid channel name', {timeout: 5000});
+ return;
+ }
+
+ // Check if we have the panel already. If not, create it
+ channel = that.panels.getByName(channel_name);
+ if (!channel) {
+ channel = new _kiwi.model.Channel({name: channel_name});
+ that.panels.add(channel);
+ }
+
+ panels.push(channel);
+
+ that.gateway.join(channel_name, channel_key);
+ });
+
+ return panels;
}
});
+
+ function onDisconnect(event) {
+ $.each(this.panels.models, function (index, panel) {
+ panel.addMsg('', 'Disconnected from the IRC network', 'action quit');
+ });
+ }
+
+
function onConnect(event) {
+ var panels, channel_names;
+
+ // Update our nick with what the network gave us
this.set('nick', event.nick);
+ // Auto joining channels
if (this.auto_join && this.auto_join.channel) {
- this.gateway.join(this.auto_join.channel, this.auto_join.channel_key);
+ panels = this.createAndJoinChannels(this.auto_join.channel + ' ' + (this.auto_join.channel_key || ''));
+
+ // Show the last channel if we have one
+ if (panels)
+ panels[panels.length - 1].view.show();
}
}
+ function onNick(event) {
+ var member;
+
+ $.each(this.panels.models, function (index, panel) {
+ if (panel.get('name') == event.nick)
+ panel.set('name', event.newnick);
+
+ if (!panel.isChannel()) return;
+
+ member = panel.get('members').getByNick(event.nick);
+ if (member) {
+ member.set('nick', event.newnick);
+ panel.addMsg('', '== ' + event.nick + ' is now known as ' + event.newnick, 'action nick');
+ }
+ });
+ }
+
+
+
function onCtcpRequest(event) {
// An ignored user? don't do anything with it
if (_kiwi.gateway.isNickIgnored(event.nick)) {
// Reply to a TIME ctcp
if (event.msg.toUpperCase() === 'TIME') {
- this.gateway.ctcp(false, event.type, event.nick, (new Date()).toString());
+ this.gateway.ctcp(null, false, event.type, event.nick, (new Date()).toString());
}
}
}
panel.addMsg('[' + (event.nick||'') + ']', event.msg);
+
+ // Show this notice to the active panel if it didn't have a set target
+ if (panel === this.panels.server)
+ _kiwi.app.panels().active.addMsg('[' + (event.nick||'') + ']', event.msg);
}
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;
+ 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) {
logon_date = formatDate(logon_date);
panel.addMsg(event.nick, 'idle for ' + idle_time + ', signed on ' + logon_date, 'whois');
+ } else if (event.away_reason) {
+ panel.addMsg(event.nick, 'Away: ' + event.away_reason, 'whois');
} else {
panel.addMsg(event.nick, 'idle for ' + idle_time, 'whois');
}