fix: publish group member info (#4184)
This commit is contained in:
parent
445135eb94
commit
27b770c41b
|
@ -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"
|
||||
)
|
||||
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue