Skip to content

Commit

Permalink
only add message listener when we're adding a new channel
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed May 1, 2021
1 parent 6d63875 commit 1dbd522
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/cabal-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,9 @@ 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 })
})
}
Expand Down
5 changes: 3 additions & 2 deletions src/initialization-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ 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) => {
Expand Down

0 comments on commit 1dbd522

Please sign in to comment.