From b801689eaa96794f00920d865cca85f257d5d782 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 4 Oct 2014 05:31:45 -0700 Subject: [PATCH] Show user modes in channel --- build.sh | 2 +- client/js/shout.templates.js | 1 + client/{templates => views}/chan.tpl | 0 client/{templates => views}/chat.tpl | 0 client/{templates => views}/msg.tpl | 2 +- client/{templates => views}/network.tpl | 0 client/{templates => views}/toggle.tpl | 0 client/{templates => views}/user.tpl | 0 src/models/chan.js | 9 +++++++++ src/plugins/irc-events/kick.js | 10 +++++++++- src/plugins/irc-events/message.js | 4 +++- src/plugins/irc-events/mode.js | 11 ++++++----- src/plugins/irc-events/part.js | 8 +++++--- src/plugins/irc-events/quit.js | 6 ++++-- src/plugins/irc-events/topic.js | 1 + 15 files changed, 40 insertions(+), 14 deletions(-) rename client/{templates => views}/chan.tpl (100%) rename client/{templates => views}/chat.tpl (100%) rename client/{templates => views}/msg.tpl (84%) rename client/{templates => views}/network.tpl (100%) rename client/{templates => views}/toggle.tpl (100%) rename client/{templates => views}/user.tpl (100%) diff --git a/build.sh b/build.sh index f02b220c..36ee2dec 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ if ! type handlebars &> /dev/null; then fi # Compile the templates -handlebars -e tpl -f client/js/shout.templates.js client/templates/ +handlebars -e tpl -f client/js/shout.templates.js client/views/ # Uglify the javascript libraries # See: Gruntfile.js diff --git a/client/js/shout.templates.js b/client/js/shout.templates.js index af59749b..64d70da0 100644 --- a/client/js/shout.templates.js +++ b/client/js/shout.templates.js @@ -88,6 +88,7 @@ templates['msg'] = template({"1":function(depth0,helpers,partials,data) { return " \n"; },"6":function(depth0,helpers,partials,data) { diff --git a/client/templates/chan.tpl b/client/views/chan.tpl similarity index 100% rename from client/templates/chan.tpl rename to client/views/chan.tpl diff --git a/client/templates/chat.tpl b/client/views/chat.tpl similarity index 100% rename from client/templates/chat.tpl rename to client/views/chat.tpl diff --git a/client/templates/msg.tpl b/client/views/msg.tpl similarity index 84% rename from client/templates/msg.tpl rename to client/views/msg.tpl index f81eb246..fdfe0908 100644 --- a/client/templates/msg.tpl +++ b/client/views/msg.tpl @@ -5,7 +5,7 @@ {{#if from}} - + {{/if}} diff --git a/client/templates/network.tpl b/client/views/network.tpl similarity index 100% rename from client/templates/network.tpl rename to client/views/network.tpl diff --git a/client/templates/toggle.tpl b/client/views/toggle.tpl similarity index 100% rename from client/templates/toggle.tpl rename to client/views/toggle.tpl diff --git a/client/templates/user.tpl b/client/views/user.tpl similarity index 100% rename from client/templates/user.tpl rename to client/views/user.tpl diff --git a/src/models/chan.js b/src/models/chan.js index 55f527fb..3664c125 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -41,6 +41,15 @@ Chan.prototype.sortUsers = function() { }, this); }; +Chan.prototype.getMode = function(name) { + var user = _.find(this.users, {name: name}); + if (user) { + return user.mode; + } else { + return ""; + } +}; + Chan.prototype.toJSON = function() { var clone = _.clone(this); clone.messages = clone.messages.slice(-100); diff --git a/src/plugins/irc-events/kick.js b/src/plugins/irc-events/kick.js index 0ee6a5e3..88e37292 100644 --- a/src/plugins/irc-events/kick.js +++ b/src/plugins/irc-events/kick.js @@ -4,26 +4,34 @@ var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("kick", function(data) { + var from = data.nick; var chan = _.findWhere(network.channels, {name: data.channel}); + var mode = chan.getMode(from); + if (typeof chan === "undefined") { return; } + if (data.client == irc.me) { chan.users = []; } else { chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.client})); } + client.emit("users", { chan: chan.id, users: chan.users }); + var self = false; if (data.nick.toLowerCase() == irc.me.toLowerCase()) { self = true; } + var msg = new Msg({ type: Msg.Type.KICK, - from: data.nick, + mode: mode, + from: from, text: data.client, self: self }); diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index 2c583e14..d1eb7899 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -48,9 +48,11 @@ module.exports = function(irc, network) { chan.unread++; } + var name = data.from; var msg = new Msg({ type: type || Msg.Type.MESSAGE, - from: data.from, + mode: chan.getMode(name), + from: name, text: text, self: self }); diff --git a/src/plugins/irc-events/mode.js b/src/plugins/irc-events/mode.js index 95bf8ea6..96648375 100644 --- a/src/plugins/irc-events/mode.js +++ b/src/plugins/irc-events/mode.js @@ -9,17 +9,18 @@ module.exports = function(irc, network) { setTimeout(function() { irc.write("NAMES " + data.target); }, 200); - var nick = data.nick; - if (nick.indexOf(".") !== -1) { - nick = data.target; + var from = data.nick; + if (from.indexOf(".") !== -1) { + from = data.target; } var self = false; - if (nick.toLowerCase() == irc.me.toLowerCase()) { + if (from.toLowerCase() == irc.me.toLowerCase()) { self = true; } var msg = new Msg({ type: Msg.Type.MODE, - from: nick, + mode: chan.getMode(from), + from: from, text: data.mode + " " + data.client, self: self }); diff --git a/src/plugins/irc-events/part.js b/src/plugins/irc-events/part.js index ceeb199c..82bee8b6 100644 --- a/src/plugins/irc-events/part.js +++ b/src/plugins/irc-events/part.js @@ -8,13 +8,14 @@ module.exports = function(irc, network) { if (typeof chan === "undefined") { return; } - if (data.nick == irc.me) { + var from = data.nick; + if (from == irc.me) { network.channels = _.without(network.channels, chan); client.emit("part", { chan: chan.id }); } else { - var user = _.findWhere(chan.users, {name: data.nick}); + var user = _.findWhere(chan.users, {name: from}); chan.users = _.without(chan.users, user); client.emit("users", { chan: chan.id, @@ -22,7 +23,8 @@ module.exports = function(irc, network) { }); var msg = new Msg({ type: Msg.Type.PART, - from: data.nick + mode: chan.getMode(from), + from: from }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/quit.js b/src/plugins/irc-events/quit.js index f6cb63b1..b60d334d 100644 --- a/src/plugins/irc-events/quit.js +++ b/src/plugins/irc-events/quit.js @@ -5,7 +5,8 @@ module.exports = function(irc, network) { var client = this; irc.on("quit", function(data) { network.channels.forEach(function(chan) { - var user = _.findWhere(chan.users, {name: data.nick}); + var from = data.nick; + var user = _.findWhere(chan.users, {name: from}); if (typeof user === "undefined") { return; } @@ -16,7 +17,8 @@ module.exports = function(irc, network) { }); var msg = new Msg({ type: Msg.Type.QUIT, - from: data.nick + mode: chan.getMode(from), + from: from }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/topic.js b/src/plugins/irc-events/topic.js index e13bfaa9..c12033f1 100644 --- a/src/plugins/irc-events/topic.js +++ b/src/plugins/irc-events/topic.js @@ -15,6 +15,7 @@ module.exports = function(irc, network) { } var msg = new Msg({ type: Msg.Type.TOPIC, + mode: chan.getMode(from), from: from, text: data.topic, self: self