From d4653cd9cc38099d2458b6b817a5c82218e9de59 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" <rick.carback@gmail.com> Date: Fri, 16 Jun 2023 19:56:42 +0000 Subject: [PATCH] Put SetMobileNotificationLevel in a promise --- wasm/channels.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/wasm/channels.go b/wasm/channels.go index 09d3b1b9..b9b7e76d 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -1711,20 +1711,25 @@ func (cm *ChannelsManager) GetNotificationLevel(_ js.Value, args []js.Value) any // - args[2] - The [notifications.NotificationState] to set for the channel // (int). // -// Returns: -// - Throws an error if setting the notification level fails. -func (cm *ChannelsManager) SetMobileNotificationsLevel(_ js.Value, args []js.Value) any { +// Returns a promise and throws an error if setting the notification +// level fails. +func (cm *ChannelsManager) SetMobileNotificationsLevel(_ js.Value, + args []js.Value) any { channelIDBytes := utils.CopyBytesToGo(args[0]) level := args[1].Int() status := args[2].Int() - err := cm.api.SetMobileNotificationsLevel(channelIDBytes, level, status) - if err != nil { - exception.ThrowTrace(err) - return nil + promiseFn := func(resolve, reject func(args ...any) js.Value) { + err := cm.api.SetMobileNotificationsLevel(channelIDBytes, + level, status) + if err != nil { + reject(exception.NewTrace(err)) + } else { + resolve() + } } - return nil + return utils.CreatePromise(promiseFn) } // GetChannelNotificationReportsForMe checks the notification data against the -- GitLab