Skip to content

Commit

Permalink
Merge pull request #94 from xPaw/action-templates
Browse files Browse the repository at this point in the history
Move actions to templates
  • Loading branch information
astorije committed Feb 26, 2016
2 parents 5ef28c3 + 2c8c84a commit 31d9384
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 30 deletions.
13 changes: 1 addition & 12 deletions client/js/lounge.js
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions client/views/actions/action.tpl
@@ -0,0 +1,2 @@
<a href="#" class="user">{{mode}}{{from}}</a>
{{{parse text}}}
5 changes: 5 additions & 0 deletions client/views/actions/invite.tpl
@@ -0,0 +1,5 @@
<a href="#" class="user">{{from}}</a>
invited
<a href="#" class="user">{{target}}</a>
to
{{{parse text}}}
3 changes: 3 additions & 0 deletions client/views/actions/join.tpl
@@ -0,0 +1,3 @@
<a href="#" class="user">{{mode}}{{from}}</a>
<i class="hostmask">({{hostmask}})</i>
has joined the channel
6 changes: 6 additions & 0 deletions client/views/actions/kick.tpl
@@ -0,0 +1,6 @@
<a href="#" class="user">{{mode}}{{from}}</a>
has kicked
<a href="#" class="user">{{target}}</a>
{{#if text}}
<i class="part-reason">({{{parse text}}})</i>
{{/if}}
3 changes: 3 additions & 0 deletions client/views/actions/mode.tpl
@@ -0,0 +1,3 @@
<a href="#" class="user">{{mode}}{{from}}</a>
sets mode
{{{parse text}}}
3 changes: 3 additions & 0 deletions client/views/actions/nick.tpl
@@ -0,0 +1,3 @@
<a href="#" class="user">{{mode}}{{from}}</a>
is now known as
<a href="#" class="user">{{mode}}{{text}}</a>
6 changes: 6 additions & 0 deletions client/views/actions/part.tpl
@@ -0,0 +1,6 @@
<a href="#" class="user">{{mode}}{{from}}</a>
<i class="hostmask">({{hostmask}})</i>
has left the channel
{{#if text}}
<i class="part-reason">({{{parse text}}})</i>
{{/if}}
6 changes: 6 additions & 0 deletions client/views/actions/quit.tpl
@@ -0,0 +1,6 @@
<a href="#" class="user">{{mode}}{{from}}</a>
<i class="hostmask">({{hostmask}})</i>
has quit
{{#if text}}
<i class="quit-reason">({{{parse text}}})</i>
{{/if}}
8 changes: 8 additions & 0 deletions client/views/actions/topic.tpl
@@ -0,0 +1,8 @@
{{#if isSetByChan}}
The topic is:
{{else}}
<a href="#" class="user">{{mode}}{{from}}</a>
has changed the topic to:
{{/if}}

<span class="new-topic">{{{parse text}}}</span>
4 changes: 1 addition & 3 deletions client/views/msg_action.tpl
Expand Up @@ -4,8 +4,6 @@
</span>
<span class="from"></span>
<span class="text">
<a href="#" class="user">{{mode}}{{from}}</a>
{{formattedAction}}
{{{parse text}}}
{{partial template}}
</span>
</div>
1 change: 1 addition & 0 deletions src/plugins/irc-events/join.js
Expand Up @@ -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
});
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/irc-events/kick.js
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/irc-events/part.js
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/irc-events/quit.js
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/irc-events/topic.js
Expand Up @@ -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);
Expand Down

0 comments on commit 31d9384

Please sign in to comment.