Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ API.v1.addRoute('teams.listRooms', { authRequired: true }, {
get() {
const { teamId } = this.queryParams;
const { offset, count } = this.getPaginationItems();
const { query } = this.parseJsonQuery();

const allowPrivateTeam = hasPermission(this.userId, 'view-all-teams');

Expand All @@ -136,7 +137,7 @@ API.v1.addRoute('teams.listRooms', { authRequired: true }, {
getAllRooms = true;
}

const { records, total } = Promise.await(Team.listRooms(this.userId, teamId, getAllRooms, allowPrivateTeam, { offset, count }));
const { records, total } = Promise.await(Team.listRooms(this.userId, teamId, getAllRooms, allowPrivateTeam, { offset, count }, { query }));

return API.v1.success({
rooms: records,
Expand Down
7 changes: 4 additions & 3 deletions app/models/server/raw/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ export class RoomsRaw extends BaseRaw {
return this.find(query, options);
}

findByTeamId(teamId, options = {}) {
const query = {
findByTeamId(teamId, options = {}, query = {}) {
const myQuery = {
...query,
teamId,
teamMain: {
$exists: false,
},
};

return this.find(query, options);
return this.find(myQuery, options);
}

findByTeamIdAndRoomsId(teamId, rids, options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion server/sdk/types/ITeamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ITeamService {
addRoom(uid: string, rid: string, teamId: string, isDefault: boolean): Promise<IRoom>;
addRooms(uid: string, rooms: Array<string>, teamId: string): Promise<Array<IRoom>>;
removeRoom(uid: string, rid: string, teamId: string, canRemoveAnyRoom: boolean): Promise<IRoom>;
listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, pagination: IPaginationOptions): Promise<IRecordsWithTotal<IRoom>>;
listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, pagination: IPaginationOptions, queryOptions: IQueryOptions<IRoom>): Promise<IRecordsWithTotal<IRoom>>;
listRoomsOfUser(uid: string, teamId: string, userId: string, allowPrivateTeam: boolean, pagination: IPaginationOptions): Promise<IRecordsWithTotal<IRoom>>;
updateRoom(uid: string, rid: string, isDefault: boolean, canUpdateAnyRoom: boolean): Promise<IRoom>;
list(uid: string, paginationOptions?: IPaginationOptions, queryOptions?: IQueryOptions<ITeam>): Promise<IRecordsWithTotal<ITeam>>;
Expand Down
6 changes: 3 additions & 3 deletions server/services/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class TeamService extends ServiceClass implements ITeamService {
};
}

async listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, { offset: skip, count: limit }: IPaginationOptions = { offset: 0, count: 50 }): Promise<IRecordsWithTotal<IRoom>> {
async listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, { offset: skip, count: limit }: IPaginationOptions = { offset: 0, count: 50 }, { query }: IQueryOptions<IRoom>): Promise<IRecordsWithTotal<IRoom>> {
if (!teamId) {
throw new Error('missing-teamId');
}
Expand All @@ -396,13 +396,13 @@ export class TeamService extends ServiceClass implements ITeamService {
throw new Error('user-not-on-private-team');
}
if (getAllRooms) {
const teamRoomsCursor = this.RoomsModel.findByTeamId(teamId, { skip, limit });
const teamRoomsCursor = this.RoomsModel.findByTeamId(teamId, { skip, limit }, query);
return {
total: await teamRoomsCursor.count(),
records: await teamRoomsCursor.toArray(),
};
}
const teamRooms = await this.RoomsModel.findByTeamId(teamId, { projection: { _id: 1, t: 1 } }).toArray();
const teamRooms = await this.RoomsModel.findByTeamId(teamId, { skip, limit, projection: { _id: 1, t: 1 } }, query).toArray();
const privateTeamRoomIds = teamRooms.filter((room) => room.t === 'p').map((room) => room._id);
const publicTeamRoomIds = teamRooms.filter((room) => room.t === 'c').map((room) => room._id);

Expand Down