Skip to content
Snippets Groups Projects
Commit f2b66f5d authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'XX-4601/HavenInvites' into 'project/HavenBeta'

Xx 4601/haven invites

See merge request !100
parents c9280e2b 9e9be645
No related branches found
No related tags found
2 merge requests!109Project/haven beta,!100Xx 4601/haven invites
......@@ -59,6 +59,7 @@ func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]any {
"SendReply": js.FuncOf(cm.SendReply),
"SendReaction": js.FuncOf(cm.SendReaction),
"SendSilent": js.FuncOf(cm.SendSilent),
"SendInvite": js.FuncOf(cm.SendInvite),
"DeleteMessage": js.FuncOf(cm.DeleteMessage),
"PinMessage": js.FuncOf(cm.PinMessage),
"MuteUser": js.FuncOf(cm.MuteUser),
......@@ -622,6 +623,32 @@ func DecodePrivateURL(_ js.Value, args []js.Value) any {
return c
}
// DecodeInviteURL decodes the channel URL, using the password, into a channel
// pretty print. This function can only be used for URLs from invitations.
//
// Parameters:
// - args[0] - The channel's share URL (string). Should be received from
// another user via invitation.
// - args[1] - The password needed to decrypt the secret data in the URL
// (string).
//
// Returns:
// - The channel pretty print (string)
func DecodeInviteURL(_ js.Value, args []js.Value) any {
var (
url = args[0].String()
password = args[1].String()
)
c, err := bindings.DecodeInviteURL(url, password)
if err != nil {
exception.ThrowTrace(err)
return nil
}
return c
}
// GetChannelJSON returns the JSON of the channel for the given pretty print.
//
// Parameters:
......@@ -1232,6 +1259,64 @@ func (cm *ChannelsManager) SendSilent(_ 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] - JSON of the invitee channel [id.ID].
// This can be retrieved from [GetChannelJSON]. (Uint8Array).
// - args[2] - The contents of the message (string).
// - args[3] - The URL to append the channel info to (string).
// - args[4] - 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[5] - JSON of [xxdk.CMIXParams]. If left empty
// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array).
// - args[6] - JSON of a slice of public keys of users that should receive
// mobile notifications for the message.
//
// Example slice of public keys:
//
// [
// "FgJMvgSsY4rrKkS/jSe+vFOJOs5qSSyOUSW7UtF9/KU=",
// "fPqcHtrJ398PAC35QyWXEU9PHzz8Z4BKQTCxSvpSygw=",
// "JnjCgh7g/+hNiI9VPKW01aRSxGOFmNulNCymy3ImXAo="
// ]
//
// 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])
inviteToJSON = utils.CopyBytesToGo(args[1])
msg = args[2].String()
host = args[3].String()
leaseTimeMS = int64(args[4].Int())
cmixParamsJSON = utils.CopyBytesToGo(args[5])
pingsJSON = utils.CopyBytesToGo(args[6])
)
promiseFn := func(resolve, reject func(args ...any) js.Value) {
sendReport, err := cm.api.SendInvite(marshalledChanId,
inviteToJSON, msg, host, leaseTimeMS,
cmixParamsJSON, pingsJSON)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve(utils.CopyBytesToJS(sendReport))
}
}
return utils.CreatePromise(promiseFn)
}
////////////////////////////////////////////////////////////////////////////////
// Admin Sending //
////////////////////////////////////////////////////////////////////////////////
......
......@@ -63,6 +63,7 @@ func newDMClientJS(api *bindings.DMClient) map[string]any {
"SendText": js.FuncOf(cm.SendText),
"SendReply": js.FuncOf(cm.SendReply),
"SendReaction": js.FuncOf(cm.SendReaction),
"SendInvite": js.FuncOf(cm.SendInvite),
"SendSilent": js.FuncOf(cm.SendSilent),
"Send": js.FuncOf(cm.Send),
......@@ -553,7 +554,8 @@ func (dmc *DMClient) SendReply(_ js.Value, args []js.Value) any {
// Users will drop the reaction if they do not recognize the reactTo message.
//
// Parameters:
// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array).
// - args[0] - The bytes of the public key of the partner's ED25519 signing
// key (Uint8Array).
// - args[1] - The token used to derive the reception ID for the partner (int).
// - args[2] - The user's reaction. This should be a single emoji with no
// other characters. As such, a Unicode string is expected (string).
......@@ -630,6 +632,52 @@ func (dmc *DMClient) SendSilent(_ js.Value, args []js.Value) any {
return utils.CreatePromise(promiseFn)
}
// SendInvite is used to send to a DM partner an invitation to another
// channel.
//
// If the channel ID for the invitee channel is not recognized by the Manager,
// then an error will be returned.
//
// Parameters:
// - args[0] - The bytes of the public key of the partner's ED25519 signing
// key (Uint8Array).
// - args[1] - The token used to derive the reception ID for the partner (int).
// - args[2] - JSON of the invitee channel [id.ID].
// This can be retrieved from [GetChannelJSON]. (Uint8Array).
// - args[3] - The contents of the message. The message should be at most 510
// bytes. This is expected to be Unicode, and thus a string data type is
// expected.
// - args[4] - The URL to append the channel info to.
// - args[5] - A JSON marshalled [xxdk.CMIXParams]. This may be empty,
// and GetDefaultCMixParams will be used internally.
//
// Returns a promise:
// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array).
// - Rejected with an error if sending fails.
func (dmc *DMClient) SendInvite(_ js.Value, args []js.Value) any {
var (
partnerPubKeyBytes = utils.CopyBytesToGo(args[0])
partnerToken = int32(args[1].Int())
inviteToJSON = utils.CopyBytesToGo(args[2])
msg = args[3].String()
host = args[4].String()
cmixParamsJSON = utils.CopyBytesToGo(args[5])
)
promiseFn := func(resolve, reject func(args ...any) js.Value) {
sendReport, err := dmc.api.SendInvite(
partnerPubKeyBytes, partnerToken, inviteToJSON, msg, host,
cmixParamsJSON)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve(utils.CopyBytesToJS(sendReport))
}
}
return utils.CreatePromise(promiseFn)
}
// Send is used to send a raw message. In general, it
// should be wrapped in a function that defines the wire protocol.
//
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment