Skip to content

Commit

Permalink
fix: code review & lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev committed Oct 31, 2023
1 parent 049f06b commit 3f232ee
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 53 deletions.
2 changes: 1 addition & 1 deletion protocol/identity/profile_showcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package identity
import "reflect"

type VisibleProfileShowcaseEntry struct {
EntryId string `json:"entryId"`
EntryID string `json:"entryId"`
Order int `json:"order"`
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/identity_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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() == "cipher: message authentication failed" { // nolint: goconst
continue
}
return err
Expand Down
20 changes: 11 additions & 9 deletions protocol/messenger_profile_showcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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),
})
}
Expand Down Expand Up @@ -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() == "cipher: message authentication failed" { // nolint: goconst
continue
}
return nil, err
Expand Down
29 changes: 15 additions & 14 deletions protocol/messenger_profile_showcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
28 changes: 14 additions & 14 deletions protocol/persistence_profile_showcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -141,7 +141,7 @@ func (db sqlitePersistence) GetProfileShowcaseForContact(contactId string) (*ide
entry := &identity.VisibleProfileShowcaseEntry{}

err := rows.Scan(
&entry.EntryId,
&entry.EntryID,
&entry.Order,
&entryType,
)
Expand All @@ -164,20 +164,20 @@ 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
}

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,
)
Expand All @@ -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
Expand All @@ -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
}
Expand Down
15 changes: 8 additions & 7 deletions protocol/persistence_profile_showcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
},
},
Expand All @@ -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,
},
},
Expand Down
8 changes: 4 additions & 4 deletions protocol/protobuf/profile_showcase.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protocol/protobuf/profile_showcase.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3f232ee

Please sign in to comment.