From 2c8c84aec57fa36042a959dc7698f9bcdf8f4038 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 23 Feb 2016 18:22:41 +0200 Subject: [PATCH] Move actions to templates --- client/js/lounge.js | 13 +------------ client/views/actions/action.tpl | 2 ++ client/views/actions/invite.tpl | 5 +++++ client/views/actions/join.tpl | 3 +++ client/views/actions/kick.tpl | 6 ++++++ client/views/actions/mode.tpl | 3 +++ client/views/actions/nick.tpl | 3 +++ client/views/actions/part.tpl | 6 ++++++ client/views/actions/quit.tpl | 6 ++++++ client/views/actions/topic.tpl | 8 ++++++++ client/views/msg_action.tpl | 4 +--- src/plugins/irc-events/join.js | 1 + src/plugins/irc-events/kick.js | 7 ++----- src/plugins/irc-events/part.js | 7 ++----- src/plugins/irc-events/quit.js | 7 ++----- src/plugins/irc-events/topic.js | 1 + 16 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 client/views/actions/action.tpl create mode 100644 client/views/actions/invite.tpl create mode 100644 client/views/actions/join.tpl create mode 100644 client/views/actions/kick.tpl create mode 100644 client/views/actions/mode.tpl create mode 100644 client/views/actions/nick.tpl create mode 100644 client/views/actions/part.tpl create mode 100644 client/views/actions/quit.tpl create mode 100644 client/views/actions/topic.tpl diff --git a/client/js/lounge.js b/client/js/lounge.js index dafafbc7..881f9f07 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -201,18 +201,7 @@ $(function() { "topic", "action", ].indexOf(type) !== -1) { - switch (type) { - case "invite": data.msg.formattedAction = "invited " + data.msg.target + " to"; break; - case "join": data.msg.formattedAction = "has joined the channel"; break; - case "mode": data.msg.formattedAction = "sets mode"; break; - case "kick": data.msg.formattedAction = "has kicked"; break; - case "nick": data.msg.formattedAction = "is now known as"; break; - case "part": data.msg.formattedAction = "has left the channel"; break; - case "quit": data.msg.formattedAction = "has quit"; break; - case "topic": data.msg.formattedAction = "has changed the topic to:"; break; - default: data.msg.formattedAction = ""; - } - + data.msg.template = "actions/" + type; msg = $(render("msg_action", data.msg)); } else { msg = $(render("msg", data.msg)); diff --git a/client/views/actions/action.tpl b/client/views/actions/action.tpl new file mode 100644 index 00000000..0e28c0c8 --- /dev/null +++ b/client/views/actions/action.tpl @@ -0,0 +1,2 @@ +{{mode}}{{from}} +{{{parse text}}} diff --git a/client/views/actions/invite.tpl b/client/views/actions/invite.tpl new file mode 100644 index 00000000..52f2c0a9 --- /dev/null +++ b/client/views/actions/invite.tpl @@ -0,0 +1,5 @@ +{{from}} +invited +{{target}} +to +{{{parse text}}} diff --git a/client/views/actions/join.tpl b/client/views/actions/join.tpl new file mode 100644 index 00000000..5d026abb --- /dev/null +++ b/client/views/actions/join.tpl @@ -0,0 +1,3 @@ +{{mode}}{{from}} +({{hostmask}}) +has joined the channel diff --git a/client/views/actions/kick.tpl b/client/views/actions/kick.tpl new file mode 100644 index 00000000..22cb4a0c --- /dev/null +++ b/client/views/actions/kick.tpl @@ -0,0 +1,6 @@ +{{mode}}{{from}} +has kicked +{{target}} +{{#if text}} + ({{{parse text}}}) +{{/if}} diff --git a/client/views/actions/mode.tpl b/client/views/actions/mode.tpl new file mode 100644 index 00000000..7574695f --- /dev/null +++ b/client/views/actions/mode.tpl @@ -0,0 +1,3 @@ +{{mode}}{{from}} +sets mode +{{{parse text}}} diff --git a/client/views/actions/nick.tpl b/client/views/actions/nick.tpl new file mode 100644 index 00000000..3ecd5ac9 --- /dev/null +++ b/client/views/actions/nick.tpl @@ -0,0 +1,3 @@ +{{mode}}{{from}} +is now known as +{{mode}}{{text}} diff --git a/client/views/actions/part.tpl b/client/views/actions/part.tpl new file mode 100644 index 00000000..54c7370e --- /dev/null +++ b/client/views/actions/part.tpl @@ -0,0 +1,6 @@ +{{mode}}{{from}} +({{hostmask}}) +has left the channel +{{#if text}} + ({{{parse text}}}) +{{/if}} diff --git a/client/views/actions/quit.tpl b/client/views/actions/quit.tpl new file mode 100644 index 00000000..2627812b --- /dev/null +++ b/client/views/actions/quit.tpl @@ -0,0 +1,6 @@ +{{mode}}{{from}} +({{hostmask}}) +has quit +{{#if text}} + ({{{parse text}}}) +{{/if}} diff --git a/client/views/actions/topic.tpl b/client/views/actions/topic.tpl new file mode 100644 index 00000000..4dba215c --- /dev/null +++ b/client/views/actions/topic.tpl @@ -0,0 +1,8 @@ +{{#if isSetByChan}} + The topic is: +{{else}} + {{mode}}{{from}} + has changed the topic to: +{{/if}} + +{{{parse text}}} diff --git a/client/views/msg_action.tpl b/client/views/msg_action.tpl index 78d2373e..da547dd0 100644 --- a/client/views/msg_action.tpl +++ b/client/views/msg_action.tpl @@ -4,8 +4,6 @@ - {{mode}}{{from}} - {{formattedAction}} - {{{parse text}}} + {{partial template}} diff --git a/src/plugins/irc-events/join.js b/src/plugins/irc-events/join.js index dbb51ef8..07e0bd0f 100644 --- a/src/plugins/irc-events/join.js +++ b/src/plugins/irc-events/join.js @@ -29,6 +29,7 @@ module.exports = function(irc, network) { } var msg = new Msg({ from: data.nick, + hostmask: data.hostmask.username + "@" + data.hostmask.hostname, type: Msg.Type.JOIN, self: self }); diff --git a/src/plugins/irc-events/kick.js b/src/plugins/irc-events/kick.js index 6044f49d..c5bac10d 100644 --- a/src/plugins/irc-events/kick.js +++ b/src/plugins/irc-events/kick.js @@ -26,15 +26,12 @@ module.exports = function(irc, network) { if (data.nick.toLowerCase() === irc.me.toLowerCase()) { self = true; } - var reason = data.message || ""; - if (reason.length > 0) { - reason = " (" + reason + ")"; - } var msg = new Msg({ type: Msg.Type.KICK, mode: mode, from: from, - text: data.client + reason, + target: data.client, + text: data.message || "", self: self }); chan.messages.push(msg); diff --git a/src/plugins/irc-events/part.js b/src/plugins/irc-events/part.js index 3489b032..89d2364e 100644 --- a/src/plugins/irc-events/part.js +++ b/src/plugins/irc-events/part.js @@ -21,14 +21,11 @@ module.exports = function(irc, network) { client.emit("users", { chan: chan.id }); - var reason = data.message || ""; - if (reason.length > 0) { - reason = "(" + reason + ")"; - } var msg = new Msg({ type: Msg.Type.PART, mode: chan.getMode(from), - text: reason, + text: data.message || "", + hostmask:data.hostmask.username + "@" + data.hostmask.hostname, from: from }); chan.messages.push(msg); diff --git a/src/plugins/irc-events/quit.js b/src/plugins/irc-events/quit.js index 896b0576..59ff5f3b 100644 --- a/src/plugins/irc-events/quit.js +++ b/src/plugins/irc-events/quit.js @@ -14,14 +14,11 @@ module.exports = function(irc, network) { client.emit("users", { chan: chan.id }); - var reason = data.message || ""; - if (reason.length > 0) { - reason = "(" + reason + ")"; - } var msg = new Msg({ type: Msg.Type.QUIT, mode: chan.getMode(from), - text: reason, + text: data.message || "", + hostmask: data.hostmask.username + "@" + data.hostmask.hostname, from: from }); chan.messages.push(msg); diff --git a/src/plugins/irc-events/topic.js b/src/plugins/irc-events/topic.js index 879a890f..600780fe 100644 --- a/src/plugins/irc-events/topic.js +++ b/src/plugins/irc-events/topic.js @@ -16,6 +16,7 @@ module.exports = function(irc, network) { mode: chan.getMode(from), from: from, text: topic, + isSetByChan: from === chan.name, self: (from.toLowerCase() === irc.me.toLowerCase()) }); chan.messages.push(msg);