From fabbb43e1841bcb89575161ba61d6ce0bdd2f2ef Mon Sep 17 00:00:00 2001 From: Fredrik Pettersen Date: Sun, 14 Sep 2014 19:06:56 +0200 Subject: [PATCH] Added boolean flag if message was sent from "me" Your own messages now have a different color, and the possibility of changing colors etc in css of all things sent by yourself --- client/css/style.css | 5 +++++ client/templates/msg.tpl | 4 ++++ src/models/msg.js | 3 ++- src/plugins/irc-events/image.js | 7 ++++++- src/plugins/irc-events/join.js | 7 ++++++- src/plugins/irc-events/kick.js | 7 ++++++- src/plugins/irc-events/message.js | 7 ++++++- src/plugins/irc-events/mode.js | 5 +++++ src/plugins/irc-events/topic.js | 5 +++++ 9 files changed, 45 insertions(+), 5 deletions(-) diff --git a/client/css/style.css b/client/css/style.css index fe5bc03..9a0bc38 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -454,6 +454,10 @@ button { height: 100%; width: 100%; } + +#chat .from_me .text { + color: #999; +} #chat .msg { display: table-row; word-wrap: break-word; @@ -478,6 +482,7 @@ button { display: table-cell; padding: 3px 0; vertical-align: top; + } #chat .time { color: #d0dbe2; diff --git a/client/templates/msg.tpl b/client/templates/msg.tpl index 5209e68..ad78480 100644 --- a/client/templates/msg.tpl +++ b/client/templates/msg.tpl @@ -1,5 +1,9 @@ {{#each messages}} +{{#if from_me}} +
+{{else}}
+{{/if}} {{tz time}} diff --git a/src/models/msg.js b/src/models/msg.js index a4c4277..b3f65e5 100644 --- a/src/models/msg.js +++ b/src/models/msg.js @@ -25,6 +25,7 @@ function Msg(attr) { from: "", text: "", time: moment().utc().format("HH:mm:ss"), - type: Msg.Type.MESSAGE + type: Msg.Type.MESSAGE, + from_me: false, }, attr)); } diff --git a/src/plugins/irc-events/image.js b/src/plugins/irc-events/image.js index d633c2d..538c61c 100644 --- a/src/plugins/irc-events/image.js +++ b/src/plugins/irc-events/image.js @@ -25,11 +25,16 @@ module.exports = function(irc, network) { if (typeof chan === "undefined") { return; } + var from_me = false + if (data.from.toLowerCase() == irc.me.toLowerCase() ) { + from_me = true + } fetchImage(image, function(name) { var msg = new Msg({ type: Msg.Type.IMAGE, from: data.from, - text: "thumbs/" + name + text: "thumbs/" + name, + from_me = from_me }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/join.js b/src/plugins/irc-events/join.js index e328573..dfc17f2 100644 --- a/src/plugins/irc-events/join.js +++ b/src/plugins/irc-events/join.js @@ -17,6 +17,10 @@ module.exports = function(irc, network) { chan: chan }); } + var from_me = false + if (data.from.toLowerCase() == irc.me.toLowerCase() ) { + from_me = true + } var users = chan.users; users.push(new User({name: data.nick})); chan.sortUsers(); @@ -26,7 +30,8 @@ module.exports = function(irc, network) { }); var msg = new Msg({ from: data.nick, - type: Msg.Type.JOIN + type: Msg.Type.JOIN, + from_me: from_me }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/kick.js b/src/plugins/irc-events/kick.js index 83aed9c..be4da46 100644 --- a/src/plugins/irc-events/kick.js +++ b/src/plugins/irc-events/kick.js @@ -17,10 +17,15 @@ module.exports = function(irc, network) { chan: chan.id, users: chan.users }); + var from_me = false + if (data.nick.toLowerCase() == irc.me.toLowerCase() ) { + from_me = true + } var msg = new Msg({ type: Msg.Type.KICK, from: data.nick, - text: data.client + text: data.client, + from_me: from_me }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index ce0acfb..15952fd 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -30,10 +30,15 @@ module.exports = function(irc, network) { text.split(" ").forEach(function(w) { if (w.indexOf(irc.me) === 0) type += " highlight"; }); + var from_me = false + if (data.from.toLowerCase() == irc.me.toLowerCase() ) { + from_me = true + } var msg = new Msg({ type: type || Msg.Type.MESSAGE, from: data.from, - text: text + text: text, + from_me: from_me }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/mode.js b/src/plugins/irc-events/mode.js index 2cffa38..ee4fb41 100644 --- a/src/plugins/irc-events/mode.js +++ b/src/plugins/irc-events/mode.js @@ -13,10 +13,15 @@ module.exports = function(irc, network) { if (nick.indexOf(".") !== -1) { nick = data.target; } + var from_me = false + if (nick.toLowerCase() == irc.me.toLowerCase() ) { + from_me = true + } var msg = new Msg({ type: Msg.Type.MODE, from: nick, text: data.mode + " " + data.client, + from_me: from_me }); chan.messages.push(msg); client.emit("msg", { diff --git a/src/plugins/irc-events/topic.js b/src/plugins/irc-events/topic.js index 5a94f4d..afe1267 100644 --- a/src/plugins/irc-events/topic.js +++ b/src/plugins/irc-events/topic.js @@ -9,10 +9,15 @@ module.exports = function(irc, network) { return; } var from = data.nick || chan.name; + var from_me = false + if (data.nick.toLowerCase() == irc.me.toLowerCase() ) { + from_me = true + } var msg = new Msg({ type: Msg.Type.TOPIC, from: from, text: data.topic, + from_me: from_me, }); chan.messages.push(msg); client.emit("msg", {