From 5b2ab5bdacb1a3e3e62fdb3b972410d24dff29de Mon Sep 17 00:00:00 2001 From: MishkaRogachev Date: Fri, 27 Oct 2023 13:16:17 +0400 Subject: [PATCH] fix: code review & lint fixes --- protocol/identity/profile_showcase.go | 2 +- protocol/identity_images.go | 4 +- protocol/messenger_profile_showcase.go | 20 ++++---- protocol/messenger_profile_showcase_test.go | 29 +++++------ protocol/migrations/migrations.go | 48 +++++++++---------- ...98839882_profile_showcase_contacts.up.sql} | 2 +- protocol/persistence_profile_showcase.go | 28 +++++------ protocol/persistence_profile_showcase_test.go | 15 +++--- protocol/protobuf/profile_showcase.pb.go | 8 ++-- protocol/protobuf/profile_showcase.proto | 4 +- 10 files changed, 83 insertions(+), 77 deletions(-) rename protocol/migrations/sqlite/{1698396318_profile_showcase_contacts.up.sql => 1698839882_profile_showcase_contacts.up.sql} (78%) diff --git a/protocol/identity/profile_showcase.go b/protocol/identity/profile_showcase.go index c34a563ffe6..e6fb9198614 100644 --- a/protocol/identity/profile_showcase.go +++ b/protocol/identity/profile_showcase.go @@ -3,7 +3,7 @@ package identity import "reflect" type VisibleProfileShowcaseEntry struct { - EntryId string `json:"entryId"` + EntryID string `json:"entryId"` Order int `json:"order"` } diff --git a/protocol/identity_images.go b/protocol/identity_images.go index bf2566880a8..bd97416f954 100644 --- a/protocol/identity_images.go +++ b/protocol/identity_images.go @@ -9,6 +9,8 @@ import ( "github.com/status-im/status-go/protocol/protobuf" ) +const CipherMessageAutentificationFailed = "cipher: message authentication failed" + func EncryptIdentityImagesWithContactPubKeys(iis map[string]*protobuf.IdentityImage, m *Messenger) (err error) { // Make AES key AESKey := make([]byte, 32) @@ -77,7 +79,7 @@ image: // Decrypt the main encryption AES key with AES encryption using the DH key dAESKey, err := common.Decrypt(empk, sharedKey) if err != nil { - if err.Error() == "cipher: message authentication failed" { + if err.Error() == CipherMessageAutentificationFailed { continue } return err diff --git a/protocol/messenger_profile_showcase.go b/protocol/messenger_profile_showcase.go index 7f81cb35764..6593d225b71 100644 --- a/protocol/messenger_profile_showcase.go +++ b/protocol/messenger_profile_showcase.go @@ -6,10 +6,11 @@ import ( "errors" "fmt" + "google.golang.org/protobuf/proto" + "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/identity" "github.com/status-im/status-go/protocol/protobuf" - "google.golang.org/protobuf/proto" ) type ProfileShowcasePreferences struct { @@ -23,13 +24,14 @@ func toProfileShowcaseUpdateEntries(entries []*ProfileShowcaseEntry, visibility result := []*protobuf.ProfileShowcaseEntry{} for _, entry := range entries { - if entry.ShowcaseVisibility == visibility { - update := &protobuf.ProfileShowcaseEntry{ - EntryId: entry.ID, - Order: uint32(entry.Order), - } - result = append(result, update) + if entry.ShowcaseVisibility != visibility { + continue + } + update := &protobuf.ProfileShowcaseEntry{ + EntryId: entry.ID, + Order: uint32(entry.Order), } + result = append(result, update) } return result } @@ -38,7 +40,7 @@ func fromProfileShowcaseUpdateEntries(messages []*protobuf.ProfileShowcaseEntry) entries := []*identity.VisibleProfileShowcaseEntry{} for _, entry := range messages { entries = append(entries, &identity.VisibleProfileShowcaseEntry{ - EntryId: entry.EntryId, + EntryID: entry.EntryId, Order: int(entry.Order), }) } @@ -186,7 +188,7 @@ func (m *Messenger) DecryptProfileShowcaseEntriesWithContactPubKeys(senderPubKey // Decrypt the main encryption AES key with AES encryption using the DH key dAESKey, err := common.Decrypt(eAESKey, sharedKey) if err != nil { - if err.Error() == "cipher: message authentication failed" { + if err.Error() == CipherMessageAutentificationFailed { continue } return nil, err diff --git a/protocol/messenger_profile_showcase_test.go b/protocol/messenger_profile_showcase_test.go index 41451618c43..1354c3de08d 100644 --- a/protocol/messenger_profile_showcase_test.go +++ b/protocol/messenger_profile_showcase_test.go @@ -5,6 +5,9 @@ import ( "crypto/ecdsa" "testing" + "github.com/stretchr/testify/suite" + "go.uber.org/zap" + gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" @@ -14,8 +17,6 @@ import ( "github.com/status-im/status-go/protocol/requests" "github.com/status-im/status-go/protocol/tt" "github.com/status-im/status-go/waku" - "github.com/stretchr/testify/suite" - "go.uber.org/zap" ) func TestMessengerProfileShowcaseSuite(t *testing.T) { // nolint: deadcode,unused @@ -77,7 +78,7 @@ func (s *TestMessengerProfileShowcase) mutualContact(theirMessenger *Messenger) _, err = WaitOnMessengerResponse( theirMessenger, func(r *MessengerResponse) bool { - return len(r.Contacts) > 0 && len(r.Messages()) > 0 && len(r.ActivityCenterNotifications()) > 0 + return len(r.Contacts) > 0 && len(r.Messages()) > 0 }, "no messages", ) @@ -149,7 +150,7 @@ func (s *TestMessengerProfileShowcase) verifiedContact(theirMessenger *Messenger s.Require().Equal(common.ContactVerificationStateTrusted, resp.Messages()[0].ContactVerificationState) } -func (s *TestMessengerProfileShowcase) prepareShocasePreferencs() ProfileShowcasePreferences { +func (s *TestMessengerProfileShowcase) prepareShowcasePreferences() ProfileShowcasePreferences { communityEntry1 := &ProfileShowcaseEntry{ ID: "0x01312357798976434", EntryType: ProfileShowcaseEntryTypeCommunity, @@ -203,7 +204,7 @@ func (s *TestMessengerProfileShowcase) prepareShocasePreferencs() ProfileShowcas } func (s *TestMessengerProfileShowcase) TestSetAndGetProfileShowcasePreferences() { - request := s.prepareShocasePreferencs() + request := s.prepareShowcasePreferences() err := s.m.SetProfileShowcasePreferences(request) s.Require().NoError(err) @@ -310,7 +311,7 @@ func (s *TestMessengerProfileShowcase) TestShareShowcasePreferences() { s.verifiedContact(verifiedContact) // Save preferences to dispatch changes - request := s.prepareShocasePreferencs() + request := s.prepareShowcasePreferences() err = s.m.SetProfileShowcasePreferences(request) s.Require().NoError(err) @@ -328,15 +329,15 @@ func (s *TestMessengerProfileShowcase) TestShareShowcasePreferences() { profileShowcase := resp.Contacts[0].ProfileShowcase s.Require().Len(profileShowcase.Communities, 2) // For everyone - s.Require().Equal(profileShowcase.Communities[0].EntryId, request.Communities[0].ID) + s.Require().Equal(profileShowcase.Communities[0].EntryID, request.Communities[0].ID) s.Require().Equal(profileShowcase.Communities[0].Order, request.Communities[0].Order) // For contacts - s.Require().Equal(profileShowcase.Communities[1].EntryId, request.Communities[1].ID) + s.Require().Equal(profileShowcase.Communities[1].EntryID, request.Communities[1].ID) s.Require().Equal(profileShowcase.Communities[1].Order, request.Communities[1].Order) s.Require().Len(profileShowcase.Accounts, 1) - s.Require().Equal(profileShowcase.Accounts[0].EntryId, request.Accounts[0].ID) + s.Require().Equal(profileShowcase.Accounts[0].EntryID, request.Accounts[0].ID) s.Require().Equal(profileShowcase.Accounts[0].Order, request.Accounts[0].Order) s.Require().Len(profileShowcase.Collectibles, 0) @@ -357,23 +358,23 @@ func (s *TestMessengerProfileShowcase) TestShareShowcasePreferences() { profileShowcase = resp.Contacts[0].ProfileShowcase s.Require().Len(profileShowcase.Communities, 3) // For everyone - s.Require().Equal(profileShowcase.Communities[0].EntryId, request.Communities[0].ID) + s.Require().Equal(profileShowcase.Communities[0].EntryID, request.Communities[0].ID) s.Require().Equal(profileShowcase.Communities[0].Order, request.Communities[0].Order) // For contacts - s.Require().Equal(profileShowcase.Communities[1].EntryId, request.Communities[1].ID) + s.Require().Equal(profileShowcase.Communities[1].EntryID, request.Communities[1].ID) s.Require().Equal(profileShowcase.Communities[1].Order, request.Communities[1].Order) // For id verified - s.Require().Equal(profileShowcase.Communities[2].EntryId, request.Communities[2].ID) + s.Require().Equal(profileShowcase.Communities[2].EntryID, request.Communities[2].ID) s.Require().Equal(profileShowcase.Communities[2].Order, request.Communities[2].Order) s.Require().Len(profileShowcase.Accounts, 1) - s.Require().Equal(profileShowcase.Accounts[0].EntryId, request.Accounts[0].ID) + s.Require().Equal(profileShowcase.Accounts[0].EntryID, request.Accounts[0].ID) s.Require().Equal(profileShowcase.Accounts[0].Order, request.Accounts[0].Order) s.Require().Len(profileShowcase.Collectibles, 1) - s.Require().Equal(profileShowcase.Collectibles[0].EntryId, request.Collectibles[0].ID) + s.Require().Equal(profileShowcase.Collectibles[0].EntryID, request.Collectibles[0].ID) s.Require().Equal(profileShowcase.Collectibles[0].Order, request.Collectibles[0].Order) s.Require().Len(profileShowcase.Assets, 0) diff --git a/protocol/migrations/migrations.go b/protocol/migrations/migrations.go index cb1d10dcc6a..1a242393ad5 100644 --- a/protocol/migrations/migrations.go +++ b/protocol/migrations/migrations.go @@ -107,9 +107,9 @@ // 1697699419_community_control_node_sync.up.sql (435B) // 1698137561_add_profile_showcase_tables.up.sql (440B) // 1698137562_fix_encryption_key_id.up.sql (758B) -// 1698396318_profile_showcase_contacts.up.sql (254B) // 1698414646_add_padding.up.sql (69B) // 1698746210_add_signature_to_revealed_addresses.up.sql (87B) +// 1698839882_profile_showcase_contacts.up.sql (240B) // README.md (554B) // doc.go (850B) @@ -2320,26 +2320,6 @@ func _1698137562_fix_encryption_key_idUpSql() (*asset, error) { return a, nil } -var __1698396318_profile_showcase_contactsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\xce\xb1\x0a\x83\x30\x10\xc6\xf1\x3d\x4f\xf1\x8d\x0a\x0e\xdd\x9d\xd2\x1a\x21\x34\x55\x89\x27\xe8\x24\xa2\x29\x15\x8a\x91\x18\x28\xbe\x7d\xc1\x4a\xbb\xb4\x1d\x8f\xdf\xfd\xb9\x4b\x74\x5e\x80\xf8\x51\x09\xcc\xce\x5e\xc7\xbb\x69\x97\x9b\x7d\xf4\xdd\x62\xda\xde\x4e\xbe\xeb\xfd\x12\x33\x76\xd2\x82\x93\xd8\x17\x65\x8a\x2c\x27\x88\x5a\x96\x54\xfe\xce\x10\x30\x00\xd8\xc7\x76\x1c\x40\xa2\xa6\x2d\xcd\x2a\xa5\xa2\x4d\xcd\xe4\xdd\xfa\xd7\xfc\x3a\x1b\xc8\xec\x3b\x5a\x37\x18\xb7\x69\x22\x52\x5e\x29\xc2\xe1\xc5\x85\x96\x17\xae\x1b\x9c\x45\x83\xe0\xf3\x42\xf4\x3e\x18\xb2\x30\x66\xcf\x00\x00\x00\xff\xff\x7e\xb6\x19\xdf\xfe\x00\x00\x00") - -func _1698396318_profile_showcase_contactsUpSqlBytes() ([]byte, error) { - return bindataRead( - __1698396318_profile_showcase_contactsUpSql, - "1698396318_profile_showcase_contacts.up.sql", - ) -} - -func _1698396318_profile_showcase_contactsUpSql() (*asset, error) { - bytes, err := _1698396318_profile_showcase_contactsUpSqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "1698396318_profile_showcase_contacts.up.sql", size: 254, mode: os.FileMode(0644), modTime: time.Unix(1698828038, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc7, 0x66, 0xbc, 0x9c, 0xce, 0x5, 0x7f, 0xd0, 0x89, 0x58, 0x8a, 0x21, 0xc9, 0x82, 0x8e, 0x4f, 0xa1, 0x3f, 0x8b, 0x2, 0x14, 0x75, 0xb5, 0x15, 0x13, 0xc9, 0xd4, 0x8, 0xf, 0xe6, 0xc0, 0x83}} - return a, nil -} - var __1698414646_add_paddingUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\xc8\x48\x2c\xce\x88\x2f\x4a\x2c\x49\xce\x48\x2d\x89\x4f\xcd\x4b\x2e\xaa\x2c\x28\x49\x4d\x89\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\x56\x70\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\x28\x48\x4c\x49\xc9\xcc\x4b\x57\x70\xf2\xf1\x77\xb2\xe6\x02\x04\x00\x00\xff\xff\xc9\x3b\x51\x83\x45\x00\x00\x00") func _1698414646_add_paddingUpSqlBytes() ([]byte, error) { @@ -2380,6 +2360,26 @@ func _1698746210_add_signature_to_revealed_addressesUpSql() (*asset, error) { return a, nil } +var __1698839882_profile_showcase_contactsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x28\xca\x4f\xcb\xcc\x49\x8d\x2f\xce\xc8\x2f\x4f\x4e\x2c\x4e\x8d\x4f\xce\xcf\x2b\x49\x4c\x2e\x29\xb6\xe6\xe2\x72\x0e\x72\x75\x0c\x71\x25\xa4\x50\x41\x83\x4b\x41\x41\x41\x01\xca\x8d\xcf\x4c\x51\x08\x71\x8d\x08\x51\xf0\xf3\x0f\x51\xf0\x0b\xf5\xf1\xd1\x01\xcb\xa6\xe6\x95\x14\x55\xe2\x95\x2b\xa9\x2c\x48\x55\xf0\xf4\xc3\x2e\x99\x5f\x94\x92\x5a\x04\x96\x75\x71\x75\x73\x0c\xf5\x09\x51\x30\x80\x48\x07\x04\x79\xfa\x3a\x06\x45\x2a\x78\xbb\x46\x2a\x68\x20\x9c\xa0\x03\xb7\x50\x93\x4b\xd3\x9a\x0b\x10\x00\x00\xff\xff\x05\x86\x7c\xa2\xf0\x00\x00\x00") + +func _1698839882_profile_showcase_contactsUpSqlBytes() ([]byte, error) { + return bindataRead( + __1698839882_profile_showcase_contactsUpSql, + "1698839882_profile_showcase_contacts.up.sql", + ) +} + +func _1698839882_profile_showcase_contactsUpSql() (*asset, error) { + bytes, err := _1698839882_profile_showcase_contactsUpSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "1698839882_profile_showcase_contacts.up.sql", size: 240, mode: os.FileMode(0644), modTime: time.Unix(1698828102, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd5, 0x7a, 0xb4, 0x76, 0xcf, 0x34, 0x63, 0x6a, 0xd9, 0x62, 0xc9, 0x5d, 0x3e, 0x52, 0xa8, 0x45, 0xe0, 0xac, 0xf6, 0xe, 0x67, 0x6a, 0x44, 0x58, 0x49, 0xb6, 0x66, 0x1d, 0xef, 0x58, 0x4c, 0xde}} + return a, nil +} + var _readmeMd = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x54\x91\xc1\xce\xd3\x30\x10\x84\xef\x7e\x8a\x91\x7a\x01\xa9\x2a\x8f\xc0\x0d\x71\x82\x03\x48\x1c\xc9\x36\x9e\x36\x96\x1c\x6f\xf0\xae\x93\xe6\xed\x91\xa3\xc2\xdf\xff\x66\xed\xd8\x33\xdf\x78\x4f\xa7\x13\xbe\xea\x06\x57\x6c\x35\x39\x31\xa7\x7b\x15\x4f\x5a\xec\x73\x08\xbf\x08\x2d\x79\x7f\x4a\x43\x5b\x86\x17\xfd\x8c\x21\xea\x56\x5e\x47\x90\x4a\x14\x75\x48\xde\x64\x37\x2c\x6a\x96\xae\x99\x48\x05\xf6\x27\x77\x13\xad\x08\xae\x8a\x51\xe7\x25\xf3\xf1\xa9\x9f\xf9\x58\x58\x2c\xad\xbc\xe0\x8b\x56\xf0\x21\x5d\xeb\x4c\x95\xb3\xae\x84\x60\xd4\xdc\xe6\x82\x5d\x1b\x36\x6d\x39\x62\x92\xf5\xb8\x11\xdb\x92\xd3\x28\xce\xe0\x13\xe1\x72\xcd\x3c\x63\xd4\x65\x87\xae\xac\xe8\xc3\x28\x2e\x67\x44\x66\x3a\x21\x25\xa2\x72\xac\x14\x67\xbc\x84\x9f\x53\x32\x8c\x52\x70\x25\x56\xd6\xfd\x8d\x05\x37\xad\x30\x9d\x9f\xa6\x86\x0f\xcd\x58\x7f\xcf\x34\x93\x3b\xed\x90\x9f\xa4\x1f\xcf\x30\x85\x4d\x07\x58\xaf\x7f\x25\xc4\x9d\xf3\x72\x64\x84\xd0\x7f\xf9\x9b\x3a\x2d\x84\xef\x85\x48\x66\x8d\xd8\x88\x9b\x8c\x8c\x98\x5b\xf6\x74\x14\x4e\x33\x0d\xc9\xe0\x93\x38\xda\x12\xc5\x69\xbd\xe4\xf0\x2e\x7a\x78\x07\x1c\xfe\x13\x9f\x91\x29\x31\x95\x7b\x7f\x62\x59\x37\xb4\xe5\x5e\x25\xfe\x33\xee\xd5\x53\x71\xd6\xda\x3a\xd8\xcb\xde\x2e\xf8\xa1\x90\x55\x53\x0c\xc7\xaa\x0d\xe9\x76\x14\x29\x1c\x7b\x68\xdd\x2f\xe1\x6f\x00\x00\x00\xff\xff\x3c\x0a\xc2\xfe\x2a\x02\x00\x00") func readmeMdBytes() ([]byte, error) { @@ -2725,12 +2725,12 @@ var _bindata = map[string]func() (*asset, error){ "1698137562_fix_encryption_key_id.up.sql": _1698137562_fix_encryption_key_idUpSql, - "1698396318_profile_showcase_contacts.up.sql": _1698396318_profile_showcase_contactsUpSql, - "1698414646_add_padding.up.sql": _1698414646_add_paddingUpSql, "1698746210_add_signature_to_revealed_addresses.up.sql": _1698746210_add_signature_to_revealed_addressesUpSql, + "1698839882_profile_showcase_contacts.up.sql": _1698839882_profile_showcase_contactsUpSql, + "README.md": readmeMd, "doc.go": docGo, @@ -2884,9 +2884,9 @@ var _bintree = &bintree{nil, map[string]*bintree{ "1697699419_community_control_node_sync.up.sql": &bintree{_1697699419_community_control_node_syncUpSql, map[string]*bintree{}}, "1698137561_add_profile_showcase_tables.up.sql": &bintree{_1698137561_add_profile_showcase_tablesUpSql, map[string]*bintree{}}, "1698137562_fix_encryption_key_id.up.sql": &bintree{_1698137562_fix_encryption_key_idUpSql, map[string]*bintree{}}, - "1698396318_profile_showcase_contacts.up.sql": &bintree{_1698396318_profile_showcase_contactsUpSql, map[string]*bintree{}}, "1698414646_add_padding.up.sql": &bintree{_1698414646_add_paddingUpSql, map[string]*bintree{}}, "1698746210_add_signature_to_revealed_addresses.up.sql": &bintree{_1698746210_add_signature_to_revealed_addressesUpSql, map[string]*bintree{}}, + "1698839882_profile_showcase_contacts.up.sql": &bintree{_1698839882_profile_showcase_contactsUpSql, map[string]*bintree{}}, "README.md": &bintree{readmeMd, map[string]*bintree{}}, "doc.go": &bintree{docGo, map[string]*bintree{}}, }} diff --git a/protocol/migrations/sqlite/1698396318_profile_showcase_contacts.up.sql b/protocol/migrations/sqlite/1698839882_profile_showcase_contacts.up.sql similarity index 78% rename from protocol/migrations/sqlite/1698396318_profile_showcase_contacts.up.sql rename to protocol/migrations/sqlite/1698839882_profile_showcase_contacts.up.sql index 4eaa061e53c..7565ea22592 100644 --- a/protocol/migrations/sqlite/1698396318_profile_showcase_contacts.up.sql +++ b/protocol/migrations/sqlite/1698839882_profile_showcase_contacts.up.sql @@ -1,6 +1,6 @@ DROP TABLE profile_showcase_contacts; -CREATE TABLE IF NOT EXISTS profile_showcase_contacts ( +CREATE TABLE profile_showcase_contacts ( contact_id TEXT NOT NULL, entry_id TEXT NOT NULL, entry_type INT NOT NULL, diff --git a/protocol/persistence_profile_showcase.go b/protocol/persistence_profile_showcase.go index b55eefc1724..809c490ee55 100644 --- a/protocol/persistence_profile_showcase.go +++ b/protocol/persistence_profile_showcase.go @@ -127,8 +127,8 @@ func (db sqlitePersistence) GetProfileShowcasePreferencesByType(entryType Profil return db.parseProfileShowcasePreferencesRows(rows) } -func (db sqlitePersistence) GetProfileShowcaseForContact(contactId string) (*identity.ProfileShowcase, error) { - rows, err := db.db.Query(selectProfileShowcaseByContactQuery, contactId) +func (db sqlitePersistence) GetProfileShowcaseForContact(contactID string) (*identity.ProfileShowcase, error) { + rows, err := db.db.Query(selectProfileShowcaseByContactQuery, contactID) if err != nil { return nil, err } @@ -141,7 +141,7 @@ func (db sqlitePersistence) GetProfileShowcaseForContact(contactId string) (*ide entry := &identity.VisibleProfileShowcaseEntry{} err := rows.Scan( - &entry.EntryId, + &entry.EntryID, &entry.Order, &entryType, ) @@ -164,8 +164,8 @@ func (db sqlitePersistence) GetProfileShowcaseForContact(contactId string) (*ide return showcase, nil } -func (db sqlitePersistence) ClearProfileShowcaseForContact(contactId string) error { - _, err := db.db.Exec(removeProfileShowcaseContactQuery, contactId) +func (db sqlitePersistence) ClearProfileShowcaseForContact(contactID string) error { + _, err := db.db.Exec(removeProfileShowcaseContactQuery, contactID) if err != nil { return err } @@ -173,11 +173,11 @@ func (db sqlitePersistence) ClearProfileShowcaseForContact(contactId string) err return nil } -func (db sqlitePersistence) saveProfileShowcaseContactEntries(tx *sql.Tx, contactId string, entryType ProfileShowcaseEntryType, entries []*identity.VisibleProfileShowcaseEntry) error { +func (db sqlitePersistence) saveProfileShowcaseContactEntries(tx *sql.Tx, contactID string, entryType ProfileShowcaseEntryType, entries []*identity.VisibleProfileShowcaseEntry) error { for _, entry := range entries { _, err := tx.Exec(insertOrUpdateProfileShowcaseContactQuery, - contactId, - entry.EntryId, + contactID, + entry.EntryID, entryType, entry.Order, ) @@ -189,7 +189,7 @@ func (db sqlitePersistence) saveProfileShowcaseContactEntries(tx *sql.Tx, contac return nil } -func (db sqlitePersistence) SaveProfileShowcaseForContact(contactId string, showcase *identity.ProfileShowcase) error { +func (db sqlitePersistence) SaveProfileShowcaseForContact(contactID string, showcase *identity.ProfileShowcase) error { tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{}) if err != nil { return err @@ -204,28 +204,28 @@ func (db sqlitePersistence) SaveProfileShowcaseForContact(contactId string, show }() // Remove old entries first - _, err = tx.Exec(removeProfileShowcaseContactQuery, contactId) + _, err = tx.Exec(removeProfileShowcaseContactQuery, contactID) if err != nil { return err } // Save all profile showcase entries - err = db.saveProfileShowcaseContactEntries(tx, contactId, ProfileShowcaseEntryTypeCommunity, showcase.Communities) + err = db.saveProfileShowcaseContactEntries(tx, contactID, ProfileShowcaseEntryTypeCommunity, showcase.Communities) if err != nil { return err } - err = db.saveProfileShowcaseContactEntries(tx, contactId, ProfileShowcaseEntryTypeAccount, showcase.Accounts) + err = db.saveProfileShowcaseContactEntries(tx, contactID, ProfileShowcaseEntryTypeAccount, showcase.Accounts) if err != nil { return err } - err = db.saveProfileShowcaseContactEntries(tx, contactId, ProfileShowcaseEntryTypeCollectible, showcase.Collectibles) + err = db.saveProfileShowcaseContactEntries(tx, contactID, ProfileShowcaseEntryTypeCollectible, showcase.Collectibles) if err != nil { return err } - err = db.saveProfileShowcaseContactEntries(tx, contactId, ProfileShowcaseEntryTypeAsset, showcase.Assets) + err = db.saveProfileShowcaseContactEntries(tx, contactID, ProfileShowcaseEntryTypeAsset, showcase.Assets) if err != nil { return err } diff --git a/protocol/persistence_profile_showcase_test.go b/protocol/persistence_profile_showcase_test.go index dadd21b7757..ff719451497 100644 --- a/protocol/persistence_profile_showcase_test.go +++ b/protocol/persistence_profile_showcase_test.go @@ -3,8 +3,9 @@ package protocol import ( "testing" - "github.com/status-im/status-go/protocol/identity" "github.com/stretchr/testify/suite" + + "github.com/status-im/status-go/protocol/identity" ) func TestProfileShowcasePersistenceSuite(t *testing.T) { @@ -91,17 +92,17 @@ func (s *TestProfileShowcasePersistence) TestProfileShowcaseContacts() { showcase1 := &identity.ProfileShowcase{ Communities: []*identity.VisibleProfileShowcaseEntry{ &identity.VisibleProfileShowcaseEntry{ - EntryId: "0x012312234234234", + EntryID: "0x012312234234234", Order: 6, }, &identity.VisibleProfileShowcaseEntry{ - EntryId: "0x04523233466753", + EntryID: "0x04523233466753", Order: 7, }, }, Assets: []*identity.VisibleProfileShowcaseEntry{ &identity.VisibleProfileShowcaseEntry{ - EntryId: "ETH", + EntryID: "ETH", Order: 1, }, }, @@ -112,17 +113,17 @@ func (s *TestProfileShowcasePersistence) TestProfileShowcaseContacts() { showcase2 := &identity.ProfileShowcase{ Communities: []*identity.VisibleProfileShowcaseEntry{ &identity.VisibleProfileShowcaseEntry{ - EntryId: "0x012312234234234", // same id to check query + EntryID: "0x012312234234234", // same id to check query Order: 3, }, &identity.VisibleProfileShowcaseEntry{ - EntryId: "0x096783478384593", + EntryID: "0x096783478384593", Order: 7, }, }, Collectibles: []*identity.VisibleProfileShowcaseEntry{ &identity.VisibleProfileShowcaseEntry{ - EntryId: "d378662f-3d71-44e0-81ee-ff7f1778c13a", + EntryID: "d378662f-3d71-44e0-81ee-ff7f1778c13a", Order: 1, }, }, diff --git a/protocol/protobuf/profile_showcase.pb.go b/protocol/protobuf/profile_showcase.pb.go index 2537e35c1c6..d663fc559bb 100644 --- a/protocol/protobuf/profile_showcase.pb.go +++ b/protocol/protobuf/profile_showcase.pb.go @@ -25,8 +25,8 @@ type ProfileShowcaseEntry struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - EntryId string `protobuf:"bytes,3,opt,name=entry_id,json=entryId,proto3" json:"entry_id,omitempty"` - Order uint32 `protobuf:"varint,5,opt,name=order,proto3" json:"order,omitempty"` + EntryId string `protobuf:"bytes,1,opt,name=entry_id,json=entryId,proto3" json:"entry_id,omitempty"` + Order uint32 `protobuf:"varint,2,opt,name=order,proto3" json:"order,omitempty"` } func (x *ProfileShowcaseEntry) Reset() { @@ -271,8 +271,8 @@ var file_profile_showcase_proto_rawDesc = []byte{ 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x47, 0x0a, 0x14, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x68, 0x6f, 0x77, 0x63, 0x61, 0x73, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, - 0x74, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e, - 0x74, 0x72, 0x79, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x05, + 0x74, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e, + 0x74, 0x72, 0x79, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x92, 0x02, 0x0a, 0x16, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x68, 0x6f, 0x77, 0x63, 0x61, 0x73, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x12, 0x40, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, diff --git a/protocol/protobuf/profile_showcase.proto b/protocol/protobuf/profile_showcase.proto index 14e7f45f846..747ce00746d 100644 --- a/protocol/protobuf/profile_showcase.proto +++ b/protocol/protobuf/profile_showcase.proto @@ -4,8 +4,8 @@ option go_package = "./;protobuf"; package protobuf; message ProfileShowcaseEntry { - string entry_id = 3; - uint32 order = 5; + string entry_id = 1; + uint32 order = 2; } message ProfileShowcaseEntries {