Skip to content

Commit

Permalink
General improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed May 12, 2021
1 parent 2578b5d commit 0749ffd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
35 changes: 18 additions & 17 deletions app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,39 +552,40 @@ export class Rooms extends Base {
return this._db.find(query, options);
}

findByNameOrFNameAndRoomIdsIncludingTeamRooms(name, teamIds, roomIds, options) {
findByNameOrFNameAndRoomIdsIncludingTeamRooms(text, teamIds, roomIds, options) {
const searchTerm = text && new RegExp(text, 'i');

const query = {
teamMain: {
$exists: false,
},
$and: [
{ teamMain: { $exists: false } },
{ prid: { $exists: false } },
{
$or: [
roomIds ? { _id: { $in: roomIds }, t: 'p' } : false,
{
t: 'c',
teamId: {
$exists: false,
},
teamId: { $exists: false },
},
{
teamId: {
$in: teamIds,
},
t: 'c',
teamId: { $in: teamIds },
},
...roomIds?.length > 0 ? [{
_id: {
$in: roomIds,
},
}] : [],
],
},
{
...searchTerm ? [{
$or: [{
name,
name: searchTerm,
}, {
fname: name,
fname: searchTerm,
}],
},
}] : [],
],
};

// do not use cache
return this._db.find(query, options);
}

Expand All @@ -604,7 +605,7 @@ export class Rooms extends Base {
};

if (text) {
const regex = new RegExp(s.trim(escapeRegExp(text)), 'i');
const regex = new RegExp(text, 'i');

query.$and.push({
$or: [{
Expand Down
11 changes: 6 additions & 5 deletions client/views/directory/ChannelsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ function ChannelsTable() {
);

const channelRoute = useRoute('channel');
const groupsRoute = useRoute('group');

const { value: data = { result: [] } } = useEndpointData('directory', query);

const onClick = useMemo(
() => (name) => (e) => {
() => (name, type) => (e) => {
if (e.type === 'click' || e.key === 'Enter') {
channelRoute.push({ name });
type === 'c' ? channelRoute.push({ name }) : groupsRoute.push({ name });
}
},
[channelRoute],
[channelRoute, groupsRoute],
);

const formatDate = useFormatDate();
Expand All @@ -122,8 +123,8 @@ function ChannelsTable() {
return (
<Table.Row
key={_id}
onKeyDown={onClick(name)}
onClick={onClick(name)}
onKeyDown={onClick(name, t)}
onClick={onClick(name, t)}
tabIndex={0}
role='link'
action
Expand Down
10 changes: 6 additions & 4 deletions server/methods/browseChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ const getChannelsAndGroups = (user, canViewAnon, searchTerm, sort, pagination) =

const teams = Promise.await(Team.getAllPublicTeams());
const teamIds = teams.map(({ _id }) => _id);

const userTeams = Promise.await(Team.listTeamsBySubscriberUserId(user._id, { projection: { teamId: 1 } }))?.map(({ teamId }) => teamId) || [];
const userRooms = user.__rooms;

const result = Rooms.findByNameOrFNameAndRoomIdsIncludingTeamRooms(searchTerm, teamIds, userRooms, {
const result = Rooms.findByNameOrFNameAndRoomIdsIncludingTeamRooms(searchTerm, [...userTeams, ...teamIds], userRooms, {
...pagination,
sort: {
featured: -1,
Expand Down Expand Up @@ -203,7 +205,7 @@ const getUsers = (user, text, workspace, sort, pagination) => {

Meteor.methods({
browseChannels({ text = '', workspace = '', type = 'channels', sortBy = 'name', sortDirection = 'asc', page, offset, limit = 10 }) {
const regex = new RegExp(s.trim(escapeRegExp(text)), 'i');
const searchTerm = s.trim(escapeRegExp(text));

if (!['channels', 'users', 'teams'].includes(type) || !['asc', 'desc'].includes(sortDirection) || ((!page && page !== 0) && (!offset && offset !== 0))) {
return;
Expand Down Expand Up @@ -231,9 +233,9 @@ Meteor.methods({

switch (type) {
case 'channels':
return getChannelsAndGroups(user, canViewAnonymous, regex, sortChannels(sortBy, sortDirection), pagination);
return getChannelsAndGroups(user, canViewAnonymous, searchTerm, sortChannels(sortBy, sortDirection), pagination);
case 'teams':
return getTeams(user, text, sortChannels(sortBy, sortDirection), pagination);
return getTeams(user, searchTerm, sortChannels(sortBy, sortDirection), pagination);
case 'users':
return getUsers(user, text, workspace, sortUsers(sortBy, sortDirection), pagination);
default:
Expand Down
1 change: 1 addition & 0 deletions server/sdk/types/ITeamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ export interface ITeamService {
getAllPublicTeams(options: FindOneOptions<ITeam>): Promise<Array<ITeam>>;
getMembersByTeamIds(teamIds: Array<string>, options: FindOneOptions<ITeamMember>): Promise<Array<ITeamMember>>;
update(uid: string, teamId: string, updateData: ITeamUpdateData): Promise<void>;
listTeamsBySubscriberUserId(uid: string, options?: FindOneOptions<ITeamMember>): Promise<Array<ITeamMember> | null>;
}

0 comments on commit 0749ffd

Please sign in to comment.