Fix: Empty community tags in always empty slice, not nil (#4420)
This commit is contained in:
parent
6e666f7c27
commit
238a6e2f2d
|
@ -428,7 +428,7 @@ func (o *Community) TagsRaw() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Community) TagsIndices() []uint32 {
|
func (o *Community) TagsIndices() []uint32 {
|
||||||
var indices []uint32
|
indices := []uint32{}
|
||||||
for _, t := range o.config.CommunityDescription.Tags {
|
for _, t := range o.config.CommunityDescription.Tags {
|
||||||
i := uint32(0)
|
i := uint32(0)
|
||||||
for k := range requests.TagsEmojies {
|
for k := range requests.TagsEmojies {
|
||||||
|
|
|
@ -189,13 +189,20 @@ func parseCommunityURLWithData(data string, chatKey string) (*URLDataResponse, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tagIndices []uint32
|
||||||
|
if communityProto.TagIndices != nil {
|
||||||
|
tagIndices = communityProto.TagIndices
|
||||||
|
} else {
|
||||||
|
tagIndices = []uint32{}
|
||||||
|
}
|
||||||
|
|
||||||
return &URLDataResponse{
|
return &URLDataResponse{
|
||||||
Community: &CommunityURLData{
|
Community: &CommunityURLData{
|
||||||
DisplayName: communityProto.DisplayName,
|
DisplayName: communityProto.DisplayName,
|
||||||
Description: communityProto.Description,
|
Description: communityProto.Description,
|
||||||
MembersCount: communityProto.MembersCount,
|
MembersCount: communityProto.MembersCount,
|
||||||
Color: communityProto.Color,
|
Color: communityProto.Color,
|
||||||
TagIndices: communityProto.TagIndices,
|
TagIndices: tagIndices,
|
||||||
CommunityID: types.EncodeHex(communityID),
|
CommunityID: types.EncodeHex(communityID),
|
||||||
},
|
},
|
||||||
Shard: shard.FromProtobuff(urlDataProto.Shard),
|
Shard: shard.FromProtobuff(urlDataProto.Shard),
|
||||||
|
@ -351,13 +358,20 @@ func parseCommunityChannelURLWithData(data string, chatKey string) (*URLDataResp
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tagIndices []uint32
|
||||||
|
if channelProto.Community.TagIndices != nil {
|
||||||
|
tagIndices = channelProto.Community.TagIndices
|
||||||
|
} else {
|
||||||
|
tagIndices = []uint32{}
|
||||||
|
}
|
||||||
|
|
||||||
return &URLDataResponse{
|
return &URLDataResponse{
|
||||||
Community: &CommunityURLData{
|
Community: &CommunityURLData{
|
||||||
DisplayName: channelProto.Community.DisplayName,
|
DisplayName: channelProto.Community.DisplayName,
|
||||||
Description: channelProto.Community.Description,
|
Description: channelProto.Community.Description,
|
||||||
MembersCount: channelProto.Community.MembersCount,
|
MembersCount: channelProto.Community.MembersCount,
|
||||||
Color: channelProto.Community.Color,
|
Color: channelProto.Community.Color,
|
||||||
TagIndices: channelProto.Community.TagIndices,
|
TagIndices: tagIndices,
|
||||||
CommunityID: types.EncodeHex(communityID),
|
CommunityID: types.EncodeHex(communityID),
|
||||||
},
|
},
|
||||||
Channel: &CommunityChannelURLData{
|
Channel: &CommunityChannelURLData{
|
||||||
|
|
|
@ -17,12 +17,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
userURL = "https://status.app/u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
|
userURL = "https://status.app/u#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
|
||||||
userURLWithData = "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
|
userURLWithData = "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj"
|
||||||
communityURL = "https://status.app/c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
communityURL = "https://status.app/c#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
||||||
communityURLWithData = "https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
communityURLWithData = "https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
||||||
channelURL = "https://status.app/cc/003cdcd5-e065-48f9-b166-b1a94ac75a11#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
communityURLWithDataNoTags = "https://status.app/c/CxCACh8KBFBJR1MSDHdlIGxvdmUgcGlncxgBIgcjRDM0NEM1Aw==#zQ3shZp9gY1FXfYkcd3CMrFLHriHQfrXvpF9XbZMwJhTcZsq8"
|
||||||
channelURLWithData = "https://status.app/cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
|
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) {
|
func TestMessengerShareUrlsSuite(t *testing.T) {
|
||||||
|
@ -261,6 +263,34 @@ func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithData() {
|
||||||
s.Require().Equal([]uint32{1, 33, 51}, urlData.Community.TagIndices)
|
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() {
|
func (s *MessengerShareUrlsSuite) TestShareAndParseCommunityURLWithData() {
|
||||||
community := s.createCommunity()
|
community := s.createCommunity()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue