From 1bf10a965f9131e8c7c831f77314e2c9d9c92733 Mon Sep 17 00:00:00 2001 From: cblgh Date: Sat, 23 Oct 2021 13:51:00 +0200 Subject: [PATCH] Revert "only add message listener when we're adding a new channel" This reverts commit 1dbd5227923aa9063b93b57cfa9dbed31e246dda. It seems this commit introduced a regression in functionality such that messages do not appear in channels (https://github.com/cabal-club/cabal-client/issues/78) and might also be responsible for a similar bug in cabal-desktop@6.0.8 It would be good to only add the relevant message listeners, instead of duplicates, but I think it will have to be done anew with fresh eyes. --- src/cabal-details.js | 5 +++-- src/initialization-callbacks.js | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cabal-details.js b/src/cabal-details.js index 972dae2..605d2bb 100644 --- a/src/cabal-details.js +++ b/src/cabal-details.js @@ -800,9 +800,10 @@ class CabalDetails extends EventEmitter { const details = this.channels[channel] if (!details) { this.channels[channel] = new ChannelDetails(cabal, channel) - // note: only add listener if we don't have a channel registered (=> prevent duplicate listeners) - cabal.messages.events.on(channel, this.messageListener.bind(this)) } + // TODO: only do this for our joined channels, instead of all channels + // Calls fn with every new message that arrives in channel. + cabal.messages.events.on(channel, this.messageListener.bind(this)) this._emitUpdate('new-channel', { channel }) }) } diff --git a/src/initialization-callbacks.js b/src/initialization-callbacks.js index fbb0ade..6c0dd9a 100644 --- a/src/initialization-callbacks.js +++ b/src/initialization-callbacks.js @@ -14,14 +14,13 @@ module.exports.getArchivesCallback = function (err, archivedChannels) { const details = this.channels[channel] if (!details) { this.channels[channel] = new ChannelDetails(cabal, channel) - // listen for updates that happen within the channel - // note: only add listener if we don't have a channel registered (=> prevent duplicate listeners) - cabal.messages.events.on(channel, this.messageListener.bind(this)) } // mark archived channels as such if (archivedChannels.indexOf(channel) >= 0) { this.channels[channel].archive() } + // listen for updates that happen within the channel + cabal.messages.events.on(channel, this.messageListener.bind(this)) // add all users joined to a channel cabal.memberships.getUsers(channel, (err, users) => {