From 5f5172b84359f6e5f9a91e1b3d8a04bfe91be9a1 Mon Sep 17 00:00:00 2001
From: jbhusson <jonah@elixxir.io>
Date: Tue, 28 Feb 2023 15:30:12 -0500
Subject: [PATCH] Add AreDMsEnabled to channels

---
 go.mod           |  2 +-
 go.sum           |  2 ++
 wasm/channels.go | 19 +++++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/go.mod b/go.mod
index c144105f..715d8126 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,7 @@ require (
 	github.com/pkg/errors v0.9.1
 	github.com/spf13/cobra v1.5.0
 	github.com/spf13/jwalterweatherman v1.1.0
-	gitlab.com/elixxir/client/v4 v4.3.12-0.20230228194909-c9c2601830c2
+	gitlab.com/elixxir/client/v4 v4.3.12-0.20230228202420-22c4d11f2d7f
 	gitlab.com/elixxir/crypto v0.0.7-0.20230214180106-72841fd1e426
 	gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c
 	gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd
diff --git a/go.sum b/go.sum
index d8e51484..1349e709 100644
--- a/go.sum
+++ b/go.sum
@@ -513,6 +513,8 @@ gitlab.com/elixxir/client/v4 v4.3.12-0.20230228180957-c62cc589d560 h1:wTIZoSxI/W
 gitlab.com/elixxir/client/v4 v4.3.12-0.20230228180957-c62cc589d560/go.mod h1:Hjx99EdI86q67mHzZVR2Dw37fuTCzDaChM/NVX3CcPU=
 gitlab.com/elixxir/client/v4 v4.3.12-0.20230228194909-c9c2601830c2 h1:cjObCobCH0IMSMEs57yAboAWPS1v8vpzO0ErHH5s4k8=
 gitlab.com/elixxir/client/v4 v4.3.12-0.20230228194909-c9c2601830c2/go.mod h1:Hjx99EdI86q67mHzZVR2Dw37fuTCzDaChM/NVX3CcPU=
+gitlab.com/elixxir/client/v4 v4.3.12-0.20230228202420-22c4d11f2d7f h1:raZyLq0MSjY33jXg5g2NgFl68LM1JJkAO3+0CHly15c=
+gitlab.com/elixxir/client/v4 v4.3.12-0.20230228202420-22c4d11f2d7f/go.mod h1:Hjx99EdI86q67mHzZVR2Dw37fuTCzDaChM/NVX3CcPU=
 gitlab.com/elixxir/comms v0.0.4-0.20230214180204-3aba2e6795af h1:Eye4+gZEUbOfz4j51WplYD9d7Gnr1s3wKYkEnCfhPaw=
 gitlab.com/elixxir/comms v0.0.4-0.20230214180204-3aba2e6795af/go.mod h1:ud3s2aHx5zu7lJhBpUMUXxjLwl8PH8z8cl64Om9U7q8=
 gitlab.com/elixxir/crypto v0.0.7-0.20230214180106-72841fd1e426 h1:O9Xz/ioc9NAj5k/QUsR0W4LCz2uVHawJF89yPTI7NXk=
diff --git a/wasm/channels.go b/wasm/channels.go
index b2138aa8..3a135cac 100644
--- a/wasm/channels.go
+++ b/wasm/channels.go
@@ -49,6 +49,7 @@ func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]any {
 		"ReplayChannel":         js.FuncOf(cm.ReplayChannel),
 		"EnableDirectMessages":  js.FuncOf(cm.EnableDirectMessages),
 		"DisableDirectMessages": js.FuncOf(cm.DisableDirectMessages),
+		"AreDMsEnabled":         js.FuncOf(cm.AreDMsEnabled),
 
 		// Share URL
 		"GetShareURL": js.FuncOf(cm.GetShareURL),
@@ -873,6 +874,24 @@ func (cm *ChannelsManager) DisableDirectMessages(_ js.Value, args []js.Value) an
 	return nil
 }
 
+// AreDMsEnabled returns the status of direct messaging for a given channel.
+//
+// Parameters:
+//   - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array).
+//
+// Returns:
+//   - enabled (bool) - status of dms for passed in channel ID, true if enabled
+//   - Throws a TypeError if unmarshalling the channel ID
+func (cm *ChannelsManager) AreDMsEnabled(_ js.Value, args []js.Value) any {
+	marshalledChanId := utils.CopyBytesToGo(args[0])
+	enabled, err := cm.api.AreDMsEnabled(marshalledChanId)
+	if err != nil {
+		utils.Throw(utils.TypeError, err)
+		return false
+	}
+	return enabled
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Channel Share URL                                                          //
 ////////////////////////////////////////////////////////////////////////////////
-- 
GitLab