From: Darren Date: Sun, 30 Sep 2012 13:53:57 +0000 (+0100) Subject: Mode change text now formatted X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=51beac3b28ee5df8a4ce92b2f375fd2a65ecc837;p=KiwiIRC.git Mode change text now formatted --- diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index 6d1d4d7..0ff5bce 100755 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -380,6 +380,42 @@ kiwi.model.Application = function () { gw.on('onmode', function (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 = that.panels.getByName(event.target); if (channel) { prefixes = kiwi.gateway.get('user_prefixes'); @@ -401,19 +437,22 @@ kiwi.model.Application = function () { } else if (event.modes[i].mode[0] === '-') { member.removeMode(event.modes[i].mode[1]); } - channel.addMsg(event.nick, 'set mode ' + event.modes[i].mode + ' ' + event.modes[i].param, 'mode'); + //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(event.nick, 'set mode ' + event.modes[i].mode + ' on ' + event.target, 'mode'); + //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() === kiwi.gateway.get("nick").toLowerCase()) { - that.panels.server.addMsg(event.nick, 'set mode ' + event.modes[i].mode + ' on ' + event.target, 'mode'); + that.panels.server.addMsg('', '=== ' + event.nick + ' set mode ' + friendlyModeString(), 'action mode'); } else { - console.log('MODE command recieved for unknown target %s: ', event.target, event.modes[i].mode,); + console.log('MODE command recieved for unknown target %s: ', event.target, event); } } }); @@ -531,13 +570,13 @@ kiwi.model.Application = function () { kiwi.app.panels.server.addMsg(' ', '=== The nickname ' + data.nick + ' is already in use. Please select a new nickname', 'status'); if (kiwi.app.panels.server !== kiwi.app.panels.active) { kiwi.app.message.text('The nickname "' + data.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; default: // We don't know what data contains, so don't do anything with it. @@ -804,4 +843,4 @@ kiwi.model.Application = function () { return new (Backbone.Model.extend(this))(arguments); -}; +};