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
10 changes: 7 additions & 3 deletions app/api/server/lib/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export async function findAdminRooms({ uid, filter, types = [], pagination: { of
msgs: 1,
archived: 1,
tokenpass: 1,
teamId: 1,
teamMain: 1,
};

const name = filter && filter.trim();
Expand All @@ -39,12 +41,14 @@ export async function findAdminRooms({ uid, filter, types = [], pagination: { of
limit: count,
};

let cursor = Rooms.findByNameContaining(name, discussion, includeTeams, options);
let cursor;

if (name && showTypes.length) {
cursor = Rooms.findByNameContainingAndTypes(name, showTypes, discussion, options);
cursor = Rooms.findByNameContainingAndTypes(name, showTypes, discussion, includeTeams, options);
} else if (showTypes.length) {
cursor = Rooms.findByTypes(showTypes, discussion, options);
cursor = Rooms.findByTypes(showTypes, discussion, includeTeams, options);
} else {
cursor = Rooms.findByNameContaining(name, discussion, includeTeams, options);
}

const total = await cursor.count();
Expand Down
51 changes: 24 additions & 27 deletions app/models/server/raw/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ export class RoomsRaw extends BaseRaw {
return statistic;
}

findByNameContainingAndTypes(name, types, discussion = false, options = {}) {
findByNameContainingAndTypes(name, types, discussion = false, teams = false, options = {}) {
const nameRegex = new RegExp(escapeRegExp(name).trim(), 'i');

const teamCondition = teams ? {} : {
teamMain: {
$exists: false,
},
};

const query = {
t: {
$in: types,
Expand All @@ -56,57 +63,47 @@ export class RoomsRaw extends BaseRaw {
usernames: nameRegex,
},
],
...teamCondition,
};
return this.find(query, options);
}

findByTypes(types, discussion = false, options = {}) {
findByTypes(types, discussion = false, teams = false, options = {}) {
const teamCondition = teams ? {} : {
teamMain: {
$exists: false,
},
};

const query = {
t: {
$in: types,
},
prid: { $exists: discussion },
teamId: {
$exists: false,
},
...teamCondition,
};
return this.find(query, options);
}

findByNameContaining(name, discussion = false, teams = false, options = {}) {
const nameRegex = new RegExp(escapeRegExp(name).trim(), 'i');

const teamCondition = teams ? {
$or: [
{
teamId: {
$exists: false,
},
},
{
teamMain: true,
},
],
} : {
teamId: {
const teamCondition = teams ? {} : {
teamMain: {
$exists: false,
},
};

const query = {
prid: { $exists: discussion },
$and: [
$or: [
{ name: nameRegex },
{
$or: [
{ name: nameRegex },
{
t: 'd',
usernames: nameRegex,
},
],
t: 'd',
usernames: nameRegex,
},
teamCondition,
],
...teamCondition,
};

return this.find(query, options);
Expand Down