From 3a13df2744f6b49a6ef1c90f5b39dd98d5f3192d Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Tue, 25 Apr 2023 16:10:40 -0700 Subject: [PATCH] Add channels.SendInvite bindings --- go.mod | 8 +++---- go.sum | 8 +++++++ wasm/channels.go | 59 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 27aeded3..78310690 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/hack-pad/go-indexeddb v0.2.0 github.com/pkg/errors v0.9.1 github.com/spf13/jwalterweatherman v1.1.0 - gitlab.com/elixxir/client/v4 v4.6.2-0.20230425190953-cd51598e9245 - gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32 + gitlab.com/elixxir/client/v4 v4.6.2-0.20230425224351-c51d46dbbc1e + gitlab.com/elixxir/crypto v0.0.7-0.20230424221508-14c052d4b967 gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd gitlab.com/xx_network/primitives v0.0.4-0.20230310205521-c440e68e34c4 @@ -62,8 +62,8 @@ require ( 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-20230315224936-a4459418f300 // indirect - gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b // indirect + gitlab.com/elixxir/bloomfilter v0.0.0-20230322223210-fa84f6842de8 // indirect + gitlab.com/elixxir/comms v0.0.4-0.20230322130755-e59b16bce601 // indirect gitlab.com/elixxir/ekv v0.2.1 // 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 diff --git a/go.sum b/go.sum index 5d38a7b8..96bc1640 100644 --- a/go.sum +++ b/go.sum @@ -505,14 +505,22 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo= github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= gitlab.com/elixxir/bloomfilter v0.0.0-20230315224936-a4459418f300 h1:oF3Pkf5NBb48KB89Q4sQXKQCIsWp1IVsqKWHWFsfBRc= gitlab.com/elixxir/bloomfilter v0.0.0-20230315224936-a4459418f300/go.mod h1:1X8gRIAPDisS3W6Vtr/ymiUmZMJUIwDV1o5DEOo/pzw= +gitlab.com/elixxir/bloomfilter v0.0.0-20230322223210-fa84f6842de8 h1:uAFCyBkXprQoPkcDDfxXtaMyL5x+xSGrAWzR907xROQ= +gitlab.com/elixxir/bloomfilter v0.0.0-20230322223210-fa84f6842de8/go.mod h1:1X8gRIAPDisS3W6Vtr/ymiUmZMJUIwDV1o5DEOo/pzw= gitlab.com/elixxir/client/v4 v4.6.2-0.20230413171204-002612660098 h1:bdwXgEa0i9KpLiKQdhv6MEWAYLt3MsbNuIzFanVpWLY= gitlab.com/elixxir/client/v4 v4.6.2-0.20230413171204-002612660098/go.mod h1:G+lN+LvQPGcm5BQnrhnqT1xiRIAzH3OffAM+5oI9SUg= gitlab.com/elixxir/client/v4 v4.6.2-0.20230425190953-cd51598e9245 h1:pBwoSYD+BFIr5Wyc+PQhqm+fZGsRSNXCpF0z1cQQzK8= gitlab.com/elixxir/client/v4 v4.6.2-0.20230425190953-cd51598e9245/go.mod h1:G+lN+LvQPGcm5BQnrhnqT1xiRIAzH3OffAM+5oI9SUg= +gitlab.com/elixxir/client/v4 v4.6.2-0.20230425224351-c51d46dbbc1e h1:Ey6eRhlbmeVp45VrTxxRXwcA7hBe54IosTSQ0t9HHeM= +gitlab.com/elixxir/client/v4 v4.6.2-0.20230425224351-c51d46dbbc1e/go.mod h1:FvhgMxYfVF+wG5BspDoAmNy9GiI2bZQXiswGpzOLWPM= gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b h1:8AVK93UEs/aufoqtFgyMVt9gf0oJ8F4pA60ZvEVvG+s= gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b/go.mod h1:z+qW0D9VpY5QKTd7wRlb5SK4kBNqLYsa4DXBcUXue9Q= +gitlab.com/elixxir/comms v0.0.4-0.20230322130755-e59b16bce601 h1:l9ZVDOXf0fvbFnNXWmwnsEIvUIUL5fy3mFexrYg8dx4= +gitlab.com/elixxir/comms v0.0.4-0.20230322130755-e59b16bce601/go.mod h1:z+qW0D9VpY5QKTd7wRlb5SK4kBNqLYsa4DXBcUXue9Q= gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32 h1:Had0F7rMPgJJ2BUZoFNgeJq33md9RpV15nvd08Uxdzc= gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32/go.mod h1:/SLOlvkYVVJf6IU+vEjMLnS7cjjcoTlPV45g6tv6INc= +gitlab.com/elixxir/crypto v0.0.7-0.20230424221508-14c052d4b967 h1:yKGoNe9xtHROwbep7yGYhTvbxm4cSRycduAkEArTE9s= +gitlab.com/elixxir/crypto v0.0.7-0.20230424221508-14c052d4b967/go.mod h1:/SLOlvkYVVJf6IU+vEjMLnS7cjjcoTlPV45g6tv6INc= gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is= gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c h1:muG8ff95woeVVwQoJHCEclxBFB22lc7EixPylEkYDRU= diff --git a/wasm/channels.go b/wasm/channels.go index 307fe5ce..88f679ce 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -60,6 +60,7 @@ func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]any { "SendMessage": js.FuncOf(cm.SendMessage), "SendReply": js.FuncOf(cm.SendReply), "SendReaction": js.FuncOf(cm.SendReaction), + "SendInvite": js.FuncOf(cm.SendInvite), "DeleteMessage": js.FuncOf(cm.DeleteMessage), "PinMessage": js.FuncOf(cm.PinMessage), "MuteUser": js.FuncOf(cm.MuteUser), @@ -1038,9 +1039,10 @@ func (cm *ChannelsManager) SendGeneric(_ js.Value, args []js.Value) any { tracked := args[4].Bool() cmixParamsJSON := utils.CopyBytesToGo(args[5]) + // fixme: add pings to wasm promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := cm.api.SendGeneric(marshalledChanId, messageType, - msg, leaseTimeMS, tracked, cmixParamsJSON) + msg, leaseTimeMS, tracked, cmixParamsJSON, nil) if err != nil { reject(utils.JsTrace(err)) } else { @@ -1081,8 +1083,9 @@ func (cm *ChannelsManager) SendMessage(_ js.Value, args []js.Value) any { cmixParamsJSON := utils.CopyBytesToGo(args[3]) promiseFn := func(resolve, reject func(args ...any) js.Value) { + // fixme: add pings to wasm sendReport, err := cm.api.SendMessage( - marshalledChanId, msg, leaseTimeMS, cmixParamsJSON) + marshalledChanId, msg, leaseTimeMS, cmixParamsJSON, nil) if err != nil { reject(utils.JsTrace(err)) } else { @@ -1131,8 +1134,9 @@ func (cm *ChannelsManager) SendReply(_ js.Value, args []js.Value) any { cmixParamsJSON := utils.CopyBytesToGo(args[4]) promiseFn := func(resolve, reject func(args ...any) js.Value) { + // fixme: add pings to wasm sendReport, err := cm.api.SendReply(marshalledChanId, msg, - messageToReactTo, leaseTimeMS, cmixParamsJSON) + messageToReactTo, leaseTimeMS, cmixParamsJSON, nil) if err != nil { reject(utils.JsTrace(err)) } else { @@ -1191,6 +1195,55 @@ func (cm *ChannelsManager) SendReaction(_ js.Value, args []js.Value) any { return utils.CreatePromise(promiseFn) } +// SendInvite is used to send to a channel (invited) an invitation to another +// channel (invitee). +// +// If the channel ID for the invitee channel is not recognized by the Manager, +// then an error will be returned. +// +// Parameters: +// - args[0] - Marshalled bytes of the invited channel [id.ID] (Uint8Array). +// - args[1] - Marshalled bytes of the invitee channel [id.ID] (Uint8Array). +// - args[2] - The contents of the message (string). +// - args[3] - The URL to append the channel info to (string). +// - args[4] - The maximum number of uses the link can be used (0 for +// unlimited) (int). +// - args[5] - The lease of the message. This will be how long the +// message is available from the network, in milliseconds (int). As per the +// [channels.Manager] documentation, this has different meanings depending +// on the use case. These use cases may be generic enough that they will not +// be enumerated here. Use [ValidForever] to last the max message life. +// - args[6] - JSON of [xxdk.CMIXParams]. If left empty +// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). +// +// Returns a promise: +// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). +// - Rejected with an error if sending fails. +func (cm *ChannelsManager) SendInvite(_ js.Value, args []js.Value) any { + var ( + marshalledChanId = utils.CopyBytesToGo(args[0]) + marshalledInviteToId = utils.CopyBytesToGo(args[1]) + msg = args[2].String() + host = args[3].String() + maxUses = args[4].Int() + leaseTimeMS = int64(args[4].Int()) + cmixParamsJSON = utils.CopyBytesToGo(args[5]) + ) + + promiseFn := func(resolve, reject func(args ...any) js.Value) { + sendReport, err := cm.api.SendInvite(marshalledChanId, + marshalledInviteToId, msg, host, maxUses, leaseTimeMS, + cmixParamsJSON) + if err != nil { + reject(utils.JsTrace(err)) + } else { + resolve(utils.CopyBytesToJS(sendReport)) + } + } + + return utils.CreatePromise(promiseFn) +} + //////////////////////////////////////////////////////////////////////////////// // Admin Sending // //////////////////////////////////////////////////////////////////////////////// -- GitLab