Show notices and errors inline

This commit is contained in:
Pavel Djundik 2017-07-28 11:53:36 +03:00
parent 3df1e9d731
commit 5e48e04623
3 changed files with 43 additions and 29 deletions

View File

@ -27,11 +27,27 @@ socket.on("msg", function(data) {
});
function processReceivedMessage(data) {
const targetId = data.chan;
const target = "#chan-" + targetId;
const channel = chat.find(target);
const container = channel.find(".messages");
let targetId = data.chan;
let target = "#chan-" + targetId;
let channel = chat.find(target);
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");
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
if (data.msg.self) {
sidebar.find("[data-target='" + target + "'] .badge").removeClass("highlight").empty();
sidebarTarget.find(".badge").removeClass("highlight").empty();
}
let messageLimit = 0;
@ -82,7 +98,7 @@ function processReceivedMessage(data) {
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");
if (nicks) {
const find = nicks.indexOf(data.msg.from.nick);

View File

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

View File

@ -38,14 +38,19 @@ module.exports = function(irc, network) {
function handleMessage(data) {
let chan;
let user;
let highlight = false;
const self = data.nick === irc.user.nick;
const msg = new Msg({
type: data.type,
time: data.time,
text: data.message,
self: data.nick === irc.user.nick,
highlight: false,
users: [],
});
// Server messages go to server window, no questions asked
if (data.from_server) {
chan = network.channels[0];
user = chan.getUser(data.nick);
msg.from = chan.getUser(data.nick);
} else {
let target = data.target;
@ -59,6 +64,7 @@ module.exports = function(irc, network) {
if (typeof chan === "undefined") {
// Send notices that are not targeted at us into the server window
if (data.type === Msg.Type.NOTICE) {
msg.showInActive = true;
chan = network.channels[0];
} else {
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
if (chan.type === Chan.Type.QUERY) {
highlight = !self;
msg.highlight = !msg.self;
} 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
// Non-self messages are highlighted as soon as the nick is detected
if (!highlight && !self) {
highlight = network.highlightRegex.test(data.message);
if (!msg.highlight && !msg.self) {
msg.highlight = network.highlightRegex.test(data.message);
}
const users = [];
let match;
while ((match = nickRegExp.exec(data.message))) {
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
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].indexOf(data.type) !== -1) {
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)
if (highlight && (!data.time || data.time > Date.now() - 900000)) {
if (msg.highlight && (!data.time || data.time > Date.now() - 900000)) {
let title = chan.name;
let body = cleanIrcMessage(data.message);