Skip to content

Commit

Permalink
Regression: Fix slash commands (#28168)
Browse files Browse the repository at this point in the history
Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
  • Loading branch information
ggazzo and tassoevan authored Feb 28, 2023
1 parent d00f7c5 commit 70320d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,44 @@ const ComposerBoxPopupPreview = forwardRef<
const executeSlashCommandPreviewMethod = useMethod('executeSlashCommandPreview');
useImperativeHandle(
ref,
() =>
suspended
? {}
: {
getFilter: () => {
const value = chat?.composer?.substring(0, chat?.composer?.selection.start);
if (!value) {
throw new Error('No value');
}
const matches = value.match(/(\/[\w\d\S]+ )([^]*)$/);

if (!matches) {
throw new Error('No matches');
}

const cmd = matches[1].replace('/', '').trim().toLowerCase();

const params = matches[2];
return { cmd, params, msg: { rid, tmid } };
},
select: (item) => {
const value = chat?.composer?.substring(0, chat?.composer?.selection.start);
if (!value) {
throw new Error('No value');
}
const matches = value.match(/(\/[\w\d\S]+ )([^]*)$/);

if (!matches) {
throw new Error('No matches');
}

const cmd = matches[1].replace('/', '').trim().toLowerCase();

const params = matches[2];
// TODO: Fix this solve the typing issue
executeSlashCommandPreviewMethod({ cmd, params, msg: { rid, tmid } }, { id: item._id, type: item.type, value: item.value });
chat?.composer?.setText('');
},
},
() => ({
getFilter: () => {
const value = chat?.composer?.substring(0, chat?.composer?.selection.start);
if (!value) {
throw new Error('No value');
}
const matches = value.match(/(\/[\w\d\S]+ )([^]*)$/);

if (!matches) {
throw new Error('No matches');
}

const cmd = matches[1].replace('/', '').trim().toLowerCase();

const params = matches[2];
return { cmd, params, msg: { rid, tmid } };
},
...(!suspended && {
select: (item) => {
const value = chat?.composer?.substring(0, chat?.composer?.selection.start);
if (!value) {
throw new Error('No value');
}
const matches = value.match(/(\/[\w\d\S]+ )([^]*)$/);

if (!matches) {
throw new Error('No matches');
}

const cmd = matches[1].replace('/', '').trim().toLowerCase();

const params = matches[2];
// TODO: Fix this solve the typing issue
executeSlashCommandPreviewMethod({ cmd, params, msg: { rid, tmid } }, { id: item._id, type: item.type, value: item.value });
chat?.composer?.setText('');
},
}),
}),
[chat?.composer, executeSlashCommandPreviewMethod, rid, tmid, suspended],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>({
});

const keydown = useMutableCallback((event: KeyboardEvent) => {
if (!popup || popup.preview) {
if (!popup) {
return;
}

Expand Down

0 comments on commit 70320d4

Please sign in to comment.