From 7e1f88314417c1e9976484f5d320e7f8f84cd090 Mon Sep 17 00:00:00 2001
From: Tigran Avakyan <tigran.avakyan@icloud.com>
Date: Thu, 28 Mar 2019 18:18:30 -0700
Subject: [PATCH] Created fake viper JSON variable that is used to get group
 JSON for registration.

---
 cmd/root.go     | 17 ++++++++++++-----
 user/session.go |  2 +-
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/cmd/root.go b/cmd/root.go
index 12cee76b5..0aed08b70 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -17,6 +17,7 @@ import (
 	"gitlab.com/elixxir/client/bindings"
 	"gitlab.com/elixxir/client/bots"
 	"gitlab.com/elixxir/client/cmixproto"
+	"gitlab.com/elixxir/client/crypto"
 	"gitlab.com/elixxir/client/globals"
 	"gitlab.com/elixxir/client/parse"
 	"gitlab.com/elixxir/primitives/switchboard"
@@ -123,10 +124,9 @@ func sessionInitialization() {
 		// 64 bits
 		grp := cyclic.Group{}
 		grpBuff := []byte(viper.GetString("group"))
-
-		err := grp.GobDecode(grpBuff)
+		err := grp.UnmarshalJSON(grpBuff)
 		if err != nil {
-			fmt.Printf("Could Not Decode group: %s\n", err.Error())
+			fmt.Printf("Could Not Decode group from JSON: %s\n", err.Error())
 			return
 		}
 
@@ -275,7 +275,6 @@ var rootCmd = &cobra.Command{
 		// Only send a message if we have a message to send (except dummy messages)
 		recipientId := new(id.User).SetUints(&[4]uint64{0, 0, 0, destinationUserId})
 		senderId := new(id.User).SetUints(&[4]uint64{0, 0, 0, userId})
-		grp := user.TheSession.GetGroup()
 		if message != "" {
 			// Get the recipient's nick
 			recipientNick := ""
@@ -286,6 +285,7 @@ var rootCmd = &cobra.Command{
 
 			// Handle sending to UDB
 			if *recipientId == *bots.UdbID {
+				grp := user.TheSession.GetGroup()
 				fmt.Println(parseUdbMessage(message, grp))
 			} else {
 				// Handle sending to any other destination
@@ -421,7 +421,14 @@ func SetCertPath(path string) {
 }
 
 // initConfig reads in config file and ENV variables if set.
-func initConfig() {}
+func initConfig() {
+	// Temporarily need to get group as JSON data into viper
+	json, err := crypto.InitCrypto().MarshalJSON()
+	if err != nil {
+		// panic
+	}
+	viper.Set("group", string(json))
+}
 
 // initLog initializes logging thresholds and the log path.
 func initLog() {
diff --git a/user/session.go b/user/session.go
index 3dd99364c..6c325d2fa 100644
--- a/user/session.go
+++ b/user/session.go
@@ -199,7 +199,7 @@ func (s *SessionObj) GetCurrentUser() (currentUser *User) {
 			Nick: s.CurrentUser.Nick,
 		}
 	}
-	return
+	return currentUser
 }
 
 func (s *SessionObj) GetGWAddress() string {
-- 
GitLab