fix: profile social links, fix older clock error

This commit is contained in:
Sale Djenic 2023-06-06 15:37:24 +02:00 committed by saledjenic
parent 1d4fa29f8e
commit 874a0656db
3 changed files with 12 additions and 4 deletions

View File

@ -13,7 +13,8 @@ const (
)
var (
ErrNilSocialLinkProvided = errors.New("social links, nil object provided")
ErrNilSocialLinkProvided = errors.New("social links, nil object provided")
ErrOlderSocialLinksProvided = errors.New("older social links provided")
)
type SocialLinksSettings struct {
@ -98,7 +99,7 @@ func (s *SocialLinksSettings) AddOrReplaceSocialLinksIfNewer(links identity.Soci
}
if dbClock > clock {
return nil
return ErrOlderSocialLinksProvided
}
dbLinks, err := s.getSocialLinks(tx)

View File

@ -81,7 +81,8 @@ func TestProfileSocialLinksSaveAndGet(t *testing.T) {
// delete add profile social links with old clock
profileSocialLinks2 := profileSocialLinks()
err = socialLinkSettings.AddOrReplaceSocialLinksIfNewer(profileSocialLinks2, oldClock)
require.NoError(t, err)
require.Error(t, err)
require.Equal(t, err, ErrOlderSocialLinksProvided)
// check social links
links, err = socialLinkSettings.GetSocialLinks()
@ -161,7 +162,8 @@ func TestProfileSocialLinksDelete(t *testing.T) {
oldClock := uint64(0)
// test delete with old clock
err = socialLinkSettings.AddOrReplaceSocialLinksIfNewer(profileSocialLinks, oldClock)
require.NoError(t, err)
require.Error(t, err)
require.Equal(t, err, ErrOlderSocialLinksProvided)
// check
links, err = socialLinkSettings.GetSocialLinks()

View File

@ -37,6 +37,7 @@ import (
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
sociallinkssettings "github.com/status-im/status-go/multiaccounts/settings_social_links"
"github.com/status-im/status-go/protocol/anonmetrics"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/communities"
@ -6348,10 +6349,14 @@ func (m *Messenger) handleSyncSocialLinks(message *protobuf.SyncSocialLinks, cal
err = m.settings.AddOrReplaceSocialLinksIfNewer(links, message.Clock)
if err != nil {
if err == sociallinkssettings.ErrOlderSocialLinksProvided {
return nil
}
return err
}
callback(links)
return nil
}