diff --git a/protocol/communities/community.go b/protocol/communities/community.go index 8cb084474..3f09556cf 100644 --- a/protocol/communities/community.go +++ b/protocol/communities/community.go @@ -297,11 +297,13 @@ func (o *Community) RemoveUserFromOrg(pk *ecdsa.PublicKey) (*protobuf.CommunityD return o.config.CommunityDescription, nil } +// TODO: this should accept a request from a user to join and perform any validation func (o *Community) AcceptRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error) { return nil, nil } +// TODO: this should decline a request from a user to join func (o *Community) DeclineRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error) { return nil, nil } @@ -437,10 +439,10 @@ func (o *Community) HandleRequestJoin(signer *ecdsa.PublicKey, request *protobuf } if len(request.ChatId) != 0 { - return o.handleRequestJoinWithChatID(signer, request) + return o.handleRequestJoinWithChatID(request) } - err := o.handleRequestJoinWithoutChatID(signer, request) + err := o.handleRequestJoinWithoutChatID(request) if err != nil { return err } @@ -453,9 +455,8 @@ func (o *Community) IsAdmin() bool { return o.config.PrivateKey != nil } -func (o *Community) handleRequestJoinWithChatID(signer *ecdsa.PublicKey, request *protobuf.CommunityRequestJoin) error { +func (o *Community) handleRequestJoinWithChatID(request *protobuf.CommunityRequestJoin) error { - var chat *protobuf.CommunityChat chat, ok := o.config.CommunityDescription.Chats[request.ChatId] if !ok { @@ -474,7 +475,7 @@ func (o *Community) handleRequestJoinWithChatID(signer *ecdsa.PublicKey, request return nil } -func (o *Community) handleRequestJoinWithoutChatID(signer *ecdsa.PublicKey, request *protobuf.CommunityRequestJoin) error { +func (o *Community) handleRequestJoinWithoutChatID(request *protobuf.CommunityRequestJoin) error { // If they want access to the org only, check that the org is ON_REQUEST if o.config.CommunityDescription.Permissions.Access != protobuf.CommunityPermissions_ON_REQUEST { diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 788de4c36..8dc195b3e 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -222,6 +222,7 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des return community, nil } +// TODO: Finish implementing this func (m *Manager) HandleCommunityInvitation(signer *ecdsa.PublicKey, invitation *protobuf.CommunityInvitation, payload []byte) (*Community, error) { m.logger.Debug("Handling wrapped community description message") diff --git a/protocol/communities/persistence.go b/protocol/communities/persistence.go index 8d8e83a69..91d6ee18e 100644 --- a/protocol/communities/persistence.go +++ b/protocol/communities/persistence.go @@ -28,14 +28,23 @@ func (p *Persistence) SaveCommunity(community *Community) error { return err } -func (p *Persistence) queryCommunities(query string) ([]*Community, error) { - var response []*Community +func (p *Persistence) queryCommunities(query string) (response []*Community, err error) { rows, err := p.db.Query(query) if err != nil { return nil, err } - defer rows.Close() + + defer func() { + if err != nil { + // Don't shadow original error + _ = rows.Close() + return + + } + err = rows.Close() + return + }() for rows.Next() { var publicKeyBytes, privateKeyBytes, descriptionBytes []byte diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index 17679a174..f6543b537 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -44,8 +44,8 @@ func (s *MessengerCommunitiesSuite) SetupTest() { s.shh = gethbridge.NewGethWakuWrapper(shh) s.Require().NoError(shh.Start(nil)) - s.bob = s.newMessenger(s.shh) - s.alice = s.newMessenger(s.shh) + s.bob = s.newMessenger() + s.alice = s.newMessenger() s.Require().NoError(s.bob.Start()) s.Require().NoError(s.alice.Start()) } @@ -84,7 +84,7 @@ func (s *MessengerCommunitiesSuite) newMessengerWithKey(shh types.Waku, privateK return s.newMessengerWithOptions(shh, privateKey, options) } -func (s *MessengerCommunitiesSuite) newMessenger(shh types.Waku) *Messenger { +func (s *MessengerCommunitiesSuite) newMessenger() *Messenger { privateKey, err := crypto.GenerateKey() s.Require().NoError(err) @@ -92,7 +92,7 @@ func (s *MessengerCommunitiesSuite) newMessenger(shh types.Waku) *Messenger { } func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() { - alice := s.newMessenger(s.shh) + alice := s.newMessenger() description := &protobuf.CommunityDescription{ Permissions: &protobuf.CommunityPermissions{ diff --git a/protocol/message_handler.go b/protocol/message_handler.go index d14d29670..405ea494c 100644 --- a/protocol/message_handler.go +++ b/protocol/message_handler.go @@ -401,7 +401,7 @@ func (m *MessageHandler) HandleCommunityInvitation(state *ReceivedMessageState, } // HandleWrappedCommunityDescriptionMessage handles a wrapped community description -func (m *MessageHandler) HandleWrappedCommunityDescriptionMessage(state *ReceivedMessageState, payload []byte) (*communities.Community, error) { +func (m *MessageHandler) HandleWrappedCommunityDescriptionMessage(payload []byte) (*communities.Community, error) { return m.communitiesManager.HandleWrappedCommunityDescriptionMessage(payload) } @@ -479,7 +479,7 @@ func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error { if receivedMessage.ContentType == protobuf.ChatMessage_COMMUNITY { m.logger.Debug("Handling community content type") - community, err := m.HandleWrappedCommunityDescriptionMessage(state, receivedMessage.GetCommunity()) + community, err := m.HandleWrappedCommunityDescriptionMessage(receivedMessage.GetCommunity()) if err != nil { return err }