Skip to content
Snippets Groups Projects
Commit 1c653f0c authored by Josh Brooks's avatar Josh Brooks
Browse files

Clean up MR and resolve comments

parent a0910756
Branches
Tags
2 merge requests!510Release,!320Make singleton track groups rather than groupChat manager
...@@ -88,13 +88,13 @@ type GroupChat struct { ...@@ -88,13 +88,13 @@ type GroupChat struct {
m *gc.Wrapper m *gc.Wrapper
} }
// LoadOrNewGroupChat creates a bindings-layer group chat manager. // NewGroupChat creates a bindings-layer group chat manager.
// //
// Parameters: // Parameters:
// - e2eID - e2e object ID in the tracker. // - e2eID - e2e object ID in the tracker.
// - requestFunc - a callback to handle group chat requests. // - requestFunc - a callback to handle group chat requests.
// - processor - the group chat message processor. // - processor - the group chat message processor.
func LoadOrNewGroupChat(e2eID int, func NewGroupChat(e2eID int,
requestFunc GroupRequest, processor GroupChatProcessor) (*GroupChat, error) { requestFunc GroupRequest, processor GroupChatProcessor) (*GroupChat, error) {
// Get user from singleton // Get user from singleton
...@@ -106,7 +106,7 @@ func LoadOrNewGroupChat(e2eID int, ...@@ -106,7 +106,7 @@ func LoadOrNewGroupChat(e2eID int,
// Construct a wrapper for the request callback // Construct a wrapper for the request callback
requestCb := func(g gs.Group) { requestCb := func(g gs.Group) {
newGroup := groupTrackerSingleton.make(g) newGroup := groupTrackerSingleton.make(g)
requestFunc.Callback(newGroup.id) requestFunc.Callback(newGroup)
} }
// Construct a group chat manager // Construct a group chat manager
...@@ -200,10 +200,12 @@ func (g *GroupChat) ResendRequest(groupId []byte) ([]byte, error) { ...@@ -200,10 +200,12 @@ func (g *GroupChat) ResendRequest(groupId []byte) ([]byte, error) {
} }
// JoinGroup allows a user to join a group when a request is received. // JoinGroup allows a user to join a group when a request is received.
// If an error is returned, handle it properly first; you may then retry later
// with the same trackedGroupId.
// //
// Parameters: // Parameters:
// - trackedGroupId - the ID to retrieve the Group object within the backend's // - trackedGroupId - the ID to retrieve the Group object within the backend's
// tracking system. // tracking system. This is received by GroupRequest.Callback.
func (g *GroupChat) JoinGroup(trackedGroupId int) error { func (g *GroupChat) JoinGroup(trackedGroupId int) error {
// Retrieve group from singleton // Retrieve group from singleton
grp, err := groupTrackerSingleton.get(trackedGroupId) grp, err := groupTrackerSingleton.get(trackedGroupId)
...@@ -277,21 +279,29 @@ func (g *GroupChat) GetGroups() ([]byte, error) { ...@@ -277,21 +279,29 @@ func (g *GroupChat) GetGroups() ([]byte, error) {
return json.Marshal(groupIds) return json.Marshal(groupIds)
} }
// GetGroup returns the Group with the tracked ID from the backend's Group tracker. // GetGroup returns the group with the group ID. If no group exists, then the
// error "failed to find group" is returned.
// //
// Parameters: // Parameters:
// - trackedGroupId - the ID to retrieve the Group object within the backend's // - groupId - The byte data representing a group ID (a byte marshalled id.ID).
// tracking system. // This can be pulled from a marshalled GroupReport.
// Returns: // Returns:
// - Group - the bindings-layer representation of a group. // - Group - The bindings-layer representation of a group.
func (g *GroupChat) GetGroup(trackedGroupId int) (*Group, error) { func (g *GroupChat) GetGroup(groupId []byte) (*Group, error) {
// Retrieve group from singleton // Unmarshal group ID
group, err := groupTrackerSingleton.get(trackedGroupId) groupID, err := id.Unmarshal(groupId)
if err != nil { if err != nil {
return nil, err return nil, errors.Errorf("Failed to unmarshal group ID: %+v", err)
}
// Retrieve group from manager
grp, exists := g.m.GetGroup(groupID)
if !exists {
return nil, errors.New("failed to find group")
} }
return group, nil // Add to tracker and return Group object
return groupTrackerSingleton.make(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.
...@@ -315,11 +325,16 @@ func (g *Group) GetName() []byte { ...@@ -315,11 +325,16 @@ 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. This represents the id.ID object
func (g *Group) GetID() []byte { func (g *Group) GetID() []byte {
return g.g.ID.Bytes() return g.g.ID.Bytes()
} }
// GetTrackedID returns the tracked ID of the Group object. This is used by the backend tracker.
func (g *Group) GetTrackedID() int {
return g.id
}
// GetInitMessage returns initial message sent with the group request. // GetInitMessage returns initial message sent with the group request.
func (g *Group) GetInitMessage() []byte { func (g *Group) GetInitMessage() []byte {
return g.g.InitMessage return g.g.InitMessage
...@@ -360,10 +375,9 @@ func (g *Group) Serialize() []byte { ...@@ -360,10 +375,9 @@ func (g *Group) Serialize() []byte {
// GroupRequest is a bindings-layer interface that handles a group reception. // GroupRequest is a bindings-layer interface that handles a group reception.
// //
// Parameters: // Parameters:
// - trackedGroupId - the ID to retrieve the Group object within the backend's // - trackedGroupId - a bindings layer Group object.
// tracking system.
type GroupRequest interface { type GroupRequest interface {
Callback(trackedGroupId int) Callback(g *Group)
} }
// GroupChatProcessor manages the handling of received group chat messages. // GroupChatProcessor manages the handling of received group chat messages.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment