Skip to content
Snippets Groups Projects
Commit 470a2eea authored by Jono Wenger's avatar Jono Wenger
Browse files

XX-4712 / Add wrapper for bindings.DmCallbacks

parent 38e5c12f
No related branches found
No related tags found
2 merge requests!135XX-4712 / Add wrapper for bindings.DmCallbacks,!109Project/haven beta
...@@ -11,7 +11,7 @@ require ( ...@@ -11,7 +11,7 @@ require (
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/stretchr/testify v1.8.2 github.com/stretchr/testify v1.8.2
gitlab.com/elixxir/client/v4 v4.6.4-0.20230629182558-519cc3467eae gitlab.com/elixxir/client/v4 v4.6.4-0.20230629183830-d8f41f8d0d1e
gitlab.com/elixxir/crypto v0.0.7-0.20230614183801-387e0cb8e76f gitlab.com/elixxir/crypto v0.0.7-0.20230614183801-387e0cb8e76f
gitlab.com/elixxir/primitives v0.0.3-0.20230613193928-8cf8bdd777ef gitlab.com/elixxir/primitives v0.0.3-0.20230613193928-8cf8bdd777ef
gitlab.com/elixxir/wasm-utils v0.0.0-20230615222914-185dd3a6fa08 gitlab.com/elixxir/wasm-utils v0.0.0-20230615222914-185dd3a6fa08
...@@ -31,10 +31,12 @@ require ( ...@@ -31,10 +31,12 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/elliotchance/orderedmap v1.4.0 // indirect github.com/elliotchance/orderedmap v1.4.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gobwas/ws v1.1.0 // indirect github.com/gobwas/ws v1.1.0 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
...@@ -43,18 +45,27 @@ require ( ...@@ -43,18 +45,27 @@ require (
github.com/klauspost/compress v1.15.9 // indirect github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/kr/pretty v0.3.0 // indirect github.com/kr/pretty v0.3.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20221003100820-41fad3beba17 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20221003100820-41fad3beba17 // indirect
github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/profile v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.8.2 // indirect github.com/rs/cors v1.8.2 // indirect
github.com/sethvargo/go-diceware v0.3.0 // indirect github.com/sethvargo/go-diceware v0.3.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/soheilhy/cmux v0.1.5 // indirect github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect
...@@ -75,6 +86,8 @@ require ( ...@@ -75,6 +86,8 @@ require (
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.49.0 // indirect google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect gorm.io/driver/sqlite v1.4.4 // indirect
gorm.io/gorm v1.24.3 // indirect gorm.io/gorm v1.24.3 // indirect
......
This diff is collapsed.
...@@ -12,6 +12,7 @@ package main ...@@ -12,6 +12,7 @@ package main
import ( import (
"crypto/ed25519" "crypto/ed25519"
"encoding/json" "encoding/json"
"gitlab.com/elixxir/client/v4/bindings"
"strconv" "strconv"
"strings" "strings"
"syscall/js" "syscall/js"
...@@ -168,8 +169,8 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID, messageID message.ID, ...@@ -168,8 +169,8 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID, messageID message.ID,
return 0 return 0
} }
go w.eventUpdate(channels.MessageReceived, channels.MessageReceivedJson{ go w.eventUpdate(bindings.MessageReceived, bindings.MessageReceivedJSON{
Uuid: int64(uuid), UUID: int64(uuid),
ChannelID: channelID, ChannelID: channelID,
Update: false, Update: false,
}) })
...@@ -210,8 +211,8 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID, messageID, ...@@ -210,8 +211,8 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID, messageID,
return 0 return 0
} }
go w.eventUpdate(channels.MessageReceived, channels.MessageReceivedJson{ go w.eventUpdate(bindings.MessageReceived, bindings.MessageReceivedJSON{
Uuid: int64(uuid), UUID: int64(uuid),
ChannelID: channelID, ChannelID: channelID,
Update: false, Update: false,
}) })
...@@ -252,8 +253,8 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID, ...@@ -252,8 +253,8 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID,
return 0 return 0
} }
go w.eventUpdate(channels.MessageReceived, channels.MessageReceivedJson{ go w.eventUpdate(bindings.MessageReceived, bindings.MessageReceivedJSON{
Uuid: int64(uuid), UUID: int64(uuid),
ChannelID: channelID, ChannelID: channelID,
Update: false, Update: false,
}) })
...@@ -409,8 +410,8 @@ func (w *wasmModel) updateMessage(currentMsg *Message, messageID *message.ID, ...@@ -409,8 +410,8 @@ func (w *wasmModel) updateMessage(currentMsg *Message, messageID *message.ID,
return 0, err return 0, err
} }
go w.eventUpdate(channels.MessageReceived, channels.MessageReceivedJson{ go w.eventUpdate(bindings.MessageReceived, bindings.MessageReceivedJSON{
Uuid: int64(uuid), UUID: int64(uuid),
ChannelID: channelID, ChannelID: channelID,
Update: true, Update: true,
}) })
...@@ -531,8 +532,8 @@ func (w *wasmModel) DeleteMessage(messageID message.ID) error { ...@@ -531,8 +532,8 @@ func (w *wasmModel) DeleteMessage(messageID message.ID) error {
return err return err
} }
go w.eventUpdate(channels.MessageDeleted, go w.eventUpdate(bindings.MessageDeleted,
channels.MessageDeletedJson{MessageID: messageID}) bindings.MessageDeletedJSON{MessageID: messageID})
return nil return nil
} }
...@@ -541,7 +542,7 @@ func (w *wasmModel) DeleteMessage(messageID message.ID) error { ...@@ -541,7 +542,7 @@ func (w *wasmModel) DeleteMessage(messageID message.ID) error {
func (w *wasmModel) MuteUser( func (w *wasmModel) MuteUser(
channelID *id.ID, pubKey ed25519.PublicKey, unmute bool) { channelID *id.ID, pubKey ed25519.PublicKey, unmute bool) {
go w.eventUpdate(channels.UserMuted, channels.UserMutedJson{ go w.eventUpdate(bindings.UserMuted, bindings.UserMutedJSON{
ChannelID: channelID, ChannelID: channelID,
PubKey: pubKey, PubKey: pubKey,
Unmute: unmute, Unmute: unmute,
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/hack-pad/go-indexeddb/idb" "github.com/hack-pad/go-indexeddb/idb"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/channels" "gitlab.com/elixxir/client/v4/channels"
idbCrypto "gitlab.com/elixxir/crypto/indexedDb" idbCrypto "gitlab.com/elixxir/crypto/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl" "gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
...@@ -29,13 +30,13 @@ const currentVersion uint = 1 ...@@ -29,13 +30,13 @@ const currentVersion uint = 1
// The name should be a base64 encoding of the users public key. Returns the // The name should be a base64 encoding of the users public key. Returns the
// EventModel based on IndexedDb and the database name as reported by IndexedDb. // EventModel based on IndexedDb and the database name as reported by IndexedDb.
func NewWASMEventModel(databaseName string, encryption idbCrypto.Cipher, func NewWASMEventModel(databaseName string, encryption idbCrypto.Cipher,
uiCallbacks channels.ChannelUICallbacks) (channels.EventModel, error) { uiCallbacks bindings.ChannelUICallbacks) (channels.EventModel, error) {
return newWASMModel(databaseName, encryption, uiCallbacks) return newWASMModel(databaseName, encryption, uiCallbacks)
} }
// newWASMModel creates the given [idb.Database] and returns a wasmModel. // newWASMModel creates the given [idb.Database] and returns a wasmModel.
func newWASMModel(databaseName string, encryption idbCrypto.Cipher, func newWASMModel(databaseName string, encryption idbCrypto.Cipher,
uiCallbacks channels.ChannelUICallbacks) (*wasmModel, error) { uiCallbacks bindings.ChannelUICallbacks) (*wasmModel, error) {
// Attempt to open database object // Attempt to open database object
ctx, cancel := impl.NewContext() ctx, cancel := impl.NewContext()
defer cancel() defer cancel()
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/channels" "gitlab.com/elixxir/client/v4/channels"
idbCrypto "gitlab.com/elixxir/crypto/indexedDb" idbCrypto "gitlab.com/elixxir/crypto/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/logging" "gitlab.com/elixxir/xxdk-wasm/logging"
...@@ -33,9 +34,8 @@ type eventUpdateCallback func(eventType int64, jsonData []byte) ...@@ -33,9 +34,8 @@ type eventUpdateCallback func(eventType int64, jsonData []byte)
// NewWASMEventModelBuilder returns an EventModelBuilder which allows // NewWASMEventModelBuilder returns an EventModelBuilder which allows
// the channel manager to define the path but the callback is the same // the channel manager to define the path but the callback is the same
// across the board. // across the board.
func NewWASMEventModelBuilder(wasmJsPath string, func NewWASMEventModelBuilder(wasmJsPath string, encryption idbCrypto.Cipher,
encryption idbCrypto.Cipher, channelCbs bindings.ChannelUICallbacks) channels.EventModelBuilder {
channelCbs channels.ChannelUICallbacks) channels.EventModelBuilder {
fn := func(path string) (channels.EventModel, error) { fn := func(path string) (channels.EventModel, error) {
return NewWASMEventModel(path, wasmJsPath, encryption, return NewWASMEventModel(path, wasmJsPath, encryption,
channelCbs) channelCbs)
...@@ -53,8 +53,7 @@ type NewWASMEventModelMessage struct { ...@@ -53,8 +53,7 @@ type NewWASMEventModelMessage struct {
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel. // NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key. // The name should be a base64 encoding of the users public key.
func NewWASMEventModel(path, wasmJsPath string, encryption idbCrypto.Cipher, func NewWASMEventModel(path, wasmJsPath string, encryption idbCrypto.Cipher,
channelCbs channels.ChannelUICallbacks) ( channelCbs bindings.ChannelUICallbacks) (channels.EventModel, error) {
channels.EventModel, error) {
databaseName := path + databaseSuffix databaseName := path + databaseSuffix
wm, err := worker.NewManager(wasmJsPath, "channelsIndexedDb", true) wm, err := worker.NewManager(wasmJsPath, "channelsIndexedDb", true)
......
...@@ -97,8 +97,9 @@ const ( ...@@ -97,8 +97,9 @@ const (
// - Internal password (Uint8Array). // - Internal password (Uint8Array).
// - Throws TypeError on failure. // - Throws TypeError on failure.
func GetOrInitPassword(_ js.Value, args []js.Value) any { func GetOrInitPassword(_ js.Value, args []js.Value) any {
externalPassword := args[0].String()
promiseFn := func(resolve, reject func(args ...any) js.Value) { promiseFn := func(resolve, reject func(args ...any) js.Value) {
internalPassword, err := getOrInit(args[0].String()) internalPassword, err := getOrInit(externalPassword)
if err != nil { if err != nil {
reject(exception.NewTrace(err)) reject(exception.NewTrace(err))
} else { } else {
......
...@@ -77,65 +77,20 @@ func newDMClientJS(api *bindings.DMClient) map[string]any { ...@@ -77,65 +77,20 @@ func newDMClientJS(api *bindings.DMClient) map[string]any {
return dmClientMap return dmClientMap
} }
// newDmNotificationUpdate adds the callbacks from the Javascript object. // dmCallbacks wraps Javascript callbacks to adhere to the
func newDmNotificationUpdate(value js.Value) *dmNotificationUpdate { // [bindings.DmCallbacks] interface.
return &dmNotificationUpdate{callback: utils.WrapCB(value, "Callback")} type dmCallbacks struct {
eventUpdate func(args ...any) js.Value
} }
// dmNotificationUpdate wraps Javascript callbacks to adhere to the // newDmCallbacks adds the callbacks from the Javascript object.
// [bindings.DmNotificationUpdate] interface. func newDmCallbacks(value js.Value) *dmCallbacks {
type dmNotificationUpdate struct { return &dmCallbacks{eventUpdate: utils.WrapCB(value, "EventUpdate")}
callback func(args ...any) js.Value
} }
// Callback is called everytime there is an update to the notification filter // EventUpdate implements [bindings.DmCallbacks.EventUpdate].
// or notification status for DMs. func (dmCBS *dmCallbacks) EventUpdate(eventType int64, jsonData []byte) {
// dmCBS.eventUpdate(eventType, utils.CopyBytesToJS(jsonData))
// Parameters:
// - nfJSON - JSON of [dm.NotificationFilter], which is passed into
// [GetDmNotificationReportsForMe] to filter DM notifications for the user.
// - changedStateListJSON - JSON of a slice of [dm.NotificationState]. It
// includes all added or changed notification states for DM conversations.
// - deletedListJSON - JSON of a slice of [ed25519.PublicKey]. It includes
// conversation that were deleted.
//
// Example nfJSON:
//
// {
// "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": {}}
// }
//
// Example changedStateListJSON:
//
// [
// {"pubKey": "lqLD1EzZBxB8PbILUJIfFq4JI0RKThpUQuNlTNgZAWk=", "level": 40},
// {"pubKey": "uOLitBZcCh2TEW406jXHJ+Rsi6LybsH8R1u4Mxv/7hA=", "level": 10},
// {"pubKey": "b3HygDv8gjteune9wgBm3YtVuAo2foOusRmj0m5nl6E=", "level": 10}
// ]
//
// Example deletedListJSON:
//
// [
// "lqLD1EzZBxB8PbILUJIfFq4JI0RKThpUQuNlTNgZAWk=",
// "lqLD1EzZBxB8PbILUJIfFq4JI0RKThpUQuNlTNgZAWk="
// ]
func (dmNU *dmNotificationUpdate) Callback(
nfJSON, changedStateListJSON, deletedListJSON []byte) {
dmNU.callback(utils.CopyBytesToJS(nfJSON),
utils.CopyBytesToJS(changedStateListJSON),
utils.CopyBytesToJS(deletedListJSON))
} }
// NewDMClient creates a new [DMClient] from a private identity // NewDMClient creates a new [DMClient] from a private identity
...@@ -156,9 +111,10 @@ func (dmNU *dmNotificationUpdate) Callback( ...@@ -156,9 +111,10 @@ func (dmNU *dmNotificationUpdate) Callback(
// - args[3] - A function that initialises and returns a Javascript object // - args[3] - A function that initialises and returns a Javascript object
// that matches the [bindings.EventModel] interface. The function must match // that matches the [bindings.EventModel] interface. The function must match
// the Build function in [bindings.EventModelBuilder]. // the Build function in [bindings.EventModelBuilder].
// - args[4] - A callback that is triggered everytime there is a change to the // - args[4] - A Javascript object that implements the function on
// notification status of a DM conversation It must be a Javascript object // [bindings.DmCallbacks]. It is a callback that informs the UI about
// that implements the callback in [bindings.DmNotificationUpdate]. // updates relating to DM conversations. The interface may be null, but if
// one is provided, each method must be implemented.
// //
// Returns: // Returns:
// - Javascript representation of the [DMClient] object. // - Javascript representation of the [DMClient] object.
...@@ -168,10 +124,10 @@ func NewDMClient(_ js.Value, args []js.Value) any { ...@@ -168,10 +124,10 @@ func NewDMClient(_ js.Value, args []js.Value) any {
notificationsID := args[1].Int() notificationsID := args[1].Int()
privateIdentity := utils.CopyBytesToGo(args[2]) privateIdentity := utils.CopyBytesToGo(args[2])
em := newDMReceiverBuilder(args[3]) em := newDMReceiverBuilder(args[3])
nu := newDmNotificationUpdate(args[4]) cbs := newDmCallbacks(args[4])
cm, err := cm, err :=
bindings.NewDMClient(cmixID, notificationsID, privateIdentity, em, nu) bindings.NewDMClient(cmixID, notificationsID, privateIdentity, em, cbs)
if err != nil { if err != nil {
exception.ThrowTrace(err) exception.ThrowTrace(err)
return nil return nil
...@@ -207,9 +163,10 @@ func NewDMClient(_ js.Value, args []js.Value) any { ...@@ -207,9 +163,10 @@ func NewDMClient(_ js.Value, args []js.Value) any {
// The row in the database that was updated can be found using the UUID. // The row in the database that was updated can be found using the UUID.
// messageUpdate is true if the message already exists and was edited. // messageUpdate is true if the message already exists and was edited.
// conversationUpdate is true if the Conversation was created or modified. // conversationUpdate is true if the Conversation was created or modified.
// - args[6] - A callback that is triggered everytime there is a change to the // - args[6] - A Javascript object that implements the function on
// notification status of a DM conversation It must be a Javascript object // [bindings.DmCallbacks]. It is a callback that informs the UI about
// that implements the callback in [bindings.DmNotificationUpdate]. // updates relating to DM conversations. The interface may be null, but if
// one is provided, each method must be implemented.
// //
// Returns: // Returns:
// - Resolves to a Javascript representation of the [DMClient] object. // - Resolves to a Javascript representation of the [DMClient] object.
...@@ -222,7 +179,7 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any { ...@@ -222,7 +179,7 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any {
wasmJsPath := args[3].String() wasmJsPath := args[3].String()
privateIdentity := utils.CopyBytesToGo(args[4]) privateIdentity := utils.CopyBytesToGo(args[4])
messageReceivedCB := args[5] messageReceivedCB := args[5]
nu := newDmNotificationUpdate(args[6]) cbs := newDmCallbacks(args[6])
cipher, err := dbCipherTrackerSingleton.get(cipherID) cipher, err := dbCipherTrackerSingleton.get(cipherID)
if err != nil { if err != nil {
...@@ -230,7 +187,7 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any { ...@@ -230,7 +187,7 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any {
} }
return newDMClientWithIndexedDb(cmixID, notificationsID, wasmJsPath, return newDMClientWithIndexedDb(cmixID, notificationsID, wasmJsPath,
privateIdentity, messageReceivedCB, cipher, nu) privateIdentity, messageReceivedCB, cipher, cbs)
} }
// NewDMClientWithIndexedDbUnsafe creates a new [DMClient] from a private // NewDMClientWithIndexedDbUnsafe creates a new [DMClient] from a private
...@@ -259,9 +216,10 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any { ...@@ -259,9 +216,10 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any {
// The row in the database that was updated can be found using the UUID. // The row in the database that was updated can be found using the UUID.
// messageUpdate is true if the message already exists and was edited. // messageUpdate is true if the message already exists and was edited.
// conversationUpdate is true if the Conversation was created or modified. // conversationUpdate is true if the Conversation was created or modified.
// - args[5] - A callback that is triggered everytime there is a change to the // - args[5] - A Javascript object that implements the function on
// notification status of a DM conversation It must be a Javascript object // [bindings.DmCallbacks]. It is a callback that informs the UI about
// that implements the callback in [bindings.DmNotificationUpdate]. // updates relating to DM conversations. The interface may be null, but if
// one is provided, each method must be implemented.
// //
// Returns a promise: // Returns a promise:
// - Resolves to a Javascript representation of the [DMClient] object. // - Resolves to a Javascript representation of the [DMClient] object.
...@@ -272,14 +230,14 @@ func NewDMClientWithIndexedDbUnsafe(_ js.Value, args []js.Value) any { ...@@ -272,14 +230,14 @@ func NewDMClientWithIndexedDbUnsafe(_ js.Value, args []js.Value) any {
wasmJsPath := args[2].String() wasmJsPath := args[2].String()
privateIdentity := utils.CopyBytesToGo(args[3]) privateIdentity := utils.CopyBytesToGo(args[3])
messageReceivedCB := args[4] messageReceivedCB := args[4]
nu := newDmNotificationUpdate(args[5]) cbs := newDmCallbacks(args[5])
return newDMClientWithIndexedDb(cmixID, notificationsID, wasmJsPath, return newDMClientWithIndexedDb(cmixID, notificationsID, wasmJsPath,
privateIdentity, messageReceivedCB, nil, nu) privateIdentity, messageReceivedCB, nil, cbs)
} }
func newDMClientWithIndexedDb(cmixID, notificationsID int, wasmJsPath string, func newDMClientWithIndexedDb(cmixID, notificationsID int, wasmJsPath string,
privateIdentity []byte, cb js.Value, cipher *DbCipher, nuCB bindings.DmNotificationUpdate) any { privateIdentity []byte, cb js.Value, cipher *DbCipher, cbs *dmCallbacks) any {
messageReceivedCB := func(uuid uint64, pubKey ed25519.PublicKey, messageReceivedCB := func(uuid uint64, pubKey ed25519.PublicKey,
messageUpdate, conversationUpdate bool) { messageUpdate, conversationUpdate bool) {
...@@ -301,7 +259,7 @@ func newDMClientWithIndexedDb(cmixID, notificationsID int, wasmJsPath string, ...@@ -301,7 +259,7 @@ func newDMClientWithIndexedDb(cmixID, notificationsID int, wasmJsPath string,
} }
cm, err := bindings.NewDMClientWithGoEventModel( cm, err := bindings.NewDMClientWithGoEventModel(
cmixID, notificationsID, privateIdentity, model, nuCB) cmixID, notificationsID, privateIdentity, model, cbs)
if err != nil { if err != nil {
reject(exception.NewTrace(err)) reject(exception.NewTrace(err))
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment