Skip to content
Snippets Groups Projects
Commit d7f5c828 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'XX-4015/FixGroupChatMakeGroup' into 'release'

XX-4015 / Fix Group Chat MakeGroup

See merge request !326
parents c54ce718 f54ff3c5
No related branches found
No related tags found
2 merge requests!510Release,!326XX-4015 / Fix Group Chat MakeGroup
......@@ -10,6 +10,7 @@ package bindings
import (
"encoding/json"
"gitlab.com/elixxir/client/backup"
"gitlab.com/xx_network/primitives/id"
)
////////////////////////////////////////////////////////////////////////////////
......@@ -26,10 +27,16 @@ type Backup struct {
// NewCmixFromBackup.
//
// Example BackupReport:
//{"RestoredContacts":["0AeVYBe87SV45A2UI4AtIe6H4AIyZSLPBPrT6eTBLycD"],"Params":""}
// {
// "RestoredContacts": [
// "U4x/lrFkvxuXu59LtHLon1sUhPJSCcnZND6SugndnVID",
// "15tNdkKbYXoMn58NO6VbDMDWFEyIhTWEGsvgcJsHWAgD"
// ],
// "Params": ""
// }
type BackupReport struct {
// The list of restored E2E partner IDs
RestoredContacts IdList
RestoredContacts []*id.ID
// The backup parameters found within the backup file
Params string
......@@ -70,7 +77,7 @@ func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string,
// Construct report
report := BackupReport{
RestoredContacts: makeIdList(backupIdList),
RestoredContacts: backupIdList,
Params: backupParams,
}
......
......@@ -41,14 +41,13 @@ func (e *E2e) GetReceptionID() []byte {
return e.api.GetE2E().GetReceptionID().Marshal()
}
// GetAllPartnerIDs returns a marshalled list of all partner IDs that the user
// has an E2E relationship with.
// GetAllPartnerIDs returns a list of all partner IDs that the user has an E2E
// relationship with.
//
// Returns:
// - []byte - the marshalled bytes of the IdList object.
// - []byte - the marshalled bytes of []*id.ID.
func (e *E2e) GetAllPartnerIDs() ([]byte, error) {
partnerIds := e.api.GetE2E().GetAllPartnerIDs()
return json.Marshal(makeIdList(partnerIds))
return json.Marshal(e.api.GetE2E().GetAllPartnerIDs())
}
// PayloadSize returns the max payload size for a partitionable E2E message.
......
......@@ -125,21 +125,24 @@ func NewGroupChat(e2eID int,
// group.
//
// Parameters:
// - membership - IDs of members the user wants in the group.
// - membershipBytes - the JSON marshalled list of []*id.ID; it contains the
// IDs of members the user wants to add to the group.
// - message - the initial message sent to all members in the group. This is an
// optional parameter and may be nil.
// - tag - the name of the group decided by the creator. This is an optional parameter
// and may be nil. If nil the group will be assigned the default name.
// - tag - the name of the group decided by the creator. This is an optional
// parameter and may be nil. If nil the group will be assigned the default
// name.
//
// Returns:
// - []byte - the JSON marshalled bytes of the GroupReport object, which can be
// passed into WaitForRoundResult to see if the group request message send
// succeeded.
func (g *GroupChat) MakeGroup(membership IdList, message, name []byte) (
func (g *GroupChat) MakeGroup(membershipBytes []byte, message, name []byte) (
[]byte, error) {
// Construct membership list into a list of []*id.Id
members, err := deserializeIdList(membership)
// Unmarshal membership list into a list of []*id.Id
var members []*id.ID
err := json.Unmarshal(membershipBytes, &members)
if err != nil {
return nil, err
}
......@@ -275,14 +278,12 @@ func (g *GroupChat) Send(groupId,
return json.Marshal(sendReport)
}
// GetGroups returns an IdList containing a list of group IDs that the user is a member of.
// GetGroups returns a list of group IDs that the user is a member of.
//
// Returns:
// - []byte - a JSON marshalled IdList representing all group ID's.
// - []byte - a JSON marshalled []*id.ID representing all group ID's.
func (g *GroupChat) GetGroups() ([]byte, error) {
groupIds := makeIdList(g.m.GetGroups())
return json.Marshal(groupIds)
return json.Marshal(g.m.GetGroups())
}
// GetGroup returns the group with the group ID. If no group exists, then the
......
......@@ -9,8 +9,6 @@ package bindings
import (
"encoding/json"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/fact"
......@@ -189,38 +187,3 @@ func GetFactsFromContact(marshaled []byte) ([]byte, error) {
}
return factsListMarshaled, nil
}
////////////////////////////////////////////////////////////////////////////////
// IdList Functions //
////////////////////////////////////////////////////////////////////////////////
// IdList is a wrapper for a list of marshalled id.ID objects.
type IdList struct {
Ids [][]byte
}
// makeIdList is a helper function which creates an IdList object
// given a list of id.ID's. It serializes each element of the
// given list of id.ID's, places that into a list of []byte's (ie [][]byte)
// and places that in the IdList.
func makeIdList(ids []*id.ID) IdList {
convertedIds := make([][]byte, len(ids))
for i, partnerId := range ids {
convertedIds[i] = partnerId.Marshal()
}
return IdList{Ids: convertedIds}
}
// deserializeIdList is a helper function which creates a list of id.ID's
// given an IdList. It deserializes each element of the IdList using id.Unmarshal.
func deserializeIdList(ids IdList) ([]*id.ID, error) {
convertedIds := make([]*id.ID, len(ids.Ids))
for i, serializedId := range ids.Ids {
deserializedId, err := id.Unmarshal(serializedId)
if err != nil {
return nil, err
}
convertedIds[i] = deserializedId
}
return convertedIds, nil
}
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