Merge pull request #1380 from thelounge/xpaw/inline-notices

Show notices and errors inline
This commit is contained in:
Pavel Djundik 2017-12-06 18:06:40 +02:00 committed by GitHub
commit 65423eb8fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 29 deletions

View File

@ -27,11 +27,27 @@ socket.on("msg", function(data) {
}); });
function processReceivedMessage(data) { function processReceivedMessage(data) {
const targetId = data.chan; let targetId = data.chan;
const target = "#chan-" + targetId; let target = "#chan-" + targetId;
const channel = chat.find(target); let channel = chat.find(target);
const container = channel.find(".messages"); let sidebarTarget = sidebar.find("[data-target='" + target + "']");
// Display received notices and errors in currently active channel.
// Reloading the page will put them back into the lobby window.
if (data.msg.showInActive) {
const activeOnNetwork = sidebarTarget.parent().find(".active");
// We only want to put errors/notices in active channel if they arrive on the same network
if (activeOnNetwork.length > 0) {
targetId = data.chan = activeOnNetwork.data("id");
target = "#chan-" + targetId;
channel = chat.find(target);
sidebarTarget = sidebar.find("[data-target='" + target + "']");
}
}
const container = channel.find(".messages");
const activeChannelId = chat.find(".chan.active").data("id"); const activeChannelId = chat.find(".chan.active").data("id");
if (data.msg.type === "channel_list" || data.msg.type === "ban_list") { if (data.msg.type === "channel_list" || data.msg.type === "ban_list") {
@ -65,7 +81,7 @@ function processReceivedMessage(data) {
// Clear unread/highlight counter if self-message // Clear unread/highlight counter if self-message
if (data.msg.self) { if (data.msg.self) {
sidebar.find("[data-target='" + target + "'] .badge").removeClass("highlight").empty(); sidebarTarget.find(".badge").removeClass("highlight").empty();
} }
let messageLimit = 0; let messageLimit = 0;
@ -82,7 +98,7 @@ function processReceivedMessage(data) {
render.trimMessageInChannel(channel, messageLimit); render.trimMessageInChannel(channel, messageLimit);
} }
if ((data.msg.type === "message" || data.msg.type === "action" || data.msg.type === "notice") && channel.hasClass("channel")) { if ((data.msg.type === "message" || data.msg.type === "action") && channel.hasClass("channel")) {
const nicks = channel.find(".users").data("nicks"); const nicks = channel.find(".users").data("nicks");
if (nicks) { if (nicks) {
const find = nicks.indexOf(data.msg.from.nick); const find = nicks.indexOf(data.msg.from.nick);

View File

@ -16,6 +16,7 @@ module.exports = function(irc, network) {
const msg = new Msg({ const msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: text, text: text,
showInActive: true,
}); });
lobby.pushMessage(client, msg, true); lobby.pushMessage(client, msg, true);
}); });
@ -25,6 +26,7 @@ module.exports = function(irc, network) {
const msg = new Msg({ const msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: data.nick + ": " + (data.reason || "Nickname is already in use."), text: data.nick + ": " + (data.reason || "Nickname is already in use."),
showInActive: true,
}); });
lobby.pushMessage(client, msg, true); lobby.pushMessage(client, msg, true);
@ -44,6 +46,7 @@ module.exports = function(irc, network) {
const msg = new Msg({ const msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: data.nick + ": " + (data.reason || "Nickname is invalid."), text: data.nick + ": " + (data.reason || "Nickname is invalid."),
showInActive: true,
}); });
lobby.pushMessage(client, msg, true); lobby.pushMessage(client, msg, true);

View File

@ -38,14 +38,19 @@ module.exports = function(irc, network) {
function handleMessage(data) { function handleMessage(data) {
let chan; let chan;
let user; const msg = new Msg({
let highlight = false; type: data.type,
const self = data.nick === irc.user.nick; time: data.time,
text: data.message,
self: data.nick === irc.user.nick,
highlight: false,
users: [],
});
// 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];
user = chan.getUser(data.nick); msg.from = chan.getUser(data.nick);
} else { } else {
let target = data.target; let target = data.target;
@ -59,6 +64,7 @@ module.exports = function(irc, network) {
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
// Send notices that are not targeted at us into the server window // Send notices that are not targeted at us into the server window
if (data.type === Msg.Type.NOTICE) { if (data.type === Msg.Type.NOTICE) {
msg.showInActive = true;
chan = network.channels[0]; chan = network.channels[0];
} else { } else {
chan = new Chan({ chan = new Chan({
@ -73,49 +79,38 @@ module.exports = function(irc, network) {
} }
} }
user = chan.getUser(data.nick); msg.from = chan.getUser(data.nick);
// Query messages (unless self) always highlight // Query messages (unless self) always highlight
if (chan.type === Chan.Type.QUERY) { if (chan.type === Chan.Type.QUERY) {
highlight = !self; msg.highlight = !msg.self;
} else if (chan.type === Chan.Type.CHANNEL) { } else if (chan.type === Chan.Type.CHANNEL) {
user.lastMessage = data.time || Date.now(); msg.from.lastMessage = data.time || Date.now();
} }
} }
// Self messages in channels are never highlighted // Self messages in channels 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
if (!highlight && !self) { if (!msg.highlight && !msg.self) {
highlight = network.highlightRegex.test(data.message); msg.highlight = network.highlightRegex.test(data.message);
} }
const users = [];
let match; let match;
while ((match = nickRegExp.exec(data.message))) { while ((match = nickRegExp.exec(data.message))) {
if (chan.findUser(match[1])) { if (chan.findUser(match[1])) {
users.push(match[1]); msg.users.push(match[1]);
} }
} }
const msg = new Msg({
type: data.type,
time: data.time,
from: user,
text: data.message,
self: self,
highlight: highlight,
users: users,
});
// No prefetch URLs unless are simple MESSAGE or ACTION types // No prefetch URLs unless are simple MESSAGE or ACTION types
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].indexOf(data.type) !== -1) { if ([Msg.Type.MESSAGE, Msg.Type.ACTION].indexOf(data.type) !== -1) {
LinkPrefetch(client, chan, msg); LinkPrefetch(client, chan, msg);
} }
chan.pushMessage(client, msg, !self); chan.pushMessage(client, msg, !msg.self);
// Do not send notifications for messages older than 15 minutes (znc buffer for example) // Do not send notifications for messages older than 15 minutes (znc buffer for example)
if (highlight && (!data.time || data.time > Date.now() - 900000)) { if (msg.highlight && (!data.time || data.time > Date.now() - 900000)) {
let title = chan.name; let title = chan.name;
let body = cleanIrcMessage(data.message); let body = cleanIrcMessage(data.message);