From 3db3dcf5af00157536b2ab5c127658f8f7489895 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" <rick.carback@gmail.com> Date: Wed, 14 Jun 2023 18:18:38 +0000 Subject: [PATCH] Add GetDmNotificationReportsForMe --- wasm/dm.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/wasm/dm.go b/wasm/dm.go index f314143d..0cfa1af8 100644 --- a/wasm/dm.go +++ b/wasm/dm.go @@ -808,6 +808,59 @@ func DecodeDMShareURL(_ js.Value, args []js.Value) any { return utils.CopyBytesToJS(report) } +// GetDmNotificationReportsForMe checks the notification data against the filter +// list to determine which notifications belong to the user. A list of +// notification reports is returned detailing all notifications for the user. +// +// Parameters: +// - args[0] - notificationFilterJSON - JSON (Uint8Array) of +// [dm.NotificationFilter]. +// - args[1] - notificationDataCSV - CSV containing notification data. +// +// Example JSON of a slice of [dm.NotificationFilter]: +// +// { +// "identifier": "MWL6mvtZ9UUm7jP3ainyI4erbRl+wyVaO5MOWboP0rA=", +// "myID": "AqDqg6Tcs359dBNRBCX7XHaotRDhz1ZRQNXIsGaubvID", +// "tags": [ +// "61334HtH85DPIifvrM+JzRmLqfV5R4AMEmcPelTmFX0=", +// "zc/EPwtx5OKTVdwLcI15bghjJ7suNhu59PcarXE+m9o=", +// "FvArzVJ/082UEpMDCWJsopCLeLnxJV6NXINNkJTk3k8=" +// ], +// "PublicKeys": { +// "61334HtH85DPIifvrM+JzRmLqfV5R4AMEmcPelTmFX0=": "b3HygDv8gjteune9wgBm3YtVuAo2foOusRmj0m5nl6E=", +// "FvArzVJ/082UEpMDCWJsopCLeLnxJV6NXINNkJTk3k8=": "uOLitBZcCh2TEW406jXHJ+Rsi6LybsH8R1u4Mxv/7hA=", +// "zc/EPwtx5OKTVdwLcI15bghjJ7suNhu59PcarXE+m9o=": "lqLD1EzZBxB8PbILUJIfFq4JI0RKThpUQuNlTNgZAWk=" +// }, +// "allowedTypes": {"1": {}, "2": {}} +// } +// +// Returns: +// - []byte - JSON of a slice of [dm.NotificationReport]. +// +// Example return: +// +// [ +// {"partner": "WUSO3trAYeBf4UeJ5TEL+Q4usoyFf0shda0YUmZ3z8k=", "type": 1}, +// {"partner": "5MY652JsVv5YLE6wGRHIFZBMvLklACnT5UtHxmEOJ4o=", "type": 2} +// ] +func GetDmNotificationReportsForMe(_ js.Value, args []js.Value) any { + notificationFilterJson := utils.CopyBytesToGo(args[0]) + notificationDataCsv := args[1].String() + + promiseFn := func(resolve, reject func(args ...any) js.Value) { + forme, err := bindings.GetDmNotificationReportsForMe( + notificationFilterJson, notificationDataCsv) + if err != nil { + reject(exception.NewTrace(err)) + } else { + resolve(utils.CopyBytesToJS(forme)) + } + } + + return utils.CreatePromise(promiseFn) +} + //////////////////////////////////////////////////////////////////////////////// // Event Model Logic // //////////////////////////////////////////////////////////////////////////////// -- GitLab