From 2be7e53a8972725a07d30d065cd44269dfda1331 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 13 May 2022 09:44:26 -0400 Subject: [PATCH] fix: community was not updated when creating general chat --- protocol/communities_messenger_test.go | 22 +++++++++++++++++----- protocol/messenger_communities.go | 3 +++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index 84ab2ff65..329147b4e 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -451,6 +451,8 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() { s.Require().NoError(err) s.Require().NotNil(response) s.Require().Len(response.Communities(), 1) + s.Require().Len(response.Communities()[0].Chats(), 1) + s.Require().Len(response.Chats(), 1) community := response.Communities()[0] @@ -469,6 +471,7 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() { s.Require().NoError(err) s.Require().NotNil(response) s.Require().Len(response.Communities(), 1) + s.Require().Len(response.Communities()[0].Chats(), 2) s.Require().Len(response.Chats(), 1) response, err = s.bob.InviteUsersToCommunity( @@ -509,6 +512,7 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() { s.Require().NoError(err) s.Require().NotNil(response) s.Require().Len(response.Communities(), 1) + s.Require().Len(response.Communities()[0].Chats(), 2) s.Require().True(response.Communities()[0].Joined()) s.Require().Len(response.Chats(), 2) @@ -535,11 +539,19 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() { s.Require().NoError(err) s.Require().Len(response.Messages(), 1) - // If 1 is set we get an error "should have 1 item(s), but has 2", - // after setting it to 2, we get "should have 2 item(s), but has 1" - // because of that commenting out the next line - //s.Require().Len(response.Chats(), 2) - s.Require().Equal(chatID, response.Chats()[1].ID) + + // check if response contains the chat we're interested in + // we use this instead of checking just the length of the chat because + // a CommunityDescription message might be received in the meantime due to syncing + // hence response.Chats() might contain the general chat, and the new chat; + // or only the new chat if the CommunityDescription message has not arrived + found := false + for _, chat := range response.Chats() { + if chat.ID == chatID { + found = true + } + } + s.Require().True(found) } func (s *MessengerCommunitiesSuite) TestImportCommunity() { diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 05a1b5888..7c2767ca1 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -673,6 +673,9 @@ func (m *Messenger) CreateCommunity(request *requests.CreateCommunity) (*Messeng return nil, err } + // updating community so it contains the general chat + community = chatResponse.Communities()[0] + response := &MessengerResponse{} response.AddCommunity(community) response.AddCommunitySettings(&communitySettings)