Skip to content
Snippets Groups Projects
Unverified Commit 258e9b33 authored by Heitor Tanoue's avatar Heitor Tanoue Committed by GitHub
Browse files

chore: move team mentions to ce (#30175)

parent bb3a0d42
No related branches found
No related tags found
No related merge requests found
import { Team } from '@rocket.chat/core-services';
import type { IMessage } from '@rocket.chat/core-typings';
import { callbacks } from '../../../lib/callbacks';
interface IExtraDataForNotification {
userMentions: any[];
otherMentions: any[];
message: IMessage;
}
callbacks.add('beforeGetMentions', async (mentionIds: string[], extra?: IExtraDataForNotification) => {
const { otherMentions } = extra ?? {};
const teamIds = otherMentions?.filter(({ type }) => type === 'team').map(({ _id }) => _id);
if (!teamIds?.length) {
return mentionIds;
}
const members = await Team.getMembersByTeamIds(teamIds, { projection: { userId: 1 } });
mentionIds.push(...new Set(members.map(({ userId }) => userId).filter((userId) => !mentionIds.includes(userId))));
return mentionIds;
});
import './server';
import './getMentionedTeamMembers';
import './methods/getUserMentionsByChannel';
import './server';
import { api } from '@rocket.chat/core-services';
import type { IUser, IRoom } from '@rocket.chat/core-typings';
import { api, Team } from '@rocket.chat/core-services';
import type { IUser, IRoom, ITeam } from '@rocket.chat/core-typings';
import { Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
......@@ -9,16 +9,28 @@ import { settings } from '../../settings/server';
import MentionsServer from './Mentions';
export class MentionQueries {
async getUsers(usernames: string[]): Promise<(Pick<IUser, '_id' | 'username' | 'name'> & { type: 'user' })[]> {
async getUsers(
usernames: string[],
): Promise<((Pick<IUser, '_id' | 'username' | 'name'> & { type: 'user' }) | (Pick<ITeam, '_id' | 'name'> & { type: 'team' }))[]> {
const uniqueUsernames = [...new Set(usernames)];
const teams = await Team.listByNames(uniqueUsernames, { projection: { name: 1 } });
const users = await Users.find(
{ username: { $in: [...new Set(usernames)] } },
{ username: { $in: uniqueUsernames } },
{ projection: { _id: true, username: true, name: 1 } },
).toArray();
return users.map((user) => ({
const taggedUsers = users.map((user) => ({
...user,
type: 'user',
type: 'user' as const,
}));
const taggedTeams = teams.map((team) => ({
...team,
type: 'team' as const,
}));
return [...taggedUsers, ...taggedTeams];
}
async getUser(userId: string): Promise<IUser | null> {
......
......@@ -8,7 +8,6 @@ export type BundleFeature =
| 'engagement-dashboard'
| 'push-privacy'
| 'scalability'
| 'teams-mention'
| 'saml-enterprise'
| 'device-management'
| 'oauth-enterprise'
......@@ -32,7 +31,6 @@ const bundles: IBundle = {
'engagement-dashboard',
'push-privacy',
'scalability',
'teams-mention',
'saml-enterprise',
'oauth-enterprise',
'device-management',
......
import { Team } from '@rocket.chat/core-services';
export const MentionQueriesEnterprise = {
async getUsers(sup, usernames) {
const uniqueUsernames = [...new Set(usernames)];
const teams = await Team.listByNames(uniqueUsernames, { projection: { name: 1 } });
if (!teams?.length) {
return sup(usernames);
}
return teams
.map((team) => ({
...team,
type: 'team',
}))
.concat(sup(usernames));
},
};
import { Team } from '@rocket.chat/core-services';
export const SpotlightEnterprise = {
mapTeams(_, teams) {
return teams.map((t) => {
t.isTeam = true;
t.username = t.name;
t.status = 'online';
return t;
});
},
async _searchTeams(_, userId, { text, options, users, mentions }) {
if (!mentions) {
return users;
}
options.limit -= users.length;
if (options.limit <= 0) {
return users;
}
const teamOptions = { ...options, projection: { name: 1, type: 1 } };
const teams = await Team.search(userId, text, teamOptions);
users.push(...this.mapTeams(teams));
return users;
},
async _performExtraUserSearches(_, userId, searchParams) {
return this._searchTeams(userId, searchParams);
},
};
import { Team } from '@rocket.chat/core-services';
import type { ITeamMember, IMessage } from '@rocket.chat/core-typings';
import { MentionQueries } from '../../../../app/mentions/server/server';
import { callbacks } from '../../../../lib/callbacks';
import { Spotlight } from '../../../../server/lib/spotlight';
import { onLicense } from '../../license/server';
import { overwriteClassOnLicense } from '../../license/server/license';
import { MentionQueriesEnterprise } from './EEMentionQueries';
import { SpotlightEnterprise } from './EESpotlight';
interface IExtraDataForNotification {
userMentions: any[];
otherMentions: any[];
message: IMessage;
}
await onLicense('teams-mention', async () => {
// Override spotlight with EE version
await overwriteClassOnLicense('teams-mention', Spotlight, SpotlightEnterprise);
await overwriteClassOnLicense('teams-mention', MentionQueries, MentionQueriesEnterprise);
callbacks.add('beforeGetMentions', async (mentionIds: string[], extra?: IExtraDataForNotification) => {
const { otherMentions } = extra ?? {};
const teamIds = otherMentions?.filter(({ type }) => type === 'team').map(({ _id }) => _id);
if (!teamIds?.length) {
return mentionIds;
}
const members: ITeamMember[] = await Team.getMembersByTeamIds(teamIds, { projection: { userId: 1 } });
mentionIds.push(
...new Set(members.map(({ userId }: { userId: string }) => userId).filter((userId: string) => !mentionIds.includes(userId))),
);
return mentionIds;
});
});
......@@ -8,7 +8,6 @@ import '../app/livechat-enterprise/server/index';
import '../app/message-read-receipt/server/index';
import '../app/voip-enterprise/server/index';
import '../app/settings/server/index';
import '../app/teams-mention/server/index';
import './api';
import './requestSeatsRoute';
import './configuration/index';
......
import { Team } from '@rocket.chat/core-services';
import { Users, Subscriptions as SubscriptionsRaw, Rooms } from '@rocket.chat/models';
import { escapeRegExp } from '@rocket.chat/string-helpers';
......@@ -133,8 +134,31 @@ export class Spotlight {
}
}
async _performExtraUserSearches(/* userId, searchParams */) {
// Overwrite this method to include extra searches
mapTeams(teams) {
return teams.map((t) => {
t.isTeam = true;
t.username = t.name;
t.status = 'online';
return t;
});
}
async _searchTeams(userId, { text, options, users, mentions }) {
if (!mentions) {
return users;
}
options.limit -= users.length;
if (options.limit <= 0) {
return users;
}
const teamOptions = { ...options, projection: { name: 1, type: 1 } };
const teams = await Team.search(userId, text, teamOptions);
users.push(...this.mapTeams(teams));
return users;
}
async searchUsers({ userId, rid, text, usernames, mentions }) {
......@@ -245,7 +269,7 @@ export class Spotlight {
return users;
}
if (await this._performExtraUserSearches(userId, searchParams)) {
if (await this._searchTeams(userId, searchParams)) {
return users;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment