fix(communities): make sure to join the community if we are a member (#4118)

Fixes https://github.com/status-im/status-desktop/issues/12368
This commit is contained in:
Jonathan Rainville 2023-10-10 14:03:55 -04:00 committed by GitHub
parent 39676c8c01
commit 736779d94b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 109 additions and 1 deletions

View File

@ -1417,6 +1417,11 @@ func (m *Manager) handleCommunityDescriptionMessageCommon(community *Community,
}
community.config.EventsData = nil
// Set Joined if we are part of the member list
if !community.Joined() && community.hasMember(&m.identity.PublicKey) {
changes.ShouldMemberJoin = true
}
err = m.persistence.SaveCommunity(community)
if err != nil {
return nil, err

View File

@ -2018,7 +2018,7 @@ func (s *MessengerCommunitiesSuite) TestShareCommunity() {
inviteMessage := "invite to community testing message"
// Create an community chat
// Create an community
response, err := s.bob.CreateCommunity(description, true)
s.Require().NoError(err)
s.Require().NotNil(response)
@ -2063,6 +2063,109 @@ func (s *MessengerCommunitiesSuite) TestShareCommunity() {
s.Require().Equal(inviteMessage, message.Text)
}
func (s *MessengerCommunitiesSuite) TestShareCommunityWithPreviousMember() {
description := &requests.CreateCommunity{
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
Name: "status",
Color: "#ffffff",
Description: "status community description",
}
inviteMessage := "invite to community testing message"
// Create an community chat
response, err := s.bob.CreateCommunity(description, true)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Communities(), 1)
community := response.Communities()[0]
orgChat := &protobuf.CommunityChat{
Permissions: &protobuf.CommunityPermissions{
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
},
Identity: &protobuf.ChatIdentity{
DisplayName: "status-core",
Emoji: "😎",
Description: "status-core community chat",
},
}
response, err = s.bob.CreateCommunityChat(community.ID(), orgChat)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Communities(), 1)
s.Require().Len(response.Chats(), 1)
community = response.Communities()[0]
communityChat := response.Chats()[0]
// Add Alice to the community before sharing it
_, err = community.AddMember(&s.alice.identity.PublicKey, []protobuf.CommunityMember_Roles{})
s.Require().NoError(err)
err = s.bob.communitiesManager.SaveCommunity(community)
s.Require().NoError(err)
response, err = s.bob.ShareCommunity(
&requests.ShareCommunity{
CommunityID: community.ID(),
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
InviteMessage: inviteMessage,
},
)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Messages(), 1)
// Add bob to contacts so it does not go on activity center
bobPk := common.PubkeyToHex(&s.bob.identity.PublicKey)
request := &requests.AddContact{ID: bobPk}
_, err = s.alice.AddContact(context.Background(), request)
s.Require().NoError(err)
// Pull message and make sure org is received
err = tt.RetryWithBackOff(func() error {
response, err = s.alice.RetrieveAll()
if err != nil {
return err
}
if len(response.messages) == 0 {
return errors.New("community link not received")
}
return nil
})
s.Require().NoError(err)
s.Require().Len(response.Messages(), 1)
message := response.Messages()[0]
s.Require().Equal(community.IDString(), message.CommunityID)
s.Require().Equal(inviteMessage, message.Text)
// Alice should have the Joined status for the community
communityInResponse := response.Communities()[0]
s.Require().Equal(community.ID(), communityInResponse.ID())
s.Require().True(communityInResponse.Joined())
// Alice is able to receive messages in the community
inputMessage := buildTestMessage(*communityChat)
sendResponse, err := s.bob.SendChatMessage(context.Background(), inputMessage)
messageID := sendResponse.Messages()[0].ID
s.NoError(err)
s.Require().Len(sendResponse.Messages(), 1)
response, err = WaitOnMessengerResponse(
s.alice,
func(r *MessengerResponse) bool { return len(r.messages) > 0 },
"no messages",
)
s.Require().NoError(err)
s.Require().Len(response.Chats(), 1)
s.Require().Len(response.Messages(), 1)
s.Require().Equal(messageID, response.Messages()[0].ID)
}
func (s *MessengerCommunitiesSuite) TestBanUser() {
community, _ := s.createCommunity()