From 94e6cac444c96db83d26401359eef592193d100b Mon Sep 17 00:00:00 2001 From: martincupela Date: Tue, 24 Oct 2023 11:00:23 +0200 Subject: [PATCH] Revert "fix: queue channel WS events until the channel is initialized (#1179)" This reverts commit 2073579e --- src/channel.ts | 25 ------------ src/events.ts | 25 ------------ test/unit/channel.js | 83 ++------------------------------------ test/unit/channel_state.js | 1 - 4 files changed, 3 insertions(+), 131 deletions(-) diff --git a/src/channel.ts b/src/channel.ts index 7ed79e98a..bcadbeac8 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -89,12 +89,6 @@ export class Channel[]; /** * constructor - Create a channel @@ -138,7 +132,6 @@ export class Channel) { const channel = this; - - if (!this._isInitialized()) { - this.wsEventQueue.push(event); - return; - } - this._client.logger( 'info', `channel:_handleChannelEvent - Received event of type { ${event.type} } on ${this.cid}`, @@ -1455,10 +1441,6 @@ export class Channel { user = { id: 'user' }; lastRead = new Date('2020-01-01T00:00:00'); + const channelResponse = generateChannel(); client = new StreamChat('apiKey'); client.user = user; client.userID = 'user'; client.userMuteStatus = (targetId) => targetId.startsWith('mute'); - const channelResponse = generateChannel(); channel = client.channel(channelResponse.channel.type, channelResponse.channel.id); channel.initialized = true; channel.lastRead = () => lastRead; @@ -532,83 +532,6 @@ describe('Channel _handleChannelEvent', function () { }); }); -describe('Channel WS events buffer', () => { - const user = { id: 'user' }; - let client; - let channel; - - beforeEach(() => { - client = new StreamChat('apiKey'); - client.user = user; - client.userID = user.id; - client.userMuteStatus = (targetId) => targetId.startsWith('mute'); - channel = client.channel('messaging', 'id'); - channel.initialized = false; - }); - - const eventTypes = Object.keys(CHANNEL_HANDLED_EVENTS); - const receiveAllChannelEvents = (channel) => { - eventTypes.forEach((type) => { - channel._handleChannelEvent({ type }); - }); - }; - - it('when uninitialized', () => { - receiveAllChannelEvents(channel); - - expect(channel.wsEventQueue).to.have.length(eventTypes.length); - }); - - it('does not buffer WS events when in offline mode', () => { - channel.offlineMode = true; - - receiveAllChannelEvents(channel); - - expect(channel.wsEventQueue).to.be.empty; - }); - - it('does not buffer WS events with server-side client', () => { - client = new StreamChat('apiKey', 'secret'); - client.user = user; - client.userID = user.id; - channel = client.channel('messaging', 'id'); - - receiveAllChannelEvents(channel); - - expect(channel.wsEventQueue).to.be.empty; - }); - - it('does not buffer WS events on initialized channel', () => { - channel.initialized = true; - - receiveAllChannelEvents(channel); - - expect(channel.wsEventQueue).to.be.empty; - }); - - it('buffers WS events and channel.watch() flushes upon channel initialization', async () => { - sinon.stub(client, 'doAxiosRequest').resolves({ channel: generateChannel(), members: [] }); - - receiveAllChannelEvents(channel); - - expect(channel.wsEventQueue).to.have.length(eventTypes.length); - await channel.watch(); - expect(channel.wsEventQueue).to.be.empty; - client.doAxiosRequest.restore(); - }); - - it('buffers WS events and channel.query() does not flush the queue', async () => { - sinon.stub(client, 'doAxiosRequest').resolves({ channel: generateChannel(), members: [] }); - - receiveAllChannelEvents(channel); - - expect(channel.wsEventQueue).to.have.length(eventTypes.length); - await channel.query(); - expect(channel.wsEventQueue).to.have.length(eventTypes.length); - client.doAxiosRequest.restore(); - }); -}); - describe('Uninitialized Channel', () => { const user = { id: 'user' }; let client; diff --git a/test/unit/channel_state.js b/test/unit/channel_state.js index 171471abf..5e7dc7b2b 100644 --- a/test/unit/channel_state.js +++ b/test/unit/channel_state.js @@ -645,7 +645,6 @@ describe('ChannelState clean', () => { client.userID = 'observer'; channel = new Channel(client, 'live', 'stream', {}); client.activeChannels[channel.cid] = channel; - channel.initialized = true; }); it('should remove any stale typing events with either string or Date received_at', async () => {