Skip to content

Commit c426d27

Browse files
committed
requested changes
Signed-off-by: Abhinav Kumar <[email protected]>
1 parent 54b2597 commit c426d27

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

apps/meteor/app/api/server/v1/misc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ API.v1.addRoute(
364364
const sortBy = sort ? Object.keys(sort)[0] : undefined;
365365
const sortDirection = sort && Object.values(sort)[0] === 1 ? 'asc' : 'desc';
366366

367+
const user = await Users.findOneById(this.userId, { projection: { __rooms: 1 } });
367368
const result = await browseChannelsMethod(
368369
{
369370
...filter,
@@ -372,7 +373,7 @@ API.v1.addRoute(
372373
offset: Math.max(0, offset),
373374
limit: Math.max(0, count),
374375
},
375-
this.user,
376+
user,
376377
);
377378

378379
if (!result) {

apps/meteor/server/methods/browseChannels.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Team } from '@rocket.chat/core-services';
2-
import type { IRoom, IUser } from '@rocket.chat/core-typings';
2+
import type { IUser } from '@rocket.chat/core-typings';
33
import type { ServerMethods } from '@rocket.chat/ddp-client';
44
import { Rooms, Users, Subscriptions } from '@rocket.chat/models';
55
import { escapeRegExp } from '@rocket.chat/string-helpers';
@@ -45,7 +45,7 @@ const sortUsers = (field: string, direction: 'asc' | 'desc'): Record<string, Sor
4545
};
4646

4747
const getChannelsAndGroups = async (
48-
user: IUser & { __rooms?: IRoom['_id'][] },
48+
user: Pick<IUser, '_id' | '__rooms'>,
4949
canViewAnon: boolean,
5050
searchTerm: string,
5151
sort: Record<string, number>,
@@ -119,7 +119,7 @@ const getChannelsCountForTeam = mem((teamId) => Rooms.countByTeamId(teamId), {
119119
});
120120

121121
const getTeams = async (
122-
user: IUser,
122+
user: Pick<IUser, '_id' | '__rooms'>,
123123
searchTerm: string,
124124
sort: Record<string, number>,
125125
pagination: {
@@ -247,7 +247,7 @@ const findUsers = async ({
247247
};
248248

249249
const getUsers = async (
250-
user: IUser | undefined,
250+
user: Pick<IUser, '_id' | '__rooms'> | undefined,
251251
text: string,
252252
workspace: string,
253253
sort: Record<string, SortDirection>,
@@ -299,7 +299,7 @@ export const browseChannelsMethod = async (
299299
offset = 0,
300300
limit = 10,
301301
}: BrowseChannelsParams,
302-
user: IUser | undefined | null,
302+
user: Pick<IUser, '_id' | '__rooms'> | undefined | null,
303303
) => {
304304
const searchTerm = trim(escapeRegExp(text));
305305

@@ -333,8 +333,6 @@ export const browseChannelsMethod = async (
333333
return;
334334
}
335335

336-
user.__rooms = user.__rooms ?? (await Users.findOneById(user._id, { projection: { __rooms: 1 } }))?.__rooms ?? [];
337-
338336
switch (type) {
339337
case 'channels':
340338
return getChannelsAndGroups(user, canViewAnonymous, searchTerm, sortChannels(sortBy, sortDirection), pagination);

0 commit comments

Comments
 (0)