Merge pull request #91 from xPaw/fix-highlight

Fix how highlights are handled
This commit is contained in:
Jérémie Astori 2016-02-28 00:45:23 -05:00
commit ce69ce333a
5 changed files with 19 additions and 27 deletions

View File

@ -665,10 +665,7 @@ $(function() {
chat.on("msg", ".messages", function(e, target, msg) { chat.on("msg", ".messages", function(e, target, msg) {
var button = sidebar.find(".chan[data-target='" + target + "']"); var button = sidebar.find(".chan[data-target='" + target + "']");
var isQuery = button.hasClass("query"); var isQuery = button.hasClass("query");
var type = msg.type; if (msg.highlight || isQuery || (options.notifyAllMessages && msg.type === "message")) {
var highlight = type.contains("highlight");
var message = type.contains("message");
if (highlight || isQuery || (options.notifyAllMessages && message)) {
if (!document.hasFocus() || !$(target).hasClass("active")) { if (!document.hasFocus() || !$(target).hasClass("active")) {
if (options.notification) { if (options.notification) {
pop.play(); pop.play();
@ -704,7 +701,7 @@ $(function() {
"nick", "nick",
"mode", "mode",
]; ];
if ($.inArray(type, ignore) !== -1){ if ($.inArray(msg.type, ignore) !== -1){
return; return;
} }
@ -713,7 +710,7 @@ $(function() {
var i = (badge.data("count") || 0) + 1; var i = (badge.data("count") || 0) + 1;
badge.data("count", i); badge.data("count", i);
badge.html(i > 999 ? (i / 1000).toFixed(1) + "k" : i); badge.html(i > 999 ? (i / 1000).toFixed(1) + "k" : i);
if (highlight || isQuery) { if (msg.highlight || isQuery) {
badge.addClass("highlight"); badge.addClass("highlight");
} }
} }

View File

@ -1,4 +1,4 @@
<div class="msg {{type}} {{#if self}}self{{/if}}"> <div class="msg {{type}}{{#if self}} self{{/if}}{{#if highlight}} highlight{{/if}}">
<span class="time"> <span class="time">
{{tz time}} {{tz time}}
</span> </span>

View File

@ -1,4 +1,4 @@
<div class="msg {{type}} {{#if self}}self{{/if}}"> <div class="msg {{type}}{{#if self}} self{{/if}}{{#if highlight}} highlight{{/if}}">
<span class="time"> <span class="time">
{{tz time}} {{tz time}}
</span> </span>

View File

@ -1,11 +1,8 @@
var Msg = require("../../models/msg");
module.exports = function(network, chan, cmd, args) { module.exports = function(network, chan, cmd, args) {
if (cmd !== "slap" && cmd !== "me") { if (cmd !== "slap" && cmd !== "me") {
return; return;
} }
var client = this;
var irc = network.irc; var irc = network.irc;
switch (cmd) { switch (cmd) {
@ -22,17 +19,10 @@ module.exports = function(network, chan, cmd, args) {
chan.name, chan.name,
text text
); );
irc.emit("message", {
var msg = new Msg({
type: Msg.Type.ACTION,
mode: chan.getMode(irc.me),
from: irc.me, from: irc.me,
text: text to: chan.name,
}); message: "\u0001ACTION " + text
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
}); });
break; break;
} }

View File

@ -28,15 +28,19 @@ module.exports = function(irc, network) {
}); });
} }
var type = ""; var type = Msg.Type.MESSAGE;
var text = data.message; var text = data.message;
if (text.split(" ")[0] === "\u0001ACTION") { var textSplit = text.split(" ");
if (textSplit[0] === "\u0001ACTION") {
type = Msg.Type.ACTION; type = Msg.Type.ACTION;
text = text.replace(/^\u0001ACTION|\u0001$/g, ""); text = text.replace(/^\u0001ACTION|\u0001$/g, "");
} }
text.split(" ").forEach(function(w) { var highlight = false;
if (w.replace(/^@/, "").toLowerCase().indexOf(irc.me.toLowerCase()) === 0) type += " highlight"; textSplit.forEach(function(w) {
if (w.replace(/^@/, "").toLowerCase().indexOf(irc.me.toLowerCase()) === 0) {
highlight = true;
}
}); });
var self = false; var self = false;
@ -50,11 +54,12 @@ module.exports = function(irc, network) {
var name = data.from; var name = data.from;
var msg = new Msg({ var msg = new Msg({
type: type || Msg.Type.MESSAGE, type: type,
mode: chan.getMode(name), mode: chan.getMode(name),
from: name, from: name,
text: text, text: text,
self: self self: self,
highlight: highlight
}); });
chan.messages.push(msg); chan.messages.push(msg);
client.emit("msg", { client.emit("msg", {