From e9a381102a7bf6023e544967db97cb1ba70c375b Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Mon, 12 Aug 2024 14:19:27 +0200 Subject: [PATCH] fix: remove ne filter from user/member query --- .../src/lib/channel.service.spec.ts | 8 +++++++- .../stream-chat-angular/src/lib/channel.service.ts | 6 ++++-- .../src/lib/chat-client.service.spec.ts | 13 ++++++++++--- .../src/lib/chat-client.service.ts | 3 +-- projects/stream-chat-angular/src/lib/mocks/index.ts | 5 +++++ 5 files changed, 27 insertions(+), 8 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 52f7fd35..74c24d89 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.spec.ts @@ -1857,7 +1857,13 @@ describe('ChannelService', () => { await init(); const channel = generateMockChannels(1)[0]; channel.cid = 'new-channel'; - spyOn(channel, 'queryMembers').and.callThrough(); + spyOn(channel, 'queryMembers').and.resolveTo({ + members: [ + { user_id: mockCurrentUser().id }, + { user_id: 'jack' }, + ] as unknown as ChannelMemberResponse[], + duration: '0ms', + }); const users = Array.from({ length: 101 }, (_, i) => ({ id: `${i}` })); channel.state.members = {} as any as Record< string, diff --git a/projects/stream-chat-angular/src/lib/channel.service.ts b/projects/stream-chat-angular/src/lib/channel.service.ts index aa8bf649..d3da017f 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.ts @@ -1063,9 +1063,11 @@ export class ChannelService< } const result = await activeChannel.queryMembers({ name: { $autocomplete: searchTerm }, - id: { $ne: this.chatClientService.chatClient.userID! }, } as UserFilters); // TODO: find out why we need typecast here - return Object.values(result.members); + + return result.members.filter( + (m) => m.user_id !== this.chatClientService.chatClient?.user?.id + ); } } diff --git a/projects/stream-chat-angular/src/lib/chat-client.service.spec.ts b/projects/stream-chat-angular/src/lib/chat-client.service.spec.ts index cdb47f5c..2822853f 100644 --- a/projects/stream-chat-angular/src/lib/chat-client.service.spec.ts +++ b/projects/stream-chat-angular/src/lib/chat-client.service.spec.ts @@ -319,8 +319,15 @@ describe('ChatClientService', () => { expect(mockChatClient.flagMessage).toHaveBeenCalledWith('messageId'); }); - it('should query members', async () => { - mockChatClient.queryUsers.and.returnValue({ users: [{}, {}] }); + it('should query users', async () => { + mockChatClient.queryUsers.and.returnValue({ + users: [ + { + id: mockCurrentUser().id, + }, + { id: 'zizi' }, + ], + }); const result = await service.autocompleteUsers('zi'); expect(mockChatClient.queryUsers).toHaveBeenCalledWith( @@ -332,7 +339,7 @@ describe('ChatClientService', () => { }) ); - expect(result.length).toBe(2); + expect(result.length).toBe(1); }); it('should initialize pending invites', async () => { diff --git a/projects/stream-chat-angular/src/lib/chat-client.service.ts b/projects/stream-chat-angular/src/lib/chat-client.service.ts index 635c2c62..60ab2e4f 100644 --- a/projects/stream-chat-angular/src/lib/chat-client.service.ts +++ b/projects/stream-chat-angular/src/lib/chat-client.service.ts @@ -230,9 +230,8 @@ export class ChatClientService< { id: { $autocomplete: searchTerm } }, { name: { $autocomplete: searchTerm } }, ], - id: { $ne: this.chatClient.userID! }, } as UserFilters); // TODO: find out why we need this typecast - return result.users; + return result.users.filter((u) => u.id !== this.chatClient?.user?.id); } private updatePendingInvites(e: Event) { diff --git a/projects/stream-chat-angular/src/lib/mocks/index.ts b/projects/stream-chat-angular/src/lib/mocks/index.ts index 25b8e2e9..bb439417 100644 --- a/projects/stream-chat-angular/src/lib/mocks/index.ts +++ b/projects/stream-chat-angular/src/lib/mocks/index.ts @@ -188,6 +188,11 @@ export const generateMockChannels = (length = 25) => { id: 'jack', }, }, + john: { + user: { + id: 'john', + }, + }, }, }), getConfig: () => ({