From c655e6e909cf0525ca24f83a71e649f530bccd29 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Mon, 20 Nov 2023 13:44:02 +0100 Subject: [PATCH] fix: offset parameter --- .../stream-chat-angular/src/lib/channel.service.spec.ts | 6 +++++- projects/stream-chat-angular/src/lib/channel.service.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/stream-chat-angular/src/lib/channel.service.spec.ts b/projects/stream-chat-angular/src/lib/channel.service.spec.ts index 8d289d5a..89076ffa 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.spec.ts @@ -114,7 +114,7 @@ describe('ChannelService', () => { }); it('should use provided options params', async () => { - const options: ChannelOptions = { offset: 5 }; + const options: ChannelOptions = { limit: 5 }; await init(undefined, undefined, options); expect(mockChatClient.queryChannels).toHaveBeenCalledWith( @@ -373,6 +373,10 @@ describe('ChannelService', () => { it('should load more channels and filter duplicates', async () => { await init(); + + // Check that offset is set properly after query + expect(service['options']?.offset).toEqual(service.channels.length); + mockChatClient.queryChannels.calls.reset(); const existingChannel = service.channels[0]; const newChannel = generateMockChannels(1)[0]; diff --git a/projects/stream-chat-angular/src/lib/channel.service.ts b/projects/stream-chat-angular/src/lib/channel.service.ts index c496f0a4..89258ed9 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.ts @@ -696,7 +696,6 @@ export class ChannelService< * Loads the next page of channels. The page size can be set in the [query option](https://getstream.io/chat/docs/javascript/query_channels/?language=javascript#query-options) object. */ async loadMoreChannels() { - this.options!.offset = this.channels.length!; await this.queryChannels(false); } @@ -1486,6 +1485,7 @@ export class ChannelService< this.sort || {}, this.options ); + this.options!.offset = channels.length!; channels.forEach((c) => this.watchForChannelEvents(c)); const prevChannels = recoverState ? []