diff --git a/app/utils/lib/slashCommand.js b/app/utils/lib/slashCommand.js index 67e72e36cf0a..42d9dd5a5365 100644 --- a/app/utils/lib/slashCommand.js +++ b/app/utils/lib/slashCommand.js @@ -24,18 +24,25 @@ export const slashCommands = { return slashCommands.commands[command].callback(command, params, message, triggerId); } }, - getPreviews: function _executeSlashCommandPreview(command, params, message, preview, triggerId) { - if (slashCommands.commands[command] && typeof slashCommands.commands[command].previewCallback === 'function') { + getPreviews: function _gettingSlashCommandPreviews(command, params, message) { + if (slashCommands.commands[command] && typeof slashCommands.commands[command].previewer === 'function') { if (!message || !message.rid) { throw new Meteor.Error('invalid-command-usage', 'Executing a command requires at least a message with a room id.'); } - // { id, type, value } - if (!preview.id || !preview.type || !preview.value) { - throw new Meteor.Error('error-invalid-preview', 'Preview Item must have an id, type, and value.'); + // { i18nTitle, items: [{ id, type, value }] } + const previewInfo = slashCommands.commands[command].previewer(command, params, message); + + if (typeof previewInfo !== 'object' || !Array.isArray(previewInfo.items) || previewInfo.items.length === 0) { + return; } - return slashCommands.commands[command].previewCallback(command, params, message, preview, triggerId); + // A limit of ten results, to save time and bandwidth + if (previewInfo.items.length >= 10) { + previewInfo.items = previewInfo.items.slice(0, 10); + } + + return previewInfo; } }, executePreview: function _executeSlashCommandPreview(command, params, message, preview, triggerId) {