address feedback
This commit is contained in:
parent
3be6d86326
commit
b4905fdbd4
|
@ -297,11 +297,13 @@ func (o *Community) RemoveUserFromOrg(pk *ecdsa.PublicKey) (*protobuf.CommunityD
|
||||||
return o.config.CommunityDescription, nil
|
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) {
|
func (o *Community) AcceptRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error) {
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this should decline a request from a user to join
|
||||||
func (o *Community) DeclineRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error) {
|
func (o *Community) DeclineRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -437,10 +439,10 @@ func (o *Community) HandleRequestJoin(signer *ecdsa.PublicKey, request *protobuf
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(request.ChatId) != 0 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -453,9 +455,8 @@ func (o *Community) IsAdmin() bool {
|
||||||
return o.config.PrivateKey != nil
|
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]
|
chat, ok := o.config.CommunityDescription.Chats[request.ChatId]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -474,7 +475,7 @@ func (o *Community) handleRequestJoinWithChatID(signer *ecdsa.PublicKey, request
|
||||||
return nil
|
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 they want access to the org only, check that the org is ON_REQUEST
|
||||||
if o.config.CommunityDescription.Permissions.Access != protobuf.CommunityPermissions_ON_REQUEST {
|
if o.config.CommunityDescription.Permissions.Access != protobuf.CommunityPermissions_ON_REQUEST {
|
||||||
|
|
|
@ -222,6 +222,7 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des
|
||||||
return community, nil
|
return community, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Finish implementing this
|
||||||
func (m *Manager) HandleCommunityInvitation(signer *ecdsa.PublicKey, invitation *protobuf.CommunityInvitation, payload []byte) (*Community, error) {
|
func (m *Manager) HandleCommunityInvitation(signer *ecdsa.PublicKey, invitation *protobuf.CommunityInvitation, payload []byte) (*Community, error) {
|
||||||
m.logger.Debug("Handling wrapped community description message")
|
m.logger.Debug("Handling wrapped community description message")
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,23 @@ func (p *Persistence) SaveCommunity(community *Community) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Persistence) queryCommunities(query string) ([]*Community, error) {
|
func (p *Persistence) queryCommunities(query string) (response []*Community, err error) {
|
||||||
var response []*Community
|
|
||||||
|
|
||||||
rows, err := p.db.Query(query)
|
rows, err := p.db.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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() {
|
for rows.Next() {
|
||||||
var publicKeyBytes, privateKeyBytes, descriptionBytes []byte
|
var publicKeyBytes, privateKeyBytes, descriptionBytes []byte
|
||||||
|
|
|
@ -44,8 +44,8 @@ func (s *MessengerCommunitiesSuite) SetupTest() {
|
||||||
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
||||||
s.Require().NoError(shh.Start(nil))
|
s.Require().NoError(shh.Start(nil))
|
||||||
|
|
||||||
s.bob = s.newMessenger(s.shh)
|
s.bob = s.newMessenger()
|
||||||
s.alice = s.newMessenger(s.shh)
|
s.alice = s.newMessenger()
|
||||||
s.Require().NoError(s.bob.Start())
|
s.Require().NoError(s.bob.Start())
|
||||||
s.Require().NoError(s.alice.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)
|
return s.newMessengerWithOptions(shh, privateKey, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerCommunitiesSuite) newMessenger(shh types.Waku) *Messenger {
|
func (s *MessengerCommunitiesSuite) newMessenger() *Messenger {
|
||||||
privateKey, err := crypto.GenerateKey()
|
privateKey, err := crypto.GenerateKey()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ func (s *MessengerCommunitiesSuite) newMessenger(shh types.Waku) *Messenger {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() {
|
func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() {
|
||||||
alice := s.newMessenger(s.shh)
|
alice := s.newMessenger()
|
||||||
|
|
||||||
description := &protobuf.CommunityDescription{
|
description := &protobuf.CommunityDescription{
|
||||||
Permissions: &protobuf.CommunityPermissions{
|
Permissions: &protobuf.CommunityPermissions{
|
||||||
|
|
|
@ -401,7 +401,7 @@ func (m *MessageHandler) HandleCommunityInvitation(state *ReceivedMessageState,
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleWrappedCommunityDescriptionMessage handles a wrapped community description
|
// 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)
|
return m.communitiesManager.HandleWrappedCommunityDescriptionMessage(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error {
|
||||||
if receivedMessage.ContentType == protobuf.ChatMessage_COMMUNITY {
|
if receivedMessage.ContentType == protobuf.ChatMessage_COMMUNITY {
|
||||||
m.logger.Debug("Handling community content type")
|
m.logger.Debug("Handling community content type")
|
||||||
|
|
||||||
community, err := m.HandleWrappedCommunityDescriptionMessage(state, receivedMessage.GetCommunity())
|
community, err := m.HandleWrappedCommunityDescriptionMessage(receivedMessage.GetCommunity())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue