diff --git a/app/models/server/models/Rooms.js b/app/models/server/models/Rooms.js index 3208a1130ad..7cf1ce7585f 100644 --- a/app/models/server/models/Rooms.js +++ b/app/models/server/models/Rooms.js @@ -600,9 +600,16 @@ export class Rooms extends Base { default: { $ne: true, }, - teamId: { - $exists: false, - }, + $or: [ + { + teamId: { + $exists: false, + }, + }, + { + teamMain: true, + }, + ], }; // do not use cache @@ -631,6 +638,12 @@ export class Rooms extends Base { $in: ids, }, }, + { + // Also return the main room of public teams + // this will have no effect if the method is called without the 'c' type, as the type filter is outside the $or group. + teamMain: true, + t: 'c', + }, ], name, }; diff --git a/app/ui-message/client/popup/messagePopupConfig.js b/app/ui-message/client/popup/messagePopupConfig.js index 029c44410b3..3fda1c15e6c 100644 --- a/app/ui-message/client/popup/messagePopupConfig.js +++ b/app/ui-message/client/popup/messagePopupConfig.js @@ -61,7 +61,7 @@ const reloadUsersFromRoomMessages = (rid, template) => { const fetchUsersFromServer = _.throttle(async (filterText, records, rid, cb) => { const usernames = records.map(({ username }) => username); - const { users } = await call('spotlight', filterText, usernames, { users: true }, rid); + const { users } = await call('spotlight', filterText, usernames, { users: true, mentions: true }, rid); if (!users || users.length <= 0) { return; @@ -95,7 +95,7 @@ const fetchRoomsFromServer = _.throttle(async (filterText, records, rid, cb) => return; } - const { rooms } = await call('spotlight', filterText, null, { rooms: true }, rid); + const { rooms } = await call('spotlight', filterText, null, { rooms: true, mentions: true }, rid); if (!rooms || rooms.length <= 0) { return; diff --git a/ee/app/teams-mention/server/EESpotlight.js b/ee/app/teams-mention/server/EESpotlight.js index 3587c460a89..49fd7c007b5 100644 --- a/ee/app/teams-mention/server/EESpotlight.js +++ b/ee/app/teams-mention/server/EESpotlight.js @@ -10,7 +10,11 @@ export const SpotlightEnterprise = { }); }, - _searchTeams(_, userId, { text, options, users }) { + _searchTeams(_, userId, { text, options, users, mentions }) { + if (!mentions) { + return users; + } + options.limit -= users.length; if (options.limit <= 0) { diff --git a/server/lib/spotlight.js b/server/lib/spotlight.js index fe7aebeb514..9cfe65cced6 100644 --- a/server/lib/spotlight.js +++ b/server/lib/spotlight.js @@ -181,7 +181,7 @@ export class Spotlight { // Overwrite this method to include extra searches } - searchUsers({ userId, rid, text, usernames }) { + searchUsers({ userId, rid, text, usernames, mentions }) { const users = []; const options = { @@ -252,6 +252,7 @@ export class Spotlight { users, canListOutsiders, insiderExtraQuery, + mentions, }; // Exact match for username only diff --git a/server/publications/spotlight.js b/server/publications/spotlight.js index 956ffbe6932..afb3a3e91ba 100644 --- a/server/publications/spotlight.js +++ b/server/publications/spotlight.js @@ -4,8 +4,9 @@ import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; import { Spotlight } from '../lib/spotlight'; Meteor.methods({ - spotlight(text, usernames = [], type = { users: true, rooms: true }, rid) { + spotlight(text, usernames = [], type = { users: true, rooms: true, mentions: false }, rid) { const spotlight = new Spotlight(); + const { mentions } = type; if (text.startsWith('#')) { type.users = false; @@ -20,7 +21,7 @@ Meteor.methods({ const { userId } = this; return { - users: type.users ? spotlight.searchUsers({ userId, rid, text, usernames }) : [], + users: type.users ? spotlight.searchUsers({ userId, rid, text, usernames, mentions }) : [], rooms: type.rooms ? spotlight.searchRooms({ userId, text }) : [], }; },