Skip to content

Commit

Permalink
Merge pull request #626 from GetStream/remove-ne-filter
Browse files Browse the repository at this point in the history
fix: remove ne filter from user/member query
  • Loading branch information
szuperaz authored Aug 12, 2024
2 parents d50d872 + e9a3811 commit 04abd70
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
8 changes: 7 additions & 1 deletion projects/stream-chat-angular/src/lib/channel.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultStreamChatGenerics>[],
duration: '0ms',
});
const users = Array.from({ length: 101 }, (_, i) => ({ id: `${i}` }));
channel.state.members = {} as any as Record<
string,
Expand Down
6 changes: 4 additions & 2 deletions projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,9 +1063,11 @@ export class ChannelService<
}
const result = await activeChannel.queryMembers({
name: { $autocomplete: searchTerm },
id: { $ne: this.chatClientService.chatClient.userID! },
} as UserFilters<T>); // 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
);
}
}

Expand Down
13 changes: 10 additions & 3 deletions projects/stream-chat-angular/src/lib/chat-client.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -332,7 +339,7 @@ describe('ChatClientService', () => {
})
);

expect(result.length).toBe(2);
expect(result.length).toBe(1);
});

it('should initialize pending invites', async () => {
Expand Down
3 changes: 1 addition & 2 deletions projects/stream-chat-angular/src/lib/chat-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ export class ChatClientService<
{ id: { $autocomplete: searchTerm } },
{ name: { $autocomplete: searchTerm } },
],
id: { $ne: this.chatClient.userID! },
} as UserFilters<T>); // 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<T>) {
Expand Down
5 changes: 5 additions & 0 deletions projects/stream-chat-angular/src/lib/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ export const generateMockChannels = (length = 25) => {
id: 'jack',
},
},
john: {
user: {
id: 'john',
},
},
},
}),
getConfig: () => ({
Expand Down

0 comments on commit 04abd70

Please sign in to comment.