diff --git a/go.mod b/go.mod index dae21fc2ed2da5a0fb5ea2cf6be5928ec487bd0c..4b7c1a51dfb84d77a09e025955ebeb0f8660cd81 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ 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.20230622162704-83b958eaee5e + gitlab.com/elixxir/client/v4 v4.6.4-0.20230623182229-d3c9062e6f57 gitlab.com/elixxir/crypto v0.0.7-0.20230614183801-387e0cb8e76f gitlab.com/elixxir/primitives v0.0.3-0.20230613193928-8cf8bdd777ef gitlab.com/elixxir/wasm-utils v0.0.0-20230615222914-185dd3a6fa08 diff --git a/go.sum b/go.sum index e06d9b218ec56cb88b4fc40a6f601766e4c55f2f..4f4af4fd747eced99afaf9e9eef656edd6d868fa 100644 --- a/go.sum +++ b/go.sum @@ -407,8 +407,8 @@ 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-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.4-0.20230622162704-83b958eaee5e h1:B3v0uU8Zx0nnrWiDP+3BgglTV6ZCdfdqWcSo+8ShhYw= -gitlab.com/elixxir/client/v4 v4.6.4-0.20230622162704-83b958eaee5e/go.mod h1:N/zw9nt1ELjMoYmxNUjIQDfAJLdwOqUCqCf9plpsOvY= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230623182229-d3c9062e6f57 h1:b/oQLnntnR6ZJlDGiBK2TlyN3omSxDYZvnAY4itrMyw= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230623182229-d3c9062e6f57/go.mod h1:N/zw9nt1ELjMoYmxNUjIQDfAJLdwOqUCqCf9plpsOvY= gitlab.com/elixxir/comms v0.0.4-0.20230613220741-7de1d2ca4a1c h1:0TpLn4AdarrqCwUMvnz4Md+9gLyk9wrQ73J3W9U5zJo= gitlab.com/elixxir/comms v0.0.4-0.20230613220741-7de1d2ca4a1c/go.mod h1:z+qW0D9VpY5QKTd7wRlb5SK4kBNqLYsa4DXBcUXue9Q= gitlab.com/elixxir/crypto v0.0.7-0.20230614183801-387e0cb8e76f h1:T0Jvhq5nCELiwkVr07Ti/Ew9ICdexviYeCkFV19kk9A= diff --git a/wasm/dm.go b/wasm/dm.go index d571dbf445075e8007226147dfd193fbf9fcec39..aefb688a06240ed1c0f3a132e39642cfa96ddc5a 100644 --- a/wasm/dm.go +++ b/wasm/dm.go @@ -580,7 +580,7 @@ func (dmc *DMClient) SendReply(_ js.Value, args []js.Value) any { // your own. Alternatively, if reacting to another user's message, you may // retrieve it via the [bindings.ChannelMessageReceptionCallback] registered // using [ChannelsManager.RegisterReceiveHandler] (Uint8Array). -// - args[3] - JSON of [xxdk.CMIXParams]. If left empty +// - args[4] - JSON of [xxdk.CMIXParams]. If left empty // [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). // // Returns a promise: @@ -694,6 +694,45 @@ func (dmc *DMClient) SendInvite(_ js.Value, args []js.Value) any { return utils.CreatePromise(promiseFn) } +// DeleteMessage sends a message to the partner to delete a message this user +// sent. Also deletes it from the local database. +// +// 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] -The bytes of the [message.ID] of the message to delete. This may +// be found in the [bindings.ChannelSendReport] (Uint8Array). +// - args[3] - 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 (dmc *DMClient) DeleteMessage(_ js.Value, args []js.Value) any { + partnerPubKeyBytes := utils.CopyBytesToGo(args[0]) + partnerToken := args[1].Int() + targetMessageIdBytes := utils.CopyBytesToGo(args[2]) + cmixParamsJSON := utils.CopyBytesToGo(args[4]) + + jww.DEBUG.Printf("DeleteMessage(%s, %d, %s)", + base64.RawStdEncoding.EncodeToString(partnerPubKeyBytes)[:8], + partnerToken, + base64.RawStdEncoding.EncodeToString(targetMessageIdBytes)) + + promiseFn := func(resolve, reject func(args ...any) js.Value) { + sendReport, err := dmc.api.DeleteMessage(partnerPubKeyBytes, + partnerToken, targetMessageIdBytes, 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. //