Skip to content

Commit 09614f6

Browse files
authored
fix: remove the use of deprecated query operator $ne (#2504)
BREAKING CHANGE: - own user will not anymore be filtered out of the selection list of users to mention if `mentionAllAppUsers` is enabled on MessageInput
1 parent 8235d45 commit 09614f6

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/components/ChannelSearch/__tests__/ChannelSearch.test.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ describe('ChannelSearch', () => {
125125
});
126126

127127
it('search is performed by default on users and not channels', async () => {
128+
const limit = 8;
129+
const otherUsers = Array.from({ length: limit }, generateUser);
128130
jest.useFakeTimers('modern');
129131
const client = await getTestClientWithUser(user);
130-
jest.spyOn(client, 'queryUsers').mockResolvedValue({ users: [user] });
132+
jest.spyOn(client, 'queryUsers').mockResolvedValue({ users: [...otherUsers, user] });
131133
jest.spyOn(client, 'queryChannels').mockImplementation();
132134
const { typeText } = await renderSearch({ client });
133135
await act(() => {
@@ -141,21 +143,26 @@ describe('ChannelSearch', () => {
141143
expect(client.queryUsers).toHaveBeenCalledWith(
142144
expect.objectContaining({
143145
$or: [{ id: { $autocomplete: typedText } }, { name: { $autocomplete: typedText } }],
144-
id: { $ne: 'id' },
145146
}),
146147
{ id: 1 },
147-
{ limit: 8 },
148+
{ limit },
148149
);
149150
expect(client.queryUsers).toHaveBeenCalledTimes(1);
150151
expect(client.queryChannels).not.toHaveBeenCalled();
152+
otherUsers.forEach((user) => {
153+
expect(screen.queryByText(user.name)).toBeInTheDocument();
154+
});
155+
expect(screen.queryByText(user.name)).not.toBeInTheDocument();
151156

152157
jest.useRealTimers();
153158
});
154159

155160
it('search is performed on users and channels if enabled', async () => {
161+
const limit = 8;
162+
const otherUsers = Array.from({ length: limit }, generateUser);
156163
jest.useFakeTimers('modern');
157164
const client = await getTestClientWithUser(user);
158-
jest.spyOn(client, 'queryUsers').mockResolvedValue({ users: [user] });
165+
jest.spyOn(client, 'queryUsers').mockResolvedValue({ users: [...otherUsers, user] });
159166
jest.spyOn(client, 'queryChannels').mockResolvedValue([channelResponseData]);
160167

161168
const { typeText } = await renderSearch({ client, props: { searchForChannels: true } });
@@ -169,7 +176,10 @@ describe('ChannelSearch', () => {
169176

170177
expect(client.queryUsers).toHaveBeenCalledTimes(1);
171178
expect(client.queryChannels).toHaveBeenCalledTimes(1);
172-
179+
otherUsers.forEach((user) => {
180+
expect(screen.queryByText(user.name)).toBeInTheDocument();
181+
});
182+
expect(screen.queryByText(user.name)).not.toBeInTheDocument();
173183
jest.useRealTimers();
174184
});
175185

@@ -270,7 +280,6 @@ describe('ChannelSearch', () => {
270280
expect(client.queryUsers).toHaveBeenCalledWith(
271281
expect.objectContaining({
272282
$or: [{ id: { $autocomplete: textToQuery } }, { name: { $autocomplete: textToQuery } }],
273-
id: { $ne: 'id' },
274283
}),
275284
{ id: 1 },
276285
{ limit: 8 },
@@ -311,7 +320,6 @@ describe('ChannelSearch', () => {
311320
expect(client.queryUsers).toHaveBeenCalledWith(
312321
expect.objectContaining({
313322
$or: [{ id: { $autocomplete: textToQuery } }, { name: { $autocomplete: textToQuery } }],
314-
id: { $ne: 'id' },
315323
}),
316324
{ id: 1 },
317325
{ limit: 8 },

src/components/ChannelSearch/hooks/useChannelSearch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ export const useChannelSearch = <
216216
// @ts-expect-error
217217
{
218218
$or: [{ id: { $autocomplete: text } }, { name: { $autocomplete: text } }],
219-
id: { $ne: client.userID },
220219
...searchQueryParams?.userFilters?.filters,
221220
},
222221
{ id: 1, ...searchQueryParams?.userFilters?.sort },
@@ -226,7 +225,7 @@ export const useChannelSearch = <
226225
if (!searchForChannels) {
227226
searchQueryPromiseInProgress.current = userQueryPromise;
228227
const { users } = await searchQueryPromiseInProgress.current;
229-
results = users;
228+
results = users.filter((u) => u.id !== client.user?.id);
230229
} else {
231230
const channelQueryPromise = client.queryChannels(
232231
// @ts-expect-error
@@ -245,7 +244,7 @@ export const useChannelSearch = <
245244

246245
const [channels, { users }] = await searchQueryPromiseInProgress.current;
247246

248-
results = [...channels, ...users];
247+
results = [...channels, ...users.filter((u) => u.id !== client.user?.id)];
249248
}
250249
} catch (error) {
251250
console.error(error);

src/components/MessageInput/hooks/useUserTrigger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export const useUserTrigger = <
103103
// @ts-expect-error
104104
{
105105
$or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }],
106-
id: { $ne: client.userID },
107106
...(typeof mentionQueryParams.filters === 'function'
108107
? mentionQueryParams.filters(query)
109108
: mentionQueryParams.filters),

0 commit comments

Comments
 (0)