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
35 changes: 35 additions & 0 deletions app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,41 @@ export class Rooms extends Base {
return this._db.find(query, options);
}

findByNameOrFNameAndTypeIncludingTeamRooms(name, type, teamIds, options) {
const query = {
t: type,
teamMain: {
$exists: false,
},
$and: [
{
$or: [
{
teamId: {
$exists: false,
},
},
{
teamId: {
$in: teamIds,
},
},
],
},
{
$or: [{
name,
}, {
fname: name,
}],
},
],
};

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

findContainingNameOrFNameInIdsAsTeamMain(text, rids, options) {
const query = {
teamMain: true,
Expand Down
4 changes: 4 additions & 0 deletions app/models/server/raw/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class TeamRaw extends BaseRaw<T> {
return this.col.find({ _id: { $in: ids }, type }, options);
}

findByType(type: number, options?: FindOneOptions<T>): Cursor<T> {
return this.col.find({ type }, options);
}

findByNameAndTeamIds(name: string | RegExp, teamIds: Array<string>, options?: FindOneOptions<T>): Cursor<T> {
return this.col.find({
name,
Expand Down
6 changes: 5 additions & 1 deletion client/views/directory/ChannelsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function ChannelsTable() {
<GenericTable.HeaderCell key={'usersCount'} direction={sort[1]} active={sort[0] === 'usersCount'} onClick={onHeaderClick} sort='usersCount' style={{ width: '100px' }}>{t('Users')}</GenericTable.HeaderCell>,
mediaQuery && <GenericTable.HeaderCell key={'createdAt'} direction={sort[1]} active={sort[0] === 'createdAt'} onClick={onHeaderClick} sort='createdAt' style={{ width: '150px' }}>{t('Created_at')}</GenericTable.HeaderCell>,
mediaQuery && <GenericTable.HeaderCell key={'lastMessage'} direction={sort[1]} active={sort[0] === 'lastMessage'} onClick={onHeaderClick} sort='lastMessage' style={{ width: '150px' }}>{t('Last_Message')}</GenericTable.HeaderCell>,
mediaQuery && <GenericTable.HeaderCell key={'belongsTo'} direction={sort[1]} active={sort[0] === 'belongsTo'} onClick={onHeaderClick} sort='belongsTo' style={{ width: '150px' }}>{t('Belongs_To')}</GenericTable.HeaderCell>,
].filter(Boolean), [sort, onHeaderClick, t, mediaQuery]);

const channelRoute = useRoute('channel');
Expand All @@ -65,7 +66,7 @@ function ChannelsTable() {

const formatDate = useFormatDate();
const renderRow = useCallback((room) => {
const { _id, ts, t, name, fname, usersCount, lastMessage, topic } = room;
const { _id, ts, t, name, fname, usersCount, lastMessage, topic, belongsTo } = room;
const avatarUrl = roomTypes.getConfig(t).getAvatarPath(room);

return <Table.Row key={_id} onKeyDown={onClick(name)} onClick={onClick(name)} tabIndex={0} role='link' action>
Expand All @@ -91,6 +92,9 @@ function ChannelsTable() {
{ mediaQuery && <Table.Cell fontScale='p1' color='hint' style={style}>
{lastMessage && formatDate(lastMessage.ts)}
</Table.Cell>}
{ mediaQuery && <Table.Cell fontScale='p1' color='hint' style={style}>
{belongsTo}
</Table.Cell>}
</Table.Row>;
}
, [formatDate, mediaQuery, onClick]);
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@
"BBB_Start_Meeting": "Start Meeting",
"BBB_Video_Call": "BBB Video Call",
"BBB_You_have_no_permission_to_start_a_call": "You have no permission to start a call",
"Belongs_To": "Belongs To",
"Best_first_response_time": "Best first response time",
"Beta_feature_Depends_on_Video_Conference_to_be_enabled": "Beta feature. Depends on Video Conference to be enabled.",
"Better": "Better",
Expand Down
24 changes: 21 additions & 3 deletions server/methods/browseChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getFederationDomain } from '../../app/federation/server/lib/getFederati
import { isFederationEnabled } from '../../app/federation/server/lib/isFederationEnabled';
import { federationSearchUsers } from '../../app/federation/server/handler';
import { escapeRegExp } from '../../lib/escapeRegExp';
import { Team } from '../sdk';

const sortChannels = function(field, direction) {
switch (field) {
Expand Down Expand Up @@ -48,7 +49,10 @@ const getChannels = (user, canViewAnon, searchTerm, sort, pagination) => {
return;
}

const result = Rooms.findByNameOrFNameAndType(searchTerm, 'c', {
const teams = Promise.await(Team.getAllPublicTeams());
const teamIds = teams.map(({ _id }) => _id);

const result = Rooms.findByNameOrFNameAndTypeIncludingTeamRooms(searchTerm, 'c', teamIds, {
...pagination,
sort: {
featured: -1,
Expand All @@ -67,12 +71,26 @@ const getChannels = (user, canViewAnon, searchTerm, sort, pagination) => {
featured: 1,
usersCount: 1,
prid: 1,
teamId: 1,
},
});

const total = result.count(); // count ignores the `skip` and `limit` options
const results = result.fetch().map((room) => {
if (room.teamId) {
const team = teams.find((team) => team._id === room.teamId);
if (team) {
room.belongsTo = team.name;
}
}
return room;
});

console.log(results);

return {
total: result.count(), // count ignores the `skip` and `limit` options
results: result.fetch(),
total,
results,
};
};

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 @@ -67,4 +67,5 @@ export interface ITeamService {
getOneByRoomId(teamId: string): Promise<ITeam | undefined>;
getMatchingTeamRooms(teamId: string, rids: Array<string>): Promise<Array<string>>;
autocomplete(uid: string, name: string): Promise<Array<IRoom>>;
getAllPublicTeams(options: FindOneOptions<ITeam>): Promise<Array<ITeam>>;
}
4 changes: 4 additions & 0 deletions server/services/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ export class TeamService extends ServiceClass implements ITeamService {
return !!await this.TeamModel.deleteOneByName(teamName);
}

async getAllPublicTeams(options: FindOneOptions<ITeam>): Promise<Array<ITeam>> {
return this.TeamModel.findByType(TEAM_TYPE.PUBLIC, options).toArray();
}

async getStatistics(): Promise<ITeamStats> {
const stats = {} as ITeamStats;
const teams = this.TeamModel.find({});
Expand Down