Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Slash commands previews not working #24387

Merged
merged 1 commit into from
Feb 3, 2022
Merged
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
19 changes: 13 additions & 6 deletions app/utils/lib/slashCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down