From 0d209fce090bda218087d18160b4c022697bf728 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Wed, 29 Dec 2021 15:46:06 +0100 Subject: [PATCH 1/2] Clear obsolete mentions upon channel part Currently, the mentions only track the chanID and MsgID. However, when we part a channel the chanID becomes orphaned. Considering that mentions from a parted channel probably aren't that relevant, let's automatically clear them when we part. Should the user really want to look at them again, they can re-join the channel and get the scroll back that way. --- src/client.js | 11 +++++++++++ src/plugins/inputs/part.js | 8 +------- src/plugins/irc-events/part.js | 8 +------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/client.js b/src/client.js index 4a8aa080..309d820c 100644 --- a/src/client.js +++ b/src/client.js @@ -649,6 +649,17 @@ Client.prototype.names = function (data) { }); }; +Client.prototype.part = function (network, chan) { + const client = this; + network.channels = _.without(network.channels, chan); + client.mentions = client.mentions.filter((msg) => !(msg.chanId === chan.id)); + chan.destroy(); + client.save(); + client.emit("part", { + chan: chan.id, + }); +}; + Client.prototype.quit = function (signOut) { const sockets = this.manager.sockets.sockets; const room = sockets.adapter.rooms.get(this.id); diff --git a/src/plugins/inputs/part.js b/src/plugins/inputs/part.js index d4ba095a..988dfba5 100644 --- a/src/plugins/inputs/part.js +++ b/src/plugins/inputs/part.js @@ -1,6 +1,5 @@ "use strict"; -const _ = require("lodash"); const Msg = require("../../models/msg"); const Chan = require("../../models/chan"); const Helper = require("../../helper"); @@ -41,12 +40,7 @@ exports.input = function (network, chan, cmd, args) { !network.irc.connection || !network.irc.connection.connected ) { - network.channels = _.without(network.channels, target); - target.destroy(); - this.emit("part", { - chan: target.id, - }); - this.save(); + this.part(network, target); } else { const partMessage = args.join(" ") || network.leaveMessage || Helper.config.leaveMessage; network.irc.part(target.name, partMessage); diff --git a/src/plugins/irc-events/part.js b/src/plugins/irc-events/part.js index a82d4e24..25c698cf 100644 --- a/src/plugins/irc-events/part.js +++ b/src/plugins/irc-events/part.js @@ -1,6 +1,5 @@ "use strict"; -const _ = require("lodash"); const Msg = require("../../models/msg"); module.exports = function (irc, network) { @@ -25,12 +24,7 @@ module.exports = function (irc, network) { chan.pushMessage(client, msg); if (data.nick === irc.user.nick) { - network.channels = _.without(network.channels, chan); - chan.destroy(); - client.save(); - client.emit("part", { - chan: chan.id, - }); + client.part(network, chan); } else { chan.removeUser(user); } From e999171f291ddbe93c46a78e977299c587931a5e Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Wed, 29 Dec 2021 16:31:44 +0100 Subject: [PATCH 2/2] Mentions window: filter list when we part a chan Should some other client part a chan, then we need to clean up the list from the mentions window in case it's open in ours. --- client/js/socket-events/part.js | 14 +++++++++----- client/js/store.js | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/js/socket-events/part.js b/client/js/socket-events/part.js index 58be3a57..7706f41c 100644 --- a/client/js/socket-events/part.js +++ b/client/js/socket-events/part.js @@ -12,10 +12,14 @@ socket.on("part", function (data) { const channel = store.getters.findChannel(data.chan); - if (channel) { - channel.network.channels.splice( - channel.network.channels.findIndex((c) => c.id === data.chan), - 1 - ); + if (!channel) { + return; } + + channel.network.channels.splice( + channel.network.channels.findIndex((c) => c.id === data.chan), + 1 + ); + + store.dispatch("partChannel", channel); }); diff --git a/client/js/store.js b/client/js/store.js index 83ce7f86..53659934 100644 --- a/client/js/store.js +++ b/client/js/store.js @@ -130,6 +130,12 @@ const store = new Vuex.Store({ state.messageSearchResults = value; }, }, + actions: { + partChannel({commit, state}, netChan) { + const mentions = state.mentions.filter((msg) => !(msg.chanId === netChan.channel.id)); + commit("mentions", mentions); + }, + }, getters: { findChannelOnCurrentNetwork: (state) => (name) => { name = name.toLowerCase();