From 357e238a458c4f0f1db6bee3acc67567707e8d9a Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 23 Feb 2016 12:38:51 +0200 Subject: [PATCH] Fix how highlights are handled --- client/js/lounge.js | 9 +++------ client/views/msg.tpl | 2 +- client/views/msg_action.tpl | 2 +- src/plugins/inputs/action.js | 16 +++------------- src/plugins/irc-events/message.js | 17 +++++++++++------ 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 2404a29b..ae023b04 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -640,10 +640,7 @@ $(function() { chat.on("msg", ".messages", function(e, target, msg) { var button = sidebar.find(".chan[data-target='" + target + "']"); var isQuery = button.hasClass("query"); - var type = msg.type; - var highlight = type.contains("highlight"); - var message = type.contains("message"); - if (highlight || isQuery || (options.notifyAllMessages && message)) { + if (msg.highlight || isQuery || (options.notifyAllMessages && msg.type === "message")) { if (!document.hasFocus() || !$(target).hasClass("active")) { if (options.notification) { pop.play(); @@ -679,7 +676,7 @@ $(function() { "nick", "mode", ]; - if ($.inArray(type, ignore) !== -1){ + if ($.inArray(msg.type, ignore) !== -1){ return; } @@ -688,7 +685,7 @@ $(function() { var i = (badge.data("count") || 0) + 1; badge.data("count", i); badge.html(i > 999 ? (i / 1000).toFixed(1) + "k" : i); - if (highlight || isQuery) { + if (msg.highlight || isQuery) { badge.addClass("highlight"); } } diff --git a/client/views/msg.tpl b/client/views/msg.tpl index 755f911e..35ca031f 100644 --- a/client/views/msg.tpl +++ b/client/views/msg.tpl @@ -1,4 +1,4 @@ -
+
{{tz time}} diff --git a/client/views/msg_action.tpl b/client/views/msg_action.tpl index da547dd0..2eb1fe85 100644 --- a/client/views/msg_action.tpl +++ b/client/views/msg_action.tpl @@ -1,4 +1,4 @@ -
+
{{tz time}} diff --git a/src/plugins/inputs/action.js b/src/plugins/inputs/action.js index e81d13a0..a01f2213 100644 --- a/src/plugins/inputs/action.js +++ b/src/plugins/inputs/action.js @@ -1,11 +1,8 @@ -var Msg = require("../../models/msg"); - module.exports = function(network, chan, cmd, args) { if (cmd !== "slap" && cmd !== "me") { return; } - var client = this; var irc = network.irc; switch (cmd) { @@ -22,17 +19,10 @@ module.exports = function(network, chan, cmd, args) { chan.name, text ); - - var msg = new Msg({ - type: Msg.Type.ACTION, - mode: chan.getMode(irc.me), + irc.emit("message", { from: irc.me, - text: text - }); - chan.messages.push(msg); - client.emit("msg", { - chan: chan.id, - msg: msg + to: chan.name, + message: "\u0001ACTION " + text }); break; } diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index 9ac503fc..f062571e 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -28,15 +28,19 @@ module.exports = function(irc, network) { }); } - var type = ""; + var type = Msg.Type.MESSAGE; var text = data.message; - if (text.split(" ")[0] === "\u0001ACTION") { + var textSplit = text.split(" "); + if (textSplit[0] === "\u0001ACTION") { type = Msg.Type.ACTION; text = text.replace(/^\u0001ACTION|\u0001$/g, ""); } - text.split(" ").forEach(function(w) { - if (w.replace(/^@/, "").toLowerCase().indexOf(irc.me.toLowerCase()) === 0) type += " highlight"; + var highlight = false; + textSplit.forEach(function(w) { + if (w.replace(/^@/, "").toLowerCase().indexOf(irc.me.toLowerCase()) === 0) { + highlight = true; + } }); var self = false; @@ -50,11 +54,12 @@ module.exports = function(irc, network) { var name = data.from; var msg = new Msg({ - type: type || Msg.Type.MESSAGE, + type: type, mode: chan.getMode(name), from: name, text: text, - self: self + self: self, + highlight: highlight }); chan.messages.push(msg); client.emit("msg", {