Skip to content

Commit

Permalink
Fix: Empty community tags in always empty slice, not nil (#4420)
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev authored Dec 8, 2023
1 parent 6e666f7 commit 238a6e2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion protocol/communities/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (o *Community) TagsRaw() []string {
}

func (o *Community) TagsIndices() []uint32 {
var indices []uint32
indices := []uint32{}
for _, t := range o.config.CommunityDescription.Tags {
i := uint32(0)
for k := range requests.TagsEmojies {
Expand Down
18 changes: 16 additions & 2 deletions protocol/messenger_share_urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,20 @@ func parseCommunityURLWithData(data string, chatKey string) (*URLDataResponse, e
return nil, err
}

var tagIndices []uint32
if communityProto.TagIndices != nil {
tagIndices = communityProto.TagIndices
} else {
tagIndices = []uint32{}
}

return &URLDataResponse{
Community: &CommunityURLData{
DisplayName: communityProto.DisplayName,
Description: communityProto.Description,
MembersCount: communityProto.MembersCount,
Color: communityProto.Color,
TagIndices: communityProto.TagIndices,
TagIndices: tagIndices,
CommunityID: types.EncodeHex(communityID),
},
Shard: shard.FromProtobuff(urlDataProto.Shard),
Expand Down Expand Up @@ -351,13 +358,20 @@ func parseCommunityChannelURLWithData(data string, chatKey string) (*URLDataResp
return nil, err
}

var tagIndices []uint32
if channelProto.Community.TagIndices != nil {
tagIndices = channelProto.Community.TagIndices
} else {
tagIndices = []uint32{}
}

return &URLDataResponse{
Community: &CommunityURLData{
DisplayName: channelProto.Community.DisplayName,
Description: channelProto.Community.Description,
MembersCount: channelProto.Community.MembersCount,
Color: channelProto.Community.Color,
TagIndices: channelProto.Community.TagIndices,
TagIndices: tagIndices,
CommunityID: types.EncodeHex(communityID),
},
Channel: &CommunityChannelURLData{
Expand Down
42 changes: 36 additions & 6 deletions protocol/messenger_share_urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import (
)

const (
userURL = "https://status.app/u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
userURLWithData = "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
communityURL = "https://status.app/c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
communityURLWithData = "https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
channelURL = "https://status.app/cc/003cdcd5-e065-48f9-b166-b1a94ac75a11#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
channelURLWithData = "https://status.app/cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
userURL = "https://status.app/u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
userURLWithData = "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
communityURL = "https://status.app/c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
communityURLWithData = "https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
communityURLWithDataNoTags = "https://status.app/c/CxCACh8KBFBJR1MSDHdlIGxvdmUgcGlncxgBIgcjRDM0NEM1Aw==#zQ3shZp9gY1FXfYkcd3CMrFLHriHQfrXvpF9XbZMwJhTcZsq8"
communityURLWithDataWithTags = "https://status.app/c/CxKACiMKBFBJR1MSDHdlIGxvdmUgcGlncxgBIgcjRDM0NEM1KgIjHgM=#zQ3shZp9gY1FXfYkcd3CMrFLHriHQfrXvpF9XbZMwJhTcZsq8"
channelURL = "https://status.app/cc/003cdcd5-e065-48f9-b166-b1a94ac75a11#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
channelURLWithData = "https://status.app/cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
)

func TestMessengerShareUrlsSuite(t *testing.T) {
Expand Down Expand Up @@ -261,6 +263,34 @@ func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithData() {
s.Require().Equal([]uint32{1, 33, 51}, urlData.Community.TagIndices)
}

func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithDataNoTags() {
urlData, err := ParseSharedURL(communityURLWithDataNoTags)
s.Require().NoError(err)
s.Require().NotNil(urlData)

s.Require().NotNil(urlData.Community)
s.Require().Equal("0x02b84843377a24ff498b6c37bd63e2b285c1ee2ccbab82d7a4afa25fff8c5076df", urlData.Community.CommunityID)
s.Require().Equal("PIGS", urlData.Community.DisplayName)
s.Require().Equal("we love pigs", urlData.Community.Description)
s.Require().Equal(uint32(0x1), urlData.Community.MembersCount)
s.Require().Equal("#D344C5", urlData.Community.Color)
s.Require().Equal([]uint32{}, urlData.Community.TagIndices)
}

func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithDataWithTags() {
urlData, err := ParseSharedURL(communityURLWithDataWithTags)
s.Require().NoError(err)
s.Require().NotNil(urlData)

s.Require().NotNil(urlData.Community)
s.Require().Equal("0x02b84843377a24ff498b6c37bd63e2b285c1ee2ccbab82d7a4afa25fff8c5076df", urlData.Community.CommunityID)
s.Require().Equal("PIGS", urlData.Community.DisplayName)
s.Require().Equal("we love pigs", urlData.Community.Description)
s.Require().Equal(uint32(0x1), urlData.Community.MembersCount)
s.Require().Equal("#D344C5", urlData.Community.Color)
s.Require().Equal([]uint32{0x23, 0x1e}, urlData.Community.TagIndices)
}

func (s *MessengerShareUrlsSuite) TestShareAndParseCommunityURLWithData() {
community := s.createCommunity()

Expand Down

0 comments on commit 238a6e2

Please sign in to comment.