Skip to content

Commit

Permalink
fix: publish group member info (#4184)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri authored Oct 25, 2023
1 parent 445135e commit 27b770c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.171.5
0.171.6
46 changes: 46 additions & 0 deletions protocol/messenger_group_chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"

userimage "github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
)
Expand Down Expand Up @@ -454,3 +455,48 @@ func (s *MessengerGroupChatSuite) TestGroupChatMembersRemovalOutOfOrder() {
defer s.NoError(admin.Shutdown())
defer s.NoError(memberA.Shutdown())
}

func (s *MessengerGroupChatSuite) TestGroupChatMembersInfoSync() {
admin, memberA, memberB := s.startNewMessenger(), s.startNewMessenger(), s.startNewMessenger()
s.Require().NoError(admin.settings.SaveSettingField(settings.DisplayName, "admin"))
s.Require().NoError(memberA.settings.SaveSettingField(settings.DisplayName, "memberA"))
s.Require().NoError(memberB.settings.SaveSettingField(settings.DisplayName, "memberB"))

members := []string{common.PubkeyToHex(&memberA.identity.PublicKey), common.PubkeyToHex(&memberB.identity.PublicKey)}

s.makeMutualContacts(admin, memberA)
s.makeMutualContacts(admin, memberB)

s.createGroupChat(admin, "test_group_chat", members)
s.verifyGroupChatCreated(memberA, true)
s.verifyGroupChatCreated(memberB, true)

response, err := WaitOnMessengerResponse(
memberA,
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
"chat invitation not received",
)
s.Require().NoError(err)
s.Require().Len(response.Chats(), 1)
s.Require().True(response.Chats()[0].Active)
s.Require().Len(response.Chats()[0].Members, 3)

_, err = WaitOnMessengerResponse(
memberA,
func(r *MessengerResponse) bool {
// we republish as we don't have store nodes in tests
err := memberB.publishContactCode()
if err != nil {
return false
}
contact, ok := memberA.allContacts.Load(common.PubkeyToHex(&memberB.identity.PublicKey))
return ok && contact.DisplayName == "memberB"
},
"DisplayName is not the same",
)
s.Require().NoError(err)

s.NoError(admin.Shutdown())
s.NoError(memberA.Shutdown())
s.NoError(memberB.Shutdown())
}
13 changes: 13 additions & 0 deletions protocol/messenger_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ func (m *Messenger) HandleMembershipUpdate(messageState *ReceivedMessageState, c
return errors.Wrap(err, "failed to get group creator")
}

publicKeys, err := group.MemberPublicKeys()
if err != nil {
return errors.Wrap(err, "failed to get group members")
}
filters, err := m.transport.JoinGroup(publicKeys)
if err != nil {
return errors.Wrap(err, "failed to join group")
}
ok, err := m.scheduleSyncFilters(filters)
if err != nil {
return errors.Wrap(err, "failed to schedule sync filter")
}
m.logger.Debug("result of schedule sync filter", zap.Bool("ok", ok))
} else {
existingGroup, err := newProtocolGroupFromChat(chat)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions protocol/v1/membership_update_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,26 @@ func (g Group) Members() []string {
return g.members.List()
}

func (g Group) MemberPublicKeys() ([]*ecdsa.PublicKey, error) {
var publicKeys = make([]*ecdsa.PublicKey, 0, len(g.Members()))
for _, memberPublicKey := range g.Members() {
publicKey, err := hexToPubkey(memberPublicKey)
if err != nil {
return nil, err
}
publicKeys = append(publicKeys, publicKey)
}
return publicKeys, nil
}

func hexToPubkey(pk string) (*ecdsa.PublicKey, error) {
bytes, err := types.DecodeHex(pk)
if err != nil {
return nil, err
}
return crypto.UnmarshalPubkey(bytes)
}

func (g Group) Admins() []string {
return g.admins.List()
}
Expand Down

0 comments on commit 27b770c

Please sign in to comment.