Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
import type { IMessageSearchProvider, IMessageSearchSuggestion, IRoom, IUser } from '@rocket.chat/core-typings';
|
|
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { SearchLogger } from '../../lib/search/logger/logger';
|
|
import type { IRawSearchResult, ISearchResult } from '../../lib/search/model/ISearchResult';
|
|
import { searchProviderService, validationService } from '../../lib/search/service';
|
|
|
|
declare module '@rocket.chat/ddp-client' {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
interface ServerMethods {
|
|
'rocketchatSearch.getProvider'(): IMessageSearchProvider | undefined;
|
|
'rocketchatSearch.search'(text: string, context: { uid?: IUser['_id']; rid: IRoom['_id'] }, payload: unknown): Promise<ISearchResult>;
|
|
'rocketchatSearch.suggest'(
|
|
text: string,
|
|
context: { uid?: IUser['_id']; rid: IRoom['_id'] },
|
|
payload: unknown,
|
|
): Promise<IMessageSearchSuggestion[]>;
|
|
}
|
|
}
|
|
|
|
Meteor.methods<ServerMethods>({
|
|
/**
|
|
* Get the current provider with key, description, resultTemplate, suggestionItemTemplate and settings (as Map)
|
|
*/
|
|
'rocketchatSearch.getProvider'() {
|
|
const provider = searchProviderService.activeProvider;
|
|
if (!provider) {
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
key: provider.key,
|
|
description: provider.i18nDescription,
|
|
icon: provider.iconName,
|
|
resultTemplate: provider.resultTemplate,
|
|
supportsSuggestions: provider.supportsSuggestions,
|
|
suggestionItemTemplate: provider.suggestionItemTemplate,
|
|
settings: Object.fromEntries(Object.values(provider.settingsAsMap).map((setting) => [setting.key, setting.value] as const)),
|
|
};
|
|
},
|
|
/**
|
|
* Search using the current search provider and check if results are valid for the user. The search result has
|
|
* the format `{messages:{start:0,numFound:1,docs:[{...}]},users:{...},rooms:{...}}`
|
|
* @param text the search text
|
|
* @param context the context (uid, rid)
|
|
* @param payload custom payload (e.g. for paging)
|
|
*/
|
|
async 'rocketchatSearch.search'(text, context, payload) {
|
|
payload = payload !== null ? payload : undefined; // TODO is this cleanup necessary?
|
|
|
|
if (!searchProviderService.activeProvider) {
|
|
throw new Error('Provider currently not active');
|
|
}
|
|
|
|
SearchLogger.debug({ msg: 'search', text, context, payload });
|
|
|
|
const userId = Meteor.userId();
|
|
if (!userId) {
|
|
throw new Error('User not logged in');
|
|
}
|
|
|
|
return new Promise<IRawSearchResult>((resolve, reject) => {
|
|
void searchProviderService.activeProvider?.search(userId, text, context, payload, (error, data) => {
|
|
if (error) {
|
|
return reject(error);
|
|
}
|
|
|
|
return resolve(data);
|
|
});
|
|
}).then((result) => validationService.validateSearchResult(result));
|
|
},
|
|
|
|
async 'rocketchatSearch.suggest'(text, context, payload) {
|
|
payload ??= undefined; // TODO is this cleanup necessary?
|
|
|
|
if (!searchProviderService.activeProvider) {
|
|
throw new Error('Provider currently not active');
|
|
}
|
|
|
|
SearchLogger.debug({ msg: 'suggest', text, context, payload });
|
|
|
|
return new Promise((resolve, reject) => {
|
|
searchProviderService.activeProvider?.suggest(text, context, payload, (error, data) => {
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
|
|
resolve(data);
|
|
});
|
|
});
|
|
},
|
|
});
|