2022-08-02 12:56:26 +00:00
|
|
|
package identity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
)
|
|
|
|
|
|
|
|
// static links which need to be decorated by the UI clients
|
|
|
|
const (
|
|
|
|
TwitterID = "__twitter"
|
|
|
|
PersonalSiteID = "__personal_site"
|
|
|
|
GithubID = "__github"
|
|
|
|
YoutubeID = "__youtube"
|
|
|
|
DiscordID = "__discord"
|
|
|
|
TelegramID = "__telegram"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SocialLink struct {
|
2023-06-05 11:10:26 +00:00
|
|
|
Text string `json:"text"`
|
|
|
|
URL string `json:"url"`
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|
|
|
|
|
2023-06-05 11:10:26 +00:00
|
|
|
type SocialLinks []*SocialLink
|
2022-08-02 12:56:26 +00:00
|
|
|
|
2023-06-05 11:10:26 +00:00
|
|
|
type SocialLinksInfo struct {
|
|
|
|
Links []*SocialLink `json:"links"`
|
|
|
|
Removed bool `json:"removed"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSocialLinks(links []*protobuf.SocialLink) SocialLinks {
|
2022-08-02 12:56:26 +00:00
|
|
|
res := SocialLinks{}
|
|
|
|
for _, link := range links {
|
2023-06-05 11:10:26 +00:00
|
|
|
res = append(res, &SocialLink{Text: link.Text, URL: link.Url})
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SocialLink) ToProtobuf() *protobuf.SocialLink {
|
|
|
|
return &protobuf.SocialLink{
|
|
|
|
Text: s.Text,
|
|
|
|
Url: s.URL,
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|
2023-06-05 11:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SocialLink) Equal(link *SocialLink) bool {
|
|
|
|
return s.Text == link.Text && s.URL == link.URL
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 14:11:28 +00:00
|
|
|
func (s *SocialLinks) ToProtobuf() []*protobuf.SocialLink {
|
2022-08-02 12:56:26 +00:00
|
|
|
res := []*protobuf.SocialLink{}
|
|
|
|
for _, link := range *s {
|
2023-06-05 11:10:26 +00:00
|
|
|
res = append(res, link.ToProtobuf())
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SocialLinks) ToSyncProtobuf(clock uint64) *protobuf.SyncSocialLinks {
|
|
|
|
res := &protobuf.SyncSocialLinks{
|
|
|
|
Clock: clock,
|
|
|
|
}
|
|
|
|
for _, link := range *s {
|
|
|
|
res.SocialLinks = append(res.SocialLinks, link.ToProtobuf())
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2023-06-05 11:10:26 +00:00
|
|
|
// Equal means the same links at the same order
|
|
|
|
func (s *SocialLinks) Equal(links SocialLinks) bool {
|
|
|
|
if len(*s) != len(links) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i := range *s {
|
|
|
|
if !(*s)[i].Equal(links[i]) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SocialLinks) Contains(link *SocialLink) bool {
|
|
|
|
if len(*s) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, l := range *s {
|
|
|
|
if l.Equal(link) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SocialLinks) Serialize() ([]byte, error) {
|
2023-06-05 11:10:26 +00:00
|
|
|
return json.Marshal(*s)
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|