Skip to content
Snippets Groups Projects
Commit 059b2eae authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

Merge branch 'ben/group' into 'release'

made bindigns group all pointerie

See merge request !50
parents 7e25bac1 2ef10120
No related branches found
No related tags found
2 merge requests!53Release,!50made bindigns group all pointerie
...@@ -23,66 +23,66 @@ type GroupChat struct { ...@@ -23,66 +23,66 @@ type GroupChat struct {
// GroupRequestFunc contains a function callback that is called when a group // GroupRequestFunc contains a function callback that is called when a group
// request is received. // request is received.
type GroupRequestFunc interface { type GroupRequestFunc interface {
GroupRequestCallback(g Group) GroupRequestCallback(g *Group)
} }
// GroupReceiveFunc contains a function callback that is called when a group // GroupReceiveFunc contains a function callback that is called when a group
// message is received. // message is received.
type GroupReceiveFunc interface { type GroupReceiveFunc interface {
GroupReceiveCallback(msg GroupMessageReceive) GroupReceiveCallback(msg *GroupMessageReceive)
} }
// NewGroupManager creates a new group chat manager. // NewGroupManager creates a new group chat manager.
func NewGroupManager(client *Client, requestFunc GroupRequestFunc, func NewGroupManager(client *Client, requestFunc GroupRequestFunc,
receiveFunc GroupReceiveFunc) (GroupChat, error) { receiveFunc GroupReceiveFunc) (*GroupChat, error) {
requestCallback := func(g gs.Group) { requestCallback := func(g gs.Group) {
requestFunc.GroupRequestCallback(Group{g}) requestFunc.GroupRequestCallback(&Group{g})
} }
receiveCallback := func(msg gc.MessageReceive) { receiveCallback := func(msg gc.MessageReceive) {
receiveFunc.GroupReceiveCallback(GroupMessageReceive{msg}) receiveFunc.GroupReceiveCallback(&GroupMessageReceive{msg})
} }
// Create a new group chat manager // Create a new group chat manager
m, err := gc.NewManager(&client.api, requestCallback, receiveCallback) m, err := gc.NewManager(&client.api, requestCallback, receiveCallback)
if err != nil { if err != nil {
return GroupChat{}, err return nil, err
} }
// Start group request and message retrieval workers // Start group request and message retrieval workers
err = client.api.AddService(m.StartProcesses) err = client.api.AddService(m.StartProcesses)
if err != nil { if err != nil {
return GroupChat{}, err return nil, err
} }
return GroupChat{m}, nil return &GroupChat{m}, nil
} }
// MakeGroup creates a new group and sends a group request to all members in the // MakeGroup creates a new group and sends a group request to all members in the
// group. The ID of the new group, the rounds the requests were sent on, and the // group. The ID of the new group, the rounds the requests were sent on, and the
// status of the send are contained in NewGroupReport. // status of the send are contained in NewGroupReport.
func (g GroupChat) MakeGroup(membership IdList, name, message []byte) (NewGroupReport, error) { func (g *GroupChat) MakeGroup(membership *IdList, name, message []byte) (*NewGroupReport, error) {
grp, rounds, status, err := g.m.MakeGroup(membership.list, name, message) grp, rounds, status, err := g.m.MakeGroup(membership.list, name, message)
return NewGroupReport{Group{grp}, rounds, status}, err return &NewGroupReport{&Group{grp}, rounds, status}, err
} }
// ResendRequest resends a group request to all members in the group. The rounds // ResendRequest resends a group request to all members in the group. The rounds
// they were sent on and the status of the send are contained in NewGroupReport. // they were sent on and the status of the send are contained in NewGroupReport.
func (g GroupChat) ResendRequest(groupIdBytes []byte) (NewGroupReport, error) { func (g *GroupChat) ResendRequest(groupIdBytes []byte) (*NewGroupReport, error) {
groupID, err := id.Unmarshal(groupIdBytes) groupID, err := id.Unmarshal(groupIdBytes)
if err != nil { if err != nil {
return NewGroupReport{}, return nil,
errors.Errorf("Failed to unmarshal group ID: %+v", err) errors.Errorf("Failed to unmarshal group ID: %+v", err)
} }
rounds, status, err := g.m.ResendRequest(groupID) rounds, status, err := g.m.ResendRequest(groupID)
return NewGroupReport{Group{}, rounds, status}, nil return &NewGroupReport{&Group{}, rounds, status}, nil
} }
// JoinGroup allows a user to join a group when they receive a request. The // JoinGroup allows a user to join a group when they receive a request. The
// caller must pass in the serialized bytes of a Group. // caller must pass in the serialized bytes of a Group.
func (g GroupChat) JoinGroup(serializedGroupData []byte) error { func (g *GroupChat) JoinGroup(serializedGroupData []byte) error {
grp, err := gs.DeserializeGroup(serializedGroupData) grp, err := gs.DeserializeGroup(serializedGroupData)
if err != nil { if err != nil {
return err return err
...@@ -91,7 +91,7 @@ func (g GroupChat) JoinGroup(serializedGroupData []byte) error { ...@@ -91,7 +91,7 @@ func (g GroupChat) JoinGroup(serializedGroupData []byte) error {
} }
// LeaveGroup deletes a group so a user no longer has access. // LeaveGroup deletes a group so a user no longer has access.
func (g GroupChat) LeaveGroup(groupIdBytes []byte) error { func (g *GroupChat) LeaveGroup(groupIdBytes []byte) error {
groupID, err := id.Unmarshal(groupIdBytes) groupID, err := id.Unmarshal(groupIdBytes)
if err != nil { if err != nil {
return errors.Errorf("Failed to unmarshal group ID: %+v", err) return errors.Errorf("Failed to unmarshal group ID: %+v", err)
...@@ -102,7 +102,7 @@ func (g GroupChat) LeaveGroup(groupIdBytes []byte) error { ...@@ -102,7 +102,7 @@ func (g GroupChat) LeaveGroup(groupIdBytes []byte) error {
// Send sends the message to the specified group. Returns the round the messages // Send sends the message to the specified group. Returns the round the messages
// were sent on. // were sent on.
func (g GroupChat) Send(groupIdBytes, message []byte) (int64, error) { func (g *GroupChat) Send(groupIdBytes, message []byte) (int64, error) {
groupID, err := id.Unmarshal(groupIdBytes) groupID, err := id.Unmarshal(groupIdBytes)
if err != nil { if err != nil {
return 0, errors.Errorf("Failed to unmarshal group ID: %+v", err) return 0, errors.Errorf("Failed to unmarshal group ID: %+v", err)
...@@ -114,28 +114,28 @@ func (g GroupChat) Send(groupIdBytes, message []byte) (int64, error) { ...@@ -114,28 +114,28 @@ func (g GroupChat) Send(groupIdBytes, message []byte) (int64, error) {
// GetGroups returns an IdList containing a list of group IDs that the user is a // GetGroups returns an IdList containing a list of group IDs that the user is a
// part of. // part of.
func (g GroupChat) GetGroups() IdList { func (g *GroupChat) GetGroups() *IdList {
return IdList{g.m.GetGroups()} return &IdList{g.m.GetGroups()}
} }
// GetGroup returns the group with the group ID. If no group exists, then the // GetGroup returns the group with the group ID. If no group exists, then the
// error "failed to find group" is returned. // error "failed to find group" is returned.
func (g GroupChat) GetGroup(groupIdBytes []byte) (Group, error) { func (g *GroupChat) GetGroup(groupIdBytes []byte) (*Group, error) {
groupID, err := id.Unmarshal(groupIdBytes) groupID, err := id.Unmarshal(groupIdBytes)
if err != nil { if err != nil {
return Group{}, errors.Errorf("Failed to unmarshal group ID: %+v", err) return nil, errors.Errorf("Failed to unmarshal group ID: %+v", err)
} }
grp, exists := g.m.GetGroup(groupID) grp, exists := g.m.GetGroup(groupID)
if !exists { if !exists {
return Group{}, errors.New("failed to find group") return nil, errors.New("failed to find group")
} }
return Group{grp}, nil return &Group{grp}, nil
} }
// NumGroups returns the number of groups the user is a part of. // NumGroups returns the number of groups the user is a part of.
func (g GroupChat) NumGroups() int { func (g *GroupChat) NumGroups() int {
return g.m.NumGroups() return g.m.NumGroups()
} }
...@@ -143,20 +143,20 @@ func (g GroupChat) NumGroups() int { ...@@ -143,20 +143,20 @@ func (g GroupChat) NumGroups() int {
// the group, a list of rounds that the group requests were sent on, and the // the group, a list of rounds that the group requests were sent on, and the
// status of the send. // status of the send.
type NewGroupReport struct { type NewGroupReport struct {
group Group group *Group
rounds []id.Round rounds []id.Round
status gc.RequestStatus status gc.RequestStatus
} }
// GetGroup returns the Group. // GetGroup returns the Group.
func (ngr NewGroupReport) GetGroup() Group { func (ngr *NewGroupReport) GetGroup() *Group {
return ngr.group return ngr.group
} }
// GetRoundList returns the RoundList containing a list of rounds requests were // GetRoundList returns the RoundList containing a list of rounds requests were
// sent on. // sent on.
func (ngr NewGroupReport) GetRoundList() RoundList { func (ngr *NewGroupReport) GetRoundList() *RoundList {
return RoundList{ngr.rounds} return &RoundList{ngr.rounds}
} }
// GetStatus returns the status of the requests sent when creating a new group. // GetStatus returns the status of the requests sent when creating a new group.
...@@ -164,7 +164,7 @@ func (ngr NewGroupReport) GetRoundList() RoundList { ...@@ -164,7 +164,7 @@ func (ngr NewGroupReport) GetRoundList() RoundList {
// 1 all requests failed to send // 1 all requests failed to send
// 2 some request failed and some succeeded // 2 some request failed and some succeeded
// 3, all requests sent successfully // 3, all requests sent successfully
func (ngr NewGroupReport) GetStatus() int { func (ngr *NewGroupReport) GetStatus() int {
return int(ngr.status) return int(ngr.status)
} }
...@@ -179,24 +179,24 @@ type Group struct { ...@@ -179,24 +179,24 @@ type Group struct {
} }
// GetName returns the name set by the user for the group. // GetName returns the name set by the user for the group.
func (g Group) GetName() []byte { func (g *Group) GetName() []byte {
return g.g.Name return g.g.Name
} }
// GetID return the 33-byte unique group ID. // GetID return the 33-byte unique group ID.
func (g Group) GetID() []byte { func (g *Group) GetID() []byte {
return g.g.ID.Bytes() return g.g.ID.Bytes()
} }
// GetMembership returns a list of contacts, one for each member in the group. // GetMembership returns a list of contacts, one for each member in the group.
// The list is in order; the first contact is the leader/creator of the group. // The list is in order; the first contact is the leader/creator of the group.
// All subsequent members are ordered by their ID. // All subsequent members are ordered by their ID.
func (g Group) GetMembership() GroupMembership { func (g *Group) GetMembership() *GroupMembership {
return GroupMembership{g.g.Members} return &GroupMembership{g.g.Members}
} }
// Serialize serializes the Group. // Serialize serializes the Group.
func (g Group) Serialize() []byte { func (g *Group) Serialize() []byte {
return g.g.Serialize() return g.g.Serialize()
} }
...@@ -211,18 +211,18 @@ type GroupMembership struct { ...@@ -211,18 +211,18 @@ type GroupMembership struct {
} }
// Len returns the number of members in the group membership. // Len returns the number of members in the group membership.
func (gm GroupMembership) Len() int { func (gm *GroupMembership) Len() int {
return gm.Len() return len(gm.m)
} }
// Get returns the member at the index. The member at index 0 is always the // Get returns the member at the index. The member at index 0 is always the
// group leader. An error is returned if the index is out of range. // group leader. An error is returned if the index is out of range.
func (gm GroupMembership) Get(i int) (GroupMember, error) { func (gm *GroupMembership) Get(i int) (*GroupMember, error) {
if i < 0 || i > gm.Len() { if i < 0 || i > gm.Len() {
return GroupMember{}, errors.Errorf("ID list index must be between %d "+ return nil, errors.Errorf("ID list index must be between %d "+
"and the last element %d.", 0, gm.Len()) "and the last element %d.", 0, gm.Len())
} }
return GroupMember{gm.m[i]}, nil return &GroupMember{gm.m[i]}, nil
} }
//// ////
...@@ -240,7 +240,7 @@ func (gm GroupMember) GetID() []byte { ...@@ -240,7 +240,7 @@ func (gm GroupMember) GetID() []byte {
// GetDhKey returns the byte representation of the public Diffie–Hellman key of // GetDhKey returns the byte representation of the public Diffie–Hellman key of
// the member. // the member.
func (gm GroupMember) GetDhKey() []byte { func (gm *GroupMember) GetDhKey() []byte {
return gm.DhKey.Bytes() return gm.DhKey.Bytes()
} }
...@@ -255,47 +255,47 @@ type GroupMessageReceive struct { ...@@ -255,47 +255,47 @@ type GroupMessageReceive struct {
} }
// GetGroupID returns the 33-byte group ID. // GetGroupID returns the 33-byte group ID.
func (gmr GroupMessageReceive) GetGroupID() []byte { func (gmr *GroupMessageReceive) GetGroupID() []byte {
return gmr.GroupID.Bytes() return gmr.GroupID.Bytes()
} }
// GetMessageID returns the message ID. // GetMessageID returns the message ID.
func (gmr GroupMessageReceive) GetMessageID() []byte { func (gmr *GroupMessageReceive) GetMessageID() []byte {
return gmr.ID.Bytes() return gmr.ID.Bytes()
} }
// GetPayload returns the message payload. // GetPayload returns the message payload.
func (gmr GroupMessageReceive) GetPayload() []byte { func (gmr *GroupMessageReceive) GetPayload() []byte {
return gmr.Payload return gmr.Payload
} }
// GetSenderID returns the 33-byte user ID of the sender. // GetSenderID returns the 33-byte user ID of the sender.
func (gmr GroupMessageReceive) GetSenderID() []byte { func (gmr *GroupMessageReceive) GetSenderID() []byte {
return gmr.SenderID.Bytes() return gmr.SenderID.Bytes()
} }
// GetRecipientID returns the 33-byte user ID of the recipient. // GetRecipientID returns the 33-byte user ID of the recipient.
func (gmr GroupMessageReceive) GetRecipientID() []byte { func (gmr *GroupMessageReceive) GetRecipientID() []byte {
return gmr.RecipientID.Bytes() return gmr.RecipientID.Bytes()
} }
// GetEphemeralID returns the ephemeral ID of the recipient. // GetEphemeralID returns the ephemeral ID of the recipient.
func (gmr GroupMessageReceive) GetEphemeralID() int64 { func (gmr *GroupMessageReceive) GetEphemeralID() int64 {
return gmr.EphemeralID.Int64() return gmr.EphemeralID.Int64()
} }
// GetTimestampNano returns the message timestamp in nanoseconds. // GetTimestampNano returns the message timestamp in nanoseconds.
func (gmr GroupMessageReceive) GetTimestampNano() int64 { func (gmr *GroupMessageReceive) GetTimestampNano() int64 {
return gmr.Timestamp.UnixNano() return gmr.Timestamp.UnixNano()
} }
// GetRoundID returns the ID of the round the message was sent on. // GetRoundID returns the ID of the round the message was sent on.
func (gmr GroupMessageReceive) GetRoundID() int64 { func (gmr *GroupMessageReceive) GetRoundID() int64 {
return int64(gmr.RoundID) return int64(gmr.RoundID)
} }
// GetRoundTimestampNano returns the timestamp, in nanoseconds, of the round the // GetRoundTimestampNano returns the timestamp, in nanoseconds, of the round the
// message was sent on. // message was sent on.
func (gmr GroupMessageReceive) GetRoundTimestampNano() int64 { func (gmr *GroupMessageReceive) GetRoundTimestampNano() int64 {
return gmr.RoundTimestamp.UnixNano() return gmr.RoundTimestamp.UnixNano()
} }
...@@ -123,17 +123,17 @@ type IdList struct { ...@@ -123,17 +123,17 @@ type IdList struct {
} }
// MakeIdList creates a new empty IdList. // MakeIdList creates a new empty IdList.
func MakeIdList() IdList { func MakeIdList() *IdList {
return IdList{[]*id.ID{}} return &IdList{[]*id.ID{}}
} }
// Len returns the number of IDs in the list. // Len returns the number of IDs in the list.
func (idl IdList) Len() int { func (idl *IdList) Len() int {
return len(idl.list) return len(idl.list)
} }
// Add appends the ID bytes to the end of the list. // Add appends the ID bytes to the end of the list.
func (idl IdList) Add(idBytes []byte) error { func (idl *IdList) Add(idBytes []byte) error {
newID, err := id.Unmarshal(idBytes) newID, err := id.Unmarshal(idBytes)
if err != nil { if err != nil {
return err return err
...@@ -145,7 +145,7 @@ func (idl IdList) Add(idBytes []byte) error { ...@@ -145,7 +145,7 @@ func (idl IdList) Add(idBytes []byte) error {
// Get returns the ID at the index. An error is returned if the index is out of // Get returns the ID at the index. An error is returned if the index is out of
// range. // range.
func (idl IdList) Get(i int) ([]byte, error) { func (idl *IdList) Get(i int) ([]byte, error) {
if i < 0 || i > len(idl.list) { if i < 0 || i > len(idl.list) {
return nil, errors.Errorf("ID list index must be between %d and the "+ return nil, errors.Errorf("ID list index must be between %d and the "+
"last element %d.", 0, len(idl.list)) "last element %d.", 0, len(idl.list))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment