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

General fixes

parent 0c0ef87a
No related branches found
No related tags found
2 merge requests!131General fixes,!109Project/haven beta
......@@ -9,10 +9,10 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/jwalterweatherman v1.1.0
github.com/stretchr/testify v1.8.2
gitlab.com/elixxir/client/v4 v4.6.4-0.20230612202411-854f86b27003
gitlab.com/elixxir/crypto v0.0.7-0.20230607170539-92d9508c78f9
gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c
gitlab.com/elixxir/wasm-utils v0.0.0-20230607204433-22c46f9d680f
gitlab.com/elixxir/client/v4 v4.6.4-0.20230614165001-88511b228887
gitlab.com/elixxir/crypto v0.0.7-0.20230614163813-d3c97c54576e
gitlab.com/elixxir/primitives v0.0.3-0.20230613193928-8cf8bdd777ef
gitlab.com/elixxir/wasm-utils v0.0.0-20230608180705-3099f411611c
gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd
gitlab.com/xx_network/primitives v0.0.4-0.20230522171102-940cdd68e516
golang.org/x/crypto v0.5.0
......@@ -29,12 +29,10 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // 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/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/golang/protobuf v1.5.2 // 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/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
......@@ -43,33 +41,24 @@ require (
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.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-sqlite3 v1.14.15 // 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/oasisprotocol/curve25519-voi v0.0.0-20221003100820-41fad3beba17 // 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/rs/cors v1.8.2 // indirect
github.com/sethvargo/go-diceware v0.3.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // 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/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/libphonenumber v1.2.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
gitlab.com/elixxir/bloomfilter v0.0.0-20230322223210-fa84f6842de8 // indirect
gitlab.com/elixxir/comms v0.0.4-0.20230519211512-4a998f4b0938 // indirect
gitlab.com/elixxir/comms v0.0.4-0.20230608201134-3cac2b04fb52 // indirect
gitlab.com/elixxir/ekv v0.3.1-0.20230525213559-f9da13f4fce1 // indirect
gitlab.com/xx_network/comms v0.0.4-0.20230214180029-5387fb85736d // indirect
gitlab.com/xx_network/ring v0.0.3-0.20220902183151-a7d3b15bc981 // indirect
......@@ -84,8 +73,6 @@ require (
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.49.0 // 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
gorm.io/driver/sqlite v1.4.4 // indirect
gorm.io/gorm v1.24.3 // indirect
......
This diff is collapsed.
......@@ -43,8 +43,6 @@ func (m *manager) registerCallbacks() {
m.wtm.RegisterCallback(wDm.ReceiveReactionTag, m.receiveReactionCB)
m.wtm.RegisterCallback(wDm.UpdateSentStatusTag, m.updateSentStatusCB)
m.wtm.RegisterCallback(wDm.BlockSenderTag, m.blockSenderCB)
m.wtm.RegisterCallback(wDm.UnblockSenderTag, m.unblockSenderCB)
m.wtm.RegisterCallback(wDm.GetConversationTag, m.getConversationCB)
m.wtm.RegisterCallback(wDm.GetConversationsTag, m.getConversationsCB)
}
......@@ -204,20 +202,6 @@ func (m *manager) updateSentStatusCB(data []byte) ([]byte, error) {
return nil, nil
}
// blockSenderCB is the callback for wasmModel.BlockSender. Always
// returns nil; meaning, no response is supplied (or expected).
func (m *manager) blockSenderCB(data []byte) ([]byte, error) {
m.model.BlockSender(data)
return nil, nil
}
// unblockSenderCB is the callback for wasmModel.UnblockSender. Always
// returns nil; meaning, no response is supplied (or expected).
func (m *manager) unblockSenderCB(data []byte) ([]byte, error) {
m.model.UnblockSender(data)
return nil, nil
}
// getConversationCB is the callback for wasmModel.GetConversation.
// Returns nil on error or the JSON marshalled Conversation on success.
func (m *manager) getConversationCB(data []byte) ([]byte, error) {
......
......@@ -250,14 +250,6 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
w.wh.SendMessage(UpdateSentStatusTag, data, nil)
}
func (w *wasmModel) BlockSender(senderPubKey ed25519.PublicKey) {
w.wh.SendMessage(BlockSenderTag, senderPubKey, nil)
}
func (w *wasmModel) UnblockSender(senderPubKey ed25519.PublicKey) {
w.wh.SendMessage(UnblockSenderTag, senderPubKey, nil)
}
func (w *wasmModel) GetConversation(senderPubKey ed25519.PublicKey) *dm.ModelConversation {
resultChan := make(chan *dm.ModelConversation)
w.wh.SendMessage(GetConversationTag, senderPubKey,
......
......@@ -23,8 +23,6 @@ const (
ReceiveTextTag worker.Tag = "ReceiveText"
UpdateSentStatusTag worker.Tag = "UpdateSentStatusTag"
BlockSenderTag worker.Tag = "BlockSender"
UnblockSenderTag worker.Tag = "UnblockSender"
GetConversationTag worker.Tag = "GetConversation"
GetConversationsTag worker.Tag = "GetConversations"
)
......@@ -143,7 +143,7 @@ func setGlobals() {
js.Global().Set("NewDatabaseCipher",
js.FuncOf(wasm.NewDatabaseCipher))
// wasm/dm.go
// wasm/channelsFileTransfer.go
js.Global().Set("InitChannelsFileTransfer",
js.FuncOf(wasm.InitChannelsFileTransfer))
......@@ -153,8 +153,8 @@ func setGlobals() {
js.FuncOf(wasm.NewDMClientWithIndexedDb))
js.Global().Set("NewDMClientWithIndexedDbUnsafe",
js.FuncOf(wasm.NewDMClientWithIndexedDbUnsafe))
js.Global().Set("NewDMsDatabaseCipher",
js.FuncOf(wasm.NewDatabaseCipher))
js.Global().Set("NewDMsDatabaseCipher", js.FuncOf(wasm.NewDatabaseCipher))
js.Global().Set("DecodeDMShareURL", js.FuncOf(wasm.DecodeDMShareURL))
// wasm/cmix.go
js.Global().Set("NewCmix", js.FuncOf(wasm.NewCmix))
......
......@@ -1642,17 +1642,20 @@ func (cm *ChannelsManager) SetMobileNotificationsLevel(_ js.Value, args []js.Val
return nil
}
// GetNotificationReportsForMe checks the notification data against the filter
// list to determine which notifications belong to the user. A list of
// GetChannelNotificationReportsForMe 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:
// - notificationFilterJSON - JSON of a slice of [channels.NotificationFilter].
// - notificationDataJSON - JSON of a slice of [notifications.Data].
// It can optionally be the entire json return from
// [bindings.NotificationUpdateJson] instead of just the needed subsection
// (Uint8Array).
// - notificationDataCSV - CSV containing notification data (string).
//
// Example JSON of a slice of [channels.NotificationFilter]:
// [
//
// [
// {
// "identifier": "O8NUg0KaDo18ybTKajXM/sgqEYS37+lewPhGV/2sMAUDYXN5bUlkZW50aWZpZXI=",
// "channelID": "O8NUg0KaDo18ybTKajXM/sgqEYS37+lewPhGV/2sMAUD",
......@@ -1682,32 +1685,16 @@ func (cm *ChannelsManager) SetMobileNotificationsLevel(_ js.Value, args []js.Val
// }
// ]
//
// Example JSON of a slice of [notifications.Data]:
//
// [
// {
// "EphemeralID": -6475,
// "RoundID": 875,
// "IdentityFP": "jWG/UuxRjD80HEo0WX3KYIag5LCfgaWKAg==",
// "MessageHash": "hDGE46QWa3d70y5nJTLbEaVmrFJHOyp2"
// },
// {
// "EphemeralID": -2563,
// "RoundID": 875,
// "IdentityFP": "gL4nhCGKPNBm6YZ7KC0v4JThw65N9bRLTQ==",
// "MessageHash": "WcS4vGrSWDK8Kj7JYOkMo8kSh1Xti94V"
// },
// {
// "EphemeralID": -13247,
// "RoundID": 875,
// "IdentityFP": "qV3uD++VWPhD2rRMmvrP9j8hp+jpFSsUHg==",
// "MessageHash": "VX6Tw7N48j7U2rRXYle20mFZi0If4CB1"
// }
// ]
//
// Returns:
// - The JSON of a slice of [channels.NotificationReport] (Uint8Array).
// - Throws an error if getting the report fails.
//
// Example return:
//
// [
// {"channel":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD","type":1},
// {"channel":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD","type":2}
// ]
func GetChannelNotificationReportsForMe(_ js.Value, args []js.Value) any {
notificationFilterJSON := utils.CopyBytesToGo(args[0])
notificationDataCSV := args[1].String()
......
......@@ -137,9 +137,11 @@ func (r *RemoteKV) Set(_ js.Value, args []js.Value) any {
return utils.CreatePromise(promiseFn)
}
// GetPrefix returns the full Prefix of the KV
// Returns a string via a Promise
func (r *RemoteKV) GetPrefix(_ js.Value, args []js.Value) any {
// GetPrefix returns the full prefix of the KV.
//
// Returns a promise:
// - Resolves to the prefix (string).
func (r *RemoteKV) GetPrefix(js.Value, []js.Value) any {
promiseFn := func(resolve, reject func(args ...any) js.Value) {
prefix := r.api.GetPrefix()
resolve(prefix)
......@@ -169,7 +171,7 @@ func (r *RemoteKV) HasPrefix(_ js.Value, args []js.Value) any {
// - args[0] - the prefix to append to the list of prefixes
//
// Returns a promise:
// - Resolves to a new RemoteKV
// - Resolves to a new [RemoteKV].
// - Rejected with an error.
func (r *RemoteKV) Prefix(_ js.Value, args []js.Value) any {
prefix := args[0].String()
......@@ -187,11 +189,14 @@ func (r *RemoteKV) Prefix(_ js.Value, args []js.Value) any {
return utils.CreatePromise(promiseFn)
}
// Root returns the KV with no prefixes
func (r *RemoteKV) Root(_ js.Value, args []js.Value) any {
// Root returns the KV with no prefixes.
//
// Returns a promise:
// - Resolves to a new [RemoteKV].
// - Rejected with an error on failure.
func (r *RemoteKV) Root(js.Value, []js.Value) any {
promiseFn := func(resolve, reject func(args ...any) js.Value) {
newAPI, err := r.api.Root()
if err != nil {
reject(exception.NewTrace(err))
} else {
......@@ -202,8 +207,12 @@ func (r *RemoteKV) Root(_ js.Value, args []js.Value) any {
return utils.CreatePromise(promiseFn)
}
// IsMemStore returns true if the underlying KV is memory based
func (r *RemoteKV) IsMemStore(_ js.Value, args []js.Value) any {
// IsMemStore returns true if the underlying KV is memory based.
//
// Returns a promise:
// - Resolves to a boolean.
// - Rejected with an error.
func (r *RemoteKV) IsMemStore(js.Value, []js.Value) any {
promiseFn := func(resolve, reject func(args ...any) js.Value) {
resolve(r.api.IsMemStore())
}
......@@ -378,20 +387,19 @@ func (r *RemoteKV) GetMapElement(_ js.Value, args []js.Value) any {
return utils.CreatePromise(promiseFn)
}
// ListenOnRemoteKey sets up a callback listener for the object specified
// by the key and version. It returns the current [versioned.Object] JSON
// of the value.
// Parameters:
// - args[0] - the key string
// - args[1] - the version int
// - args[2] - the [KeyChangedByRemoteCallback] javascript callback
// - args[3] - set the localEvents flag to true or false (optional)
// ListenOnRemoteKey sets up a callback listener for the object specified by the
// key and version. It returns the ID of the callback or -1.
// The version and "localEvents" flags are only respected on first call.
//
// Returns a promise with an error if any or the json of the existing
// [versioned.Object], e.g.:
// Parameters:
// - args[0] - The key (string).
// - args[1] - The version (int).
// - args[2] - The [KeyChangedByRemoteCallback] Javascript callback.
// - args[3] - Toggle local events (optional) (boolean).
//
// {"Version":1,"Timestamp":"2023-05-13T00:50:03.889192694Z",
// "Data":"bm90IHVwZ3JhZGVk"}
// Returns a promise:
// - Resolves to the callback ID (int).
// - Rejects with an error on failure.
func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any {
key := args[0].String()
version := int64(args[1].Int())
......@@ -403,31 +411,30 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any {
}
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.ListenOnRemoteKey(key, version, cb, localEvents)
id, err := r.api.ListenOnRemoteKey(key, version, cb, localEvents)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
resolve(id)
}
}
return utils.CreatePromise(promiseFn)
}
// ListenOnRemoteMap allows the caller to receive updates when
// the map or map elements are updated. Returns a JSON of
// map[string]versioned.Object of the current map value.
// ListenOnRemoteMap allows the caller to receive updates when the map or map
// elements are updated. It returns the ID of the callback or -1 and an error.
// The version and "localEvents" flags are only respected on first call.
//
// Parameters:
// - args[0] - the mapName string
// - args[1] - the version int
// - args[0] - The key (string).
// - args[1] - The version (int).
// - args[2] - the [MapChangedByRemoteCallback] javascript callback
// - args[3] - set the localEvents flag to true or false (optional)
// - args[3] - Toggle local events (optional) (boolean).
//
// Returns a promise with an error if any or the json of the existing
// the [map[string]versioned.Object] JSON value, e.g.:
//
// {"elementKey": {"Version":1,"Timestamp":"2023-05-13T00:50:03.889192694Z",
// "Data":"bm90IHVwZ3JhZGVk"}}
// Returns a promise:
// - Resolves to the callback ID (int).
// - Rejects with an error on failure.
func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any {
mapName := args[0].String()
version := int64(args[1].Int())
......@@ -439,11 +446,11 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any {
}
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.ListenOnRemoteMap(mapName, version, cb, localEvents)
id, err := r.api.ListenOnRemoteMap(mapName, version, cb, localEvents)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
resolve(id)
}
}
......
......@@ -50,8 +50,10 @@ func newDMClientJS(api *bindings.DMClient) map[string]any {
"ExportPrivateIdentity": js.FuncOf(cm.ExportPrivateIdentity),
"GetNickname": js.FuncOf(cm.GetNickname),
"SetNickname": js.FuncOf(cm.SetNickname),
"BlockPartner": js.FuncOf(cm.BlockPartner),
"UnblockPartner": js.FuncOf(cm.UnblockPartner),
"IsBlocked": js.FuncOf(cm.IsBlocked),
"GetBlockedSenders": js.FuncOf(cm.GetBlockedSenders),
"GetBlockedPartners": js.FuncOf(cm.GetBlockedPartners),
"GetDatabaseName": js.FuncOf(cm.GetDatabaseName),
// Share URL
......@@ -63,15 +65,72 @@ func newDMClientJS(api *bindings.DMClient) map[string]any {
"SendReaction": js.FuncOf(cm.SendReaction),
"SendSilent": js.FuncOf(cm.SendSilent),
"Send": js.FuncOf(cm.Send),
// User Mute/Unmute
"BlockSender": js.FuncOf(cm.BlockSender),
"UnblockSender": js.FuncOf(cm.UnblockSender),
}
return dmClientMap
}
// newDmNotificationUpdate adds the callbacks from the Javascript object.
func newDmNotificationUpdate(value js.Value) *dmNotificationUpdate {
return &dmNotificationUpdate{callback: utils.WrapCB(value, "Callback")}
}
// dmNotificationUpdate wraps Javascript callbacks to adhere to the
// [bindings.DmNotificationUpdate] interface.
type dmNotificationUpdate struct {
callback func(args ...any) js.Value
}
// Callback is called everytime there is an update to the notification filter
// or notification status for DMs.
//
// 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
// ([codename.PrivateIdentity]), used for direct messaging.
//
......@@ -83,20 +142,29 @@ func newDMClientJS(api *bindings.DMClient) map[string]any {
// Parameters:
// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved
// using [Cmix.GetID].
// - args[1] - Bytes of a private identity ([codename.PrivateIdentity]) that
// - args[1] - ID of [Notifications] object in tracker. This can be retrieved
// using [Notifications.GetID] (int).
// - args[2] - Bytes of a private identity ([codename.PrivateIdentity]) that
// is generated by [codename.GenerateIdentity] (Uint8Array).
// - args[2] - 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
// the Build function in [bindings.EventModelBuilder].
// - args[4] - A callback that is triggered everytime there is a change to the
// notification status of a DM conversation It must be a Javascript object
// that implements the callback in [bindings.DmNotificationUpdate].
//
// Returns:
// - Javascript representation of the [DMClient] object.
// - Throws an error if creating the manager fails.
func NewDMClient(_ js.Value, args []js.Value) any {
privateIdentity := utils.CopyBytesToGo(args[1])
em := newDMReceiverBuilder(args[2])
cmixID := args[0].Int()
notificationsID := args[1].Int()
privateIdentity := utils.CopyBytesToGo(args[2])
em := newDMReceiverBuilder(args[3])
nu := newDmNotificationUpdate(args[4])
cm, err := bindings.NewDMClient(args[0].Int(), privateIdentity, em)
cm, err :=
bindings.NewDMClient(cmixID, notificationsID, privateIdentity, em, nu)
if err != nil {
exception.ThrowTrace(err)
return nil
......@@ -119,17 +187,22 @@ func NewDMClient(_ js.Value, args []js.Value) any {
// Parameters:
// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved
// using [Cmix.GetID].
// - args[1] - Path to Javascript file that starts the worker (string).
// - args[2] - Bytes of a private identity ([codename.PrivateIdentity]) that
// - args[1] - ID of [Notifications] object in tracker. This can be retrieved
// using [Notifications.GetID] (int).
// - args[2] - ID of [DbCipher] object in tracker (int). Create this object
// with [NewDatabaseCipher] and get its id with [DbCipher.GetID].
// - args[3] - Path to Javascript file that starts the worker (string).
// - args[4] - Bytes of a private identity ([codename.PrivateIdentity]) that
// is generated by [codename.GenerateIdentity] (Uint8Array).
// - args[3] - The message receive callback. It is a function that takes in
// - args[5] - The message receive callback. It is a function that takes in
// the same parameters as [dm.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.
// messageUpdate is true if the message already exists and was edited.
// conversationUpdate is true if the Conversation was created or modified.
// - args[4] - ID of [DbCipher] object in tracker (int). Create this object
// with [NewDatabaseCipher] and get its id with [DbCipher.GetID].
// - args[6] - A callback that is triggered everytime there is a change to the
// notification status of a DM conversation It must be a Javascript object
// that implements the callback in [bindings.DmNotificationUpdate].
//
// Returns:
// - Resolves to a Javascript representation of the [DMClient] object.
......@@ -137,18 +210,20 @@ func NewDMClient(_ js.Value, args []js.Value) any {
// - Throws an error if the cipher ID does not correspond to a cipher.
func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any {
cmixID := args[0].Int()
wasmJsPath := args[1].String()
privateIdentity := utils.CopyBytesToGo(args[2])
messageReceivedCB := args[3]
cipherID := args[4].Int()
notificationsID := args[1].Int()
cipherID := args[2].Int()
wasmJsPath := args[3].String()
privateIdentity := utils.CopyBytesToGo(args[4])
messageReceivedCB := args[5]
nu := newDmNotificationUpdate(args[6])
cipher, err := dbCipherTrackerSingleton.get(cipherID)
if err != nil {
exception.ThrowTrace(err)
}
return newDMClientWithIndexedDb(
cmixID, wasmJsPath, privateIdentity, messageReceivedCB, cipher)
return newDMClientWithIndexedDb(cmixID, notificationsID, wasmJsPath,
privateIdentity, messageReceivedCB, cipher, nu)
}
// NewDMClientWithIndexedDbUnsafe creates a new [DMClient] from a private
......@@ -166,31 +241,38 @@ func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any {
// Parameters:
// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved
// using [Cmix.GetID].
// - args[1] - Path to Javascript file that starts the worker (string).
// - args[2] - Bytes of a private identity ([codename.PrivateIdentity]) that
// - args[1] - ID of [Notifications] object in tracker. This can be retrieved
// using [Notifications.GetID] (int).
// - args[2] - Path to Javascript file that starts the worker (string).
// - args[3] - Bytes of a private identity ([codename.PrivateIdentity]) that
// is generated by [codename.GenerateIdentity] (Uint8Array).
// - args[3] - The message receive callback. It is a function that takes in
// - args[4] - The message receive callback. It is a function that takes in
// the same parameters as [dm.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.
// messageUpdate is true if the message already exists and was edited.
// conversationUpdate is true if the Conversation was created or modified.
// - args[5] - A callback that is triggered everytime there is a change to the
// notification status of a DM conversation It must be a Javascript object
// that implements the callback in [bindings.DmNotificationUpdate].
//
// Returns a promise:
// - Resolves to a Javascript representation of the [DMClient] object.
// - Rejected with an error if loading indexedDbWorker or the manager fails.
func NewDMClientWithIndexedDbUnsafe(_ js.Value, args []js.Value) any {
cmixID := args[0].Int()
wasmJsPath := args[1].String()
privateIdentity := utils.CopyBytesToGo(args[2])
messageReceivedCB := args[3]
notificationsID := args[1].Int()
wasmJsPath := args[2].String()
privateIdentity := utils.CopyBytesToGo(args[3])
messageReceivedCB := args[4]
nu := newDmNotificationUpdate(args[5])
return newDMClientWithIndexedDb(
cmixID, wasmJsPath, privateIdentity, messageReceivedCB, nil)
return newDMClientWithIndexedDb(cmixID, notificationsID, wasmJsPath,
privateIdentity, messageReceivedCB, nil, nu)
}
func newDMClientWithIndexedDb(cmixID int, wasmJsPath string,
privateIdentity []byte, cb js.Value, cipher *DbCipher) any {
func newDMClientWithIndexedDb(cmixID, notificationsID int, wasmJsPath string,
privateIdentity []byte, cb js.Value, cipher *DbCipher, nuCB bindings.DmNotificationUpdate) any {
messageReceivedCB := func(uuid uint64, pubKey ed25519.PublicKey,
messageUpdate, conversationUpdate bool) {
......@@ -212,7 +294,7 @@ func newDMClientWithIndexedDb(cmixID int, wasmJsPath string,
}
cm, err := bindings.NewDMClientWithGoEventModel(
cmixID, privateIdentity, model)
cmixID, notificationsID, privateIdentity, model, nuCB)
if err != nil {
reject(exception.NewTrace(err))
} else {
......@@ -277,7 +359,7 @@ func (dmc *DMClient) ExportPrivateIdentity(_ js.Value, args []js.Value) any {
//
// Returns:
// - The nickname (string).
// - Throws TypeError if the channel has no nickname set.
// - Throws an error if the channel has no nickname set.
func (dmc *DMClient) GetNickname(_ js.Value, _ []js.Value) any {
nickname, err := dmc.api.GetNickname()
if err != nil {
......@@ -292,38 +374,66 @@ func (dmc *DMClient) GetNickname(_ js.Value, _ []js.Value) any {
//
// Parameters:
// - args[0] - The nickname to set (string).
//
// Returns:
// - Throws an error if setting the nickname fails.
func (dmc *DMClient) SetNickname(_ js.Value, args []js.Value) any {
dmc.api.SetNickname(args[0].String())
err := dmc.api.SetNickname(args[0].String())
if err != nil {
exception.ThrowTrace(err)
return nil
}
return nil
}
// BlockPartner prevents receiving messages and notifications from the partner.
//
// Parameters:
// - args[0] - The partner's [ed25519.PublicKey] key to block (Uint8Array).
func (dmc *DMClient) BlockPartner(_ js.Value, args []js.Value) any {
partnerPubKey := utils.CopyBytesToGo(args[0])
dmc.api.BlockPartner(partnerPubKey)
return nil
}
// UnblockPartner unblocks a blocked partner to allow DM messages.
//
// Parameters:
// - args[0] - The partner's [ed25519.PublicKey] to unblock (Uint8Array).
func (dmc *DMClient) UnblockPartner(_ js.Value, args []js.Value) any {
partnerPubKey := utils.CopyBytesToGo(args[0])
dmc.api.UnblockPartner(partnerPubKey)
return nil
}
// IsBlocked indicates if the given sender is blocked.
// Blocking is controlled by the receiver/EventModel.
// IsBlocked indicates if the given partner is blocked.
//
// Parameters:
// - args[0] - Bytes of the sender's ED25519 public key (Uint8Array).
// - args[0] - The partner's [ed25519.PublicKey] public key to check
// (Uint8Array).
//
// Returns:
// - boolean
func (dmc *DMClient) IsBlocked(_ js.Value, args []js.Value) any {
return dmc.api.IsBlocked(utils.CopyBytesToGo(args[0]))
partnerPubKey := utils.CopyBytesToGo(args[0])
return dmc.api.IsBlocked(partnerPubKey)
}
// GetBlockedSenders returns the ED25519 public keys of all senders who are
// blocked by this user. Blocking is controlled by the receiver/EventModel.
// GetBlockedPartners returns all partners who are blocked by this user.
//
// Returns:
// - JSON of an array of [ed25519.PublicKey] (Uint8Array)
//
// Example JSON return:
// Example return:
//
// [
// "v3TON4ju4FxFvp3D/Df0OFV50QSqmiHPQ/BOHMwRRJ8=",
// "ZsehfwnncIx4NC8WZyhbypC3nfGsiqU21T+bPRC+iIU=",
// "ZuBal443tYZ4j025A6q9xU7xn9ZQF5xB1hbh6LxpBAQ="
// "TYWuCfyGBjNWDtl/Roa6f/o206yYPpuB6sX2kJZTe98=",
// "4JLRzgtW1SZ9c5pE+v0WwrGPj1t19AuU6Gg5IND5ymA=",
// "CWDqF1bnhulW2pko+zgmbDZNaKkmNtFdUgY4bTm2DhA="
// ]
func (dmc *DMClient) GetBlockedSenders(_ js.Value, args []js.Value) any {
return dmc.api.IsBlocked(utils.CopyBytesToGo(args[0]))
func (dmc *DMClient) GetBlockedPartners(js.Value, []js.Value) any {
return utils.CopyBytesToJS(dmc.api.GetBlockedPartners())
}
////////////////////////////////////////////////////////////////////////////////
......@@ -576,30 +686,6 @@ func (dmc *DMClient) GetDatabaseName(js.Value, []js.Value) any {
"_speakeasy_dm"
}
// BlockSender blocks the provided sender public key from sending DMs
//
// Parameters:
// - args[0] - [ed25519.PublicKey] (Uint8Array)
//
// Returns nothing
func (dmc *DMClient) BlockSender(_ js.Value, args []js.Value) any {
senderKey := utils.CopyBytesToGo(args[0])
dmc.api.BlockSender(senderKey)
return nil
}
// UnblockSender unblocks the provided sender public key to allow sending DMs
//
// Parameters:
// - args[0] - [ed25519.PublicKey] (Uint8Array)
//
// Returns nothing
func (dmc *DMClient) UnblockSender(_ js.Value, args []js.Value) any {
senderKey := utils.CopyBytesToGo(args[0])
dmc.api.UnblockSender(senderKey)
return nil
}
////////////////////////////////////////////////////////////////////////////////
// DM Share URL //
////////////////////////////////////////////////////////////////////////////////
......@@ -660,7 +746,6 @@ func (dmc *DMClient) GetShareURL(_ js.Value, args []js.Value) any {
// Returns:
// - JSON of [DMUser] (Uint8Array).
func DecodeDMShareURL(_ js.Value, args []js.Value) any {
url := args[0].String()
report, err := bindings.DecodeDMShareURL(url)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment