Skip to content

Commit

Permalink
Merge branch 'new/teams-back' into new/teams
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Mar 22, 2021
2 parents dce14da + 6f94e35 commit 1099ea6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
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
4 changes: 2 additions & 2 deletions app/models/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ export class Subscriptions extends Base {

return userSubs.map((sub) => {
const roomSub = rooms.find((r) => r._id === sub.rid);
sub.teamMain = roomSub.teamMain || false;
sub.teamId = roomSub.teamId || undefined;
sub.teamMain = roomSub?.teamMain || false;
sub.teamId = roomSub?.teamId || undefined;
return sub;
});
}
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

0 comments on commit 1099ea6

Please sign in to comment.