fix(communities)_: ensure community ID is populated with description

Ensure that communities created prior to the introduction of tokenized
ownership propagate community ID through the description.

fixes: status-im/status-desktop#16226
This commit is contained in:
Patryk Osmaczko 2024-10-03 19:14:26 +02:00 committed by osmaczko
parent 0f151a0fbf
commit 4cef3baf85
2 changed files with 30 additions and 0 deletions

View File

@ -1627,6 +1627,12 @@ func (o *Community) marshaledDescription() ([]byte, error) {
}
}
// Ensure that communities created prior to the introduction of tokenized ownership
// propagate community ID through the description.
if len(clone.ID) == 0 {
clone.ID = o.IDString()
}
return proto.Marshal(clone)
}

View File

@ -2145,3 +2145,27 @@ func (s *ManagerSuite) TestDetermineChannelsForHRKeysRequest() {
s.Require().Len(channels, 1)
s.Require().Equal("channel-id", channels[0])
}
// Covers solution for: https://github.com/status-im/status-desktop/issues/16226
func (s *ManagerSuite) TestCommunityIDIsHydratedWhenMarshaling() {
request := &requests.CreateCommunity{
Name: "status",
Description: "description",
Membership: protobuf.CommunityPermissions_AUTO_ACCEPT,
}
community, err := s.manager.CreateCommunity(request, true)
s.Require().NoError(err)
s.Require().NotNil(community)
// Simulate legacy community that wasn't aware of ID field in `CommunityDescription` protobuf
community.config.CommunityDescription.ID = ""
// The fix is applied when community is marshaled, effectively hydrating empty ID
err = s.manager.SaveCommunity(community)
s.Require().NoError(err)
community, err = s.manager.GetByID(community.ID())
s.Require().NoError(err)
s.Require().Equal(community.IDString(), community.config.CommunityDescription.ID)
}