From 3f6909ffb827698ad00e9c3d15e33d309471a480 Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Wed, 28 Sep 2022 10:27:12 -0700 Subject: [PATCH] Update channels bindings for indexedDb changes --- wasm/channels.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/wasm/channels.go b/wasm/channels.go index 024d31c0..23c5cb9b 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -10,6 +10,7 @@ package wasm import ( + "gitlab.com/xx_network/primitives/id" "syscall/js" "gitlab.com/elixxir/client/bindings" @@ -229,6 +230,12 @@ func LoadChannelsManager(_ js.Value, args []js.Value) interface{} { // using [Cmix.GetID]. // - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is // generated by [GenerateChannelIdentity] (Uint8Array). +// - args[2] - Function that takes in the same parameters as +// [indexedDb.MessageReceivedCallback]. On the Javascript side, the uuid is +// returned as an int and the channelID as a Uint8Array. The row in the +// database that was updated can be found using the UUID. The channel ID is +// provided so that the recipient can filter if they want to the processes +// the update now or not. // // Returns a promise: // - Resolves to a Javascript representation of the [ChannelsManager] object. @@ -237,9 +244,16 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { cmixID := args[0].Int() privateIdentity := utils.CopyBytesToGo(args[1]) + fn := func(uuid uint64, channelID *id.ID) { + args[2].Invoke(uuid, channelID.Marshal()) + } + + model := indexedDb.NewWASMEventModelBuilder(fn) + promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + cm, err := bindings.NewChannelsManagerGoEventModel( - cmixID, privateIdentity, indexedDb.NewWasmEventModel) + cmixID, privateIdentity, model) if err != nil { reject(utils.JsTrace(err)) } else { @@ -263,6 +277,12 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { // using [Cmix.GetID]. // - args[1] - The storage tag associated with the previously created channel // manager and retrieved with [ChannelsManager.GetStorageTag] (string). +// - args[2] - Function that takes in the same parameters as +// [indexedDb.MessageReceivedCallback]. On the Javascript side, the uuid is +// returned as an int and the channelID as a Uint8Array. The row in the +// database that was updated can be found using the UUID. The channel ID is +// provided so that the recipient can filter if they want to the processes +// the update now or not. // // Returns a promise: // - Resolves to a Javascript representation of the [ChannelsManager] object. @@ -271,9 +291,16 @@ func LoadChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { cmixID := args[0].Int() storageTag := args[1].String() + fn := func(uuid uint64, channelID *id.ID) { + args[2].Invoke(uuid, channelID.Marshal()) + } + + model := indexedDb.NewWASMEventModelBuilder(fn) + promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + cm, err := bindings.LoadChannelsManagerGoEventModel( - cmixID, storageTag, indexedDb.NewWasmEventModel) + cmixID, storageTag, model) if err != nil { reject(utils.JsTrace(err)) } else { -- GitLab