From 9c2ac46fdb9bf3f2a364f580cf937612ea39140e Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 30 Jul 2024 11:45:49 -0400 Subject: [PATCH] Check for update capability before the action name Co-authored-by: Timo <16718859+toger5@users.noreply.github.com> --- src/ClientWidgetApi.ts | 50 ++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ClientWidgetApi.ts b/src/ClientWidgetApi.ts index 03c2d94..f154573 100644 --- a/src/ClientWidgetApi.ts +++ b/src/ClientWidgetApi.ts @@ -558,39 +558,37 @@ export class ClientWidgetApi extends EventEmitter { }); } - private handleUpdateDelayedEvent(request: IUpdateDelayedEventFromWidgetActionRequest) { - if (!request.data.delay_id) { - return this.transport.reply(request, { - error: {message: "Invalid request - missing delay_id"}, - }); - } +private handleUpdateDelayedEvent(request: IUpdateDelayedEventFromWidgetActionRequest) { + if (!request.data.delay_id) { + return this.transport.reply(request, { + error: {message: "Invalid request - missing delay_id"}, + }); + } - switch (request.data.action) { - case UpdateDelayedEventAction.Cancel: - case UpdateDelayedEventAction.Restart: - case UpdateDelayedEventAction.Send: - break - default: + if (!this.hasCapability(MatrixCapabilities.MSC4157UpdateDelayedEvent)) { + return this.transport.reply(request, { + error: {message: "Missing capability"}, + }); + } + + switch (request.data.action) { + case UpdateDelayedEventAction.Cancel: + case UpdateDelayedEventAction.Restart: + case UpdateDelayedEventAction.Send: + this.driver.updateDelayedEvent(request.data.delay_id, request.data.action).then(() => { + return this.transport.reply(request, {}); + }).catch(e => { + console.error("error updating delayed event: ", e); return this.transport.reply(request, { - error: {message: "Invalid request - unsupported action"}, + error: {message: "Error updating delayed event"}, }); - } - - if (!this.hasCapability(MatrixCapabilities.MSC4157UpdateDelayedEvent)) { - return this.transport.reply(request, { - error: {message: "Missing capability"}, }); - } - - this.driver.updateDelayedEvent(request.data.delay_id, request.data.action).then(() => { - return this.transport.reply(request, {}); - }).catch(e => { - console.error("error updating delayed event: ", e); + default: return this.transport.reply(request, { - error: {message: "Error updating delayed event"}, + error: {message: "Invalid request - unsupported action"}, }); - }); } +} private async handleSendToDevice(request: ISendToDeviceFromWidgetActionRequest): Promise { if (!request.data.type) {