Fix: Empty community tags in always empty slice, not nil (#4420)

This commit is contained in:
Mikhail Rogachev 2023-12-08 15:13:36 +07:00 committed by GitHub
parent 6e666f7c27
commit 238a6e2f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 9 deletions

View File

@ -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 {

View File

@ -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),
@ -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{

View File

@ -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) {
@ -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()