Merge pull request #270 from thelounge/ircv3/echo-message

Add support for echo-message and znc.in/self-message caps
This commit is contained in:
Jérémie Astori 2016-04-30 19:37:10 -04:00
commit 404bf2c4df
7 changed files with 43 additions and 26 deletions

View File

@ -770,8 +770,7 @@ $(function() {
} }
var button = sidebar.find(".chan[data-target='" + target + "']"); var button = sidebar.find(".chan[data-target='" + target + "']");
var isQuery = button.hasClass("query"); if (msg.highlight || (options.notifyAllMessages && msg.type === "message")) {
if (msg.type === "invite" || msg.highlight || isQuery || (options.notifyAllMessages && msg.type === "message")) {
if (!document.hasFocus() || !$(target).hasClass("active")) { if (!document.hasFocus() || !$(target).hasClass("active")) {
if (options.notification) { if (options.notification) {
pop.play(); pop.play();
@ -787,7 +786,7 @@ $(function() {
body = msg.from + " invited you to " + msg.channel; body = msg.from + " invited you to " + msg.channel;
} else { } else {
title = msg.from; title = msg.from;
if (!isQuery) { if (!button.hasClass("query")) {
title += " (" + button.data("title").trim() + ")"; title += " (" + button.data("title").trim() + ")";
} }
title += " says:"; title += " says:";
@ -830,7 +829,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 (msg.highlight || isQuery) { if (msg.highlight) {
badge.addClass("highlight"); badge.addClass("highlight");
} }
} }

View File

@ -170,6 +170,10 @@ Client.prototype.connect = function(args) {
} }
network.irc = new ircFramework.Client(); network.irc = new ircFramework.Client();
network.irc.requestCap([
"echo-message",
"znc.in/self-message",
]);
network.irc.connect({ network.irc.connect({
host: network.host, host: network.host,
port: network.port, port: network.port,

View File

@ -16,11 +16,15 @@ exports.input = function(network, chan, cmd, args) {
text = text || args.join(" "); text = text || args.join(" ");
irc.say(chan.name, "\u0001ACTION " + text + "\u0001"); irc.say(chan.name, "\u0001ACTION " + text + "\u0001");
irc.emit("action", {
nick: irc.user.nick, if (!network.irc.network.cap.isEnabled("echo-message")) {
target: chan.name, irc.emit("action", {
message: text nick: irc.user.nick,
}); target: chan.name,
message: text
});
}
break; break;
} }

View File

@ -19,13 +19,15 @@ exports.input = function(network, chan, cmd, args) {
var msg = args.join(" "); var msg = args.join(" ");
irc.say(target, msg); irc.say(target, msg);
var channel = network.getChannel(target); if (!network.irc.network.cap.isEnabled("echo-message")) {
if (typeof channel !== "undefined") { var channel = network.getChannel(target);
irc.emit("privmsg", { if (typeof channel !== "undefined") {
nick: irc.user.nick, irc.emit("privmsg", {
target: channel.name, nick: irc.user.nick,
message: msg target: channel.name,
}); message: msg
});
}
} }
return true; return true;

View File

@ -15,11 +15,13 @@ exports.input = function(network, chan, cmd, args) {
targetChan = chan; targetChan = chan;
} }
irc.emit("notice", { if (!network.irc.network.cap.isEnabled("echo-message")) {
nick: irc.user.nick, irc.emit("notice", {
target: targetChan.name, nick: irc.user.nick,
message: message target: targetChan.name,
}); message: message
});
}
return true; return true;
}; };

View File

@ -14,6 +14,7 @@ module.exports = function(irc, network) {
from: data.nick, from: data.nick,
invited: data.invited, invited: data.invited,
channel: data.channel, channel: data.channel,
highlight: true,
invitedYou: data.invited === irc.user.nick invitedYou: data.invited === irc.user.nick
}); });
chan.pushMessage(client, msg); chan.pushMessage(client, msg);

View File

@ -26,6 +26,9 @@ module.exports = function(irc, network) {
}); });
function handleMessage(data) { function handleMessage(data) {
var highlight = false;
var self = data.nick === irc.user.nick;
// Server messages go to server window, no questions asked // Server messages go to server window, no questions asked
if (data.from_server) { if (data.from_server) {
chan = network.channels[0]; chan = network.channels[0];
@ -43,6 +46,7 @@ module.exports = function(irc, network) {
if (data.type === Msg.Type.NOTICE) { if (data.type === Msg.Type.NOTICE) {
chan = network.channels[0]; chan = network.channels[0];
} else { } else {
highlight = !self;
chan = new Chan({ chan = new Chan({
type: Chan.Type.QUERY, type: Chan.Type.QUERY,
name: target name: target
@ -56,13 +60,14 @@ module.exports = function(irc, network) {
} }
} }
var self = data.nick === irc.user.nick; // Query messages (unless self) always highlight
// Self messages are never highlighted // Self messages are never highlighted
// Non-self messages are highlighted as soon as the nick is detected // Non-self messages are highlighted as soon as the nick is detected
var highlight = !self && data.message.split(" ").some(function(w) { if (!highlight && !self) {
return (w.replace(/^@/, "").toLowerCase().indexOf(irc.user.nick.toLowerCase()) === 0); highlight = data.message.split(" ").some(function(w) {
}); return (w.replace(/^@/, "").toLowerCase().indexOf(irc.user.nick.toLowerCase()) === 0);
});
}
if (!self && chan.id !== client.activeChannel) { if (!self && chan.id !== client.activeChannel) {
chan.unread++; chan.unread++;