From 87201c8bfbe9dac2a60ffc51d03aeb116a7ab516 Mon Sep 17 00:00:00 2001 From: Germain Date: Tue, 23 Nov 2021 08:17:30 +0000 Subject: [PATCH] Chat effects fixes for threads (#7183) --- src/SlashCommands.tsx | 10 +++++++++- src/components/views/rooms/EditMessageComposer.tsx | 4 +++- src/components/views/rooms/SendMessageComposer.tsx | 8 ++++++-- src/stores/widgets/StopGapWidgetDriver.ts | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 1ceaf910ae..1c7d9d16ed 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -139,9 +139,17 @@ export class Command { return this.getCommand() + " " + this.args; } - run(roomId: string, args: string) { + run(roomId: string, threadId: string, args: string) { // if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me` if (!this.runFn) return reject(_t("Command error")); + + const renderingType = threadId + ? TimelineRenderingType.Thread + : TimelineRenderingType.Room; + if (this.renderingTypes && !this.renderingTypes?.includes(renderingType)) { + return reject(_t("Command error")); + } + return this.runFn.bind(this)(roomId, args); } diff --git a/src/components/views/rooms/EditMessageComposer.tsx b/src/components/views/rooms/EditMessageComposer.tsx index a247c285db..03851138f0 100644 --- a/src/components/views/rooms/EditMessageComposer.tsx +++ b/src/components/views/rooms/EditMessageComposer.tsx @@ -321,7 +321,9 @@ class EditMessageComposer extends React.Component { - const result = cmd.run(roomId, args); + const threadId = this.props.editState?.getEvent()?.getThread()?.id || null; + + const result = cmd.run(roomId, threadId, args); let messageContent; let error = result.error; if (result.promise) { diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index e6ec92cffb..9b8ed76f68 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -350,7 +350,11 @@ export class SendMessageComposer extends React.Component { - const result = cmd.run(this.props.room.roomId, args); + const threadId = this.props.relation?.rel_type === RelationType.Thread + ? this.props.relation?.event_id + : null; + + const result = cmd.run(this.props.room.roomId, threadId, args); let messageContent; let error = result.error; if (result.promise) { @@ -495,7 +499,7 @@ export class SendMessageComposer extends React.Component