From a77a40fdf43888c328919f378f6e287fa9976c61 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Tue, 24 Nov 2020 23:16:19 +0000 Subject: [PATCH] Resolved linting issues --- images/encode.go | 11 +++++----- multiaccounts/database.go | 18 +++++++-------- multiaccounts/database_test.go | 22 +++++++++---------- multiaccounts/migrations/bindata.go | 8 +++---- ...181_drop_photo_path_from_accounts.down.sql | 6 +---- protocol/images/type.go | 2 +- protocol/message_handler.go | 4 ++-- protocol/messenger.go | 4 ++-- protocol/messenger_config.go | 2 +- protocol/persistence.go | 8 +++---- protocol/persistence_test.go | 8 +++---- 11 files changed, 44 insertions(+), 49 deletions(-) diff --git a/images/encode.go b/images/encode.go index 637e0637c..b145c2bd6 100644 --- a/images/encode.go +++ b/images/encode.go @@ -41,13 +41,12 @@ func EncodeToBestSize(bb *bytes.Buffer, img image.Image, size ResizeDimension) e if q == MinJpegQuality { if DimensionSizeLimit[size].Max > bb.Len() { return nil - } else { - return fmt.Errorf( - "image size after processing exceeds max, expect < '%d', received < '%d'", - DimensionSizeLimit[size].Max, - bb.Len(), - ) } + return fmt.Errorf( + "image size after processing exceeds max, expect < '%d', received < '%d'", + DimensionSizeLimit[size].Max, + bb.Len(), + ) } bb.Reset() diff --git a/multiaccounts/database.go b/multiaccounts/database.go index 565528913..2b57f5472 100644 --- a/multiaccounts/database.go +++ b/multiaccounts/database.go @@ -81,8 +81,8 @@ func (db *Database) DeleteAccount(keyUID string) error { // Account images -func (db *Database) GetIdentityImages(keyUid string) ([]*images.IdentityImage, error) { - rows, err := db.db.Query(`SELECT key_uid, name, image_payload, width, height, file_size, resize_target FROM identity_images WHERE key_uid = ?`, keyUid) +func (db *Database) GetIdentityImages(keyUID string) ([]*images.IdentityImage, error) { + rows, err := db.db.Query(`SELECT key_uid, name, image_payload, width, height, file_size, resize_target FROM identity_images WHERE key_uid = ?`, keyUID) if err != nil { return nil, err } @@ -102,8 +102,8 @@ func (db *Database) GetIdentityImages(keyUid string) ([]*images.IdentityImage, e return iis, nil } -func (db *Database) GetIdentityImage(keyUid, it string) (*images.IdentityImage, error) { - rows, err := db.db.Query("SELECT key_uid, name, image_payload, width, height, file_size, resize_target FROM identity_images WHERE key_uid = ? AND name = ?", keyUid, it) +func (db *Database) GetIdentityImage(keyUID, it string) (*images.IdentityImage, error) { + rows, err := db.db.Query("SELECT key_uid, name, image_payload, width, height, file_size, resize_target FROM identity_images WHERE key_uid = ? AND name = ?", keyUID, it) if err != nil { return nil, err } @@ -111,7 +111,7 @@ func (db *Database) GetIdentityImage(keyUid, it string) (*images.IdentityImage, var ii images.IdentityImage for rows.Next() { - err = rows.Scan(&ii.KeyUID ,&ii.Name, &ii.Payload, &ii.Width, &ii.Height, &ii.FileSize, &ii.ResizeTarget) + err = rows.Scan(&ii.KeyUID, &ii.Name, &ii.Payload, &ii.Width, &ii.Height, &ii.FileSize, &ii.ResizeTarget) if err != nil { return nil, err } @@ -120,7 +120,7 @@ func (db *Database) GetIdentityImage(keyUid, it string) (*images.IdentityImage, return &ii, nil } -func (db *Database) StoreIdentityImages(keyUid string, iis []*images.IdentityImage) error { +func (db *Database) StoreIdentityImages(keyUID string, iis []*images.IdentityImage) error { // Because SQL INSERTs are triggered in a loop use a tx to ensure a single call to the DB. tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{}) if err != nil { @@ -142,7 +142,7 @@ func (db *Database) StoreIdentityImages(keyUid string, iis []*images.IdentityIma _, err := tx.Exec( "INSERT INTO identity_images (key_uid, name, image_payload, width, height, file_size, resize_target) VALUES (?, ?, ?, ?, ?, ?, ?)", - keyUid, + keyUID, ii.Name, ii.Payload, ii.Width, @@ -158,7 +158,7 @@ func (db *Database) StoreIdentityImages(keyUid string, iis []*images.IdentityIma return nil } -func (db *Database) DeleteIdentityImage(keyUid string) error { - _, err := db.db.Exec(`DELETE FROM identity_images WHERE key_uid = ?`, keyUid) +func (db *Database) DeleteIdentityImage(keyUID string) error { + _, err := db.db.Exec(`DELETE FROM identity_images WHERE key_uid = ?`, keyUID) return err } diff --git a/multiaccounts/database_test.go b/multiaccounts/database_test.go index 7a94d9e57..b8c9b8daf 100644 --- a/multiaccounts/database_test.go +++ b/multiaccounts/database_test.go @@ -66,13 +66,13 @@ func TestLoginUpdate(t *testing.T) { // Profile Image tests var ( - keyUid = "0xdeadbeef" - keyUid2 = "0x1337beef" + keyUID = "0xdeadbeef" + keyUID2 = "0x1337beef" ) func seedTestDB(t *testing.T, db *Database) { iis := images.SampleIdentityImages() - require.NoError(t, db.StoreIdentityImages(keyUid, iis)) + require.NoError(t, db.StoreIdentityImages(keyUID, iis)) } func TestDatabase_GetIdentityImages(t *testing.T) { @@ -82,14 +82,14 @@ func TestDatabase_GetIdentityImages(t *testing.T) { expected := `[{"key_uid":"0xdeadbeef","type":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240},{"key_uid":"0xdeadbeef","type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}]` - oiis, err := db.GetIdentityImages(keyUid) + oiis, err := db.GetIdentityImages(keyUID) require.NoError(t, err) joiis, err := json.Marshal(oiis) require.NoError(t, err) require.Exactly(t, expected, string(joiis)) - oiis, err = db.GetIdentityImages(keyUid2) + oiis, err = db.GetIdentityImages(keyUID2) require.NoError(t, err) require.Exactly(t, 0, len(oiis)) @@ -101,22 +101,22 @@ func TestDatabase_GetIdentityImage(t *testing.T) { seedTestDB(t, db) cs := []struct { - KeyUid string + KeyUid string Name string Expected string }{ { - keyUid, + keyUID, images.SmallDimName, `{"key_uid":"0xdeadbeef","type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}`, }, { - keyUid, + keyUID, images.LargeDimName, `{"key_uid":"0xdeadbeef","type":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240}`, }, { - keyUid2, + keyUID2, images.LargeDimName, `{"key_uid":"","type":"","uri":"","width":0,"height":0,"file_size":0,"resize_target":0}`, }, @@ -137,9 +137,9 @@ func TestDatabase_DeleteIdentityImage(t *testing.T) { defer stop() seedTestDB(t, db) - require.NoError(t, db.DeleteIdentityImage(keyUid)) + require.NoError(t, db.DeleteIdentityImage(keyUID)) - oii, err := db.GetIdentityImage(keyUid, images.SmallDimName) + oii, err := db.GetIdentityImage(keyUID, images.SmallDimName) require.NoError(t, err) require.Empty(t, oii) } diff --git a/multiaccounts/migrations/bindata.go b/multiaccounts/migrations/bindata.go index 639a044d2..d3a764554 100644 --- a/multiaccounts/migrations/bindata.go +++ b/multiaccounts/migrations/bindata.go @@ -4,7 +4,7 @@ // 0001_accounts.up.sql (163B) // 1605007189_identity_images.down.sql (29B) // 1605007189_identity_images.up.sql (268B) -// 1606224181_drop_photo_path_from_accounts.down.sql (76B) +// 1606224181_drop_photo_path_from_accounts.down.sql (47B) // 1606224181_drop_photo_path_from_accounts.up.sql (675B) // doc.go (74B) @@ -155,7 +155,7 @@ func _1605007189_identity_imagesUpSql() (*asset, error) { return a, nil } -var __1606224181_drop_photo_path_from_accountsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x04\xc0\xb1\x0a\xc4\x20\x0c\x06\xe0\x3d\x4f\x91\xf7\x70\x8a\x1a\x0e\x41\xe3\xe1\xfd\x07\x5d\xc5\xc5\xa9\x16\x6a\xdf\xbf\x9f\xd7\x4f\x32\x46\x13\xfb\x49\x40\xaa\xe6\x88\x24\x43\x1b\x43\x7c\x56\xee\x63\xac\xe7\xdc\x37\x49\x8c\x1c\x6a\xfe\x17\xe3\x6b\xae\xbd\xbe\x7d\x4f\x86\x1e\x70\x44\xa1\x96\x92\xe0\xde\x00\x00\x00\xff\xff\xb3\x5f\x64\x53\x4c\x00\x00\x00") +var __1606224181_drop_photo_path_from_accountsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\x48\x4c\x4e\xce\x2f\xcd\x2b\x29\xe6\x72\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\x28\xc8\xc8\x2f\xc9\x0f\x48\x2c\xc9\x50\x08\x71\x8d\x08\xb1\x06\x04\x00\x00\xff\xff\xc2\xe6\xd6\xb1\x2f\x00\x00\x00") func _1606224181_drop_photo_path_from_accountsDownSqlBytes() ([]byte, error) { return bindataRead( @@ -170,8 +170,8 @@ func _1606224181_drop_photo_path_from_accountsDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1606224181_drop_photo_path_from_accounts.down.sql", size: 76, mode: os.FileMode(0644), modTime: time.Unix(1606224883, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x90, 0x14, 0xfc, 0xb9, 0x6e, 0x1, 0x27, 0x56, 0x83, 0xdd, 0xa7, 0x1a, 0x2, 0x38, 0x2b, 0x5, 0xb4, 0xf8, 0x69, 0xe7, 0x49, 0x52, 0xc8, 0x47, 0x28, 0xcd, 0x64, 0xb5, 0x43, 0x7a, 0x11, 0xc7}} + info := bindataFileInfo{name: "1606224181_drop_photo_path_from_accounts.down.sql", size: 47, mode: os.FileMode(0644), modTime: time.Unix(1606258709, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xdc, 0x18, 0x37, 0x1a, 0x2, 0x2b, 0x46, 0x72, 0xe0, 0x25, 0xa6, 0x7c, 0x59, 0xa4, 0xde, 0x3a, 0x78, 0x30, 0x9a, 0xc6, 0xbf, 0x24, 0x96, 0xa6, 0x4, 0xa4, 0x73, 0x92, 0xc6, 0x18, 0xe4, 0xfc}} return a, nil } diff --git a/multiaccounts/migrations/sql/1606224181_drop_photo_path_from_accounts.down.sql b/multiaccounts/migrations/sql/1606224181_drop_photo_path_from_accounts.down.sql index 5a0bd3653..92b1996ad 100644 --- a/multiaccounts/migrations/sql/1606224181_drop_photo_path_from_accounts.down.sql +++ b/multiaccounts/migrations/sql/1606224181_drop_photo_path_from_accounts.down.sql @@ -1,6 +1,2 @@ -BEGIN TRANSACTION; - ALTER TABLE accounts -ADD COLUMN photoPath TEXT; - -COMMIT; \ No newline at end of file +ADD COLUMN photoPath TEXT; \ No newline at end of file diff --git a/protocol/images/type.go b/protocol/images/type.go index fc2b9ff7f..d61e13954 100644 --- a/protocol/images/type.go +++ b/protocol/images/type.go @@ -6,7 +6,7 @@ import ( ) func ImageType(buf []byte) protobuf.ImageType { - switch images.GetType(buf){ + switch images.GetType(buf) { case images.JPEG: return protobuf.ImageType_JPEG case images.PNG: diff --git a/protocol/message_handler.go b/protocol/message_handler.go index ae13ae8ce..bc31055b9 100644 --- a/protocol/message_handler.go +++ b/protocol/message_handler.go @@ -841,11 +841,11 @@ func (m *MessageHandler) HandleChatIdentity(state *ReceivedMessageState, ci prot } } - dataUri, err := images.GetPayloadDataURI(ci.Images[name].Payload) + dataURI, err := images.GetPayloadDataURI(ci.Images[name].Payload) if err != nil { return err } - contact.Photo = dataUri + contact.Photo = dataURI contact.LastUpdated = ci.Clock state.ModifiedContacts[contact.ID] = true state.AllContacts[contact.ID] = contact diff --git a/protocol/messenger.go b/protocol/messenger.go index 43d65dc4d..4e6beeadb 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -557,8 +557,8 @@ func (m *Messenger) handleStandaloneChatIdentity(chat *Chat) error { } // shouldPublishChatIdentity returns true if the last time the ChatIdentity was attached was more than 24 hours ago -func (m *Messenger) shouldPublishChatIdentity(chatId string) (bool, error) { - lp, err := m.persistence.GetWhenChatIdentityLastPublished(chatId) +func (m *Messenger) shouldPublishChatIdentity(chatID string) (bool, error) { + lp, err := m.persistence.GetWhenChatIdentityLastPublished(chatID) if err != nil { return false, err } diff --git a/protocol/messenger_config.go b/protocol/messenger_config.go index db4d9e838..7ad37b283 100644 --- a/protocol/messenger_config.go +++ b/protocol/messenger_config.go @@ -2,10 +2,10 @@ package protocol import ( "database/sql" - "github.com/status-im/status-go/multiaccounts" "go.uber.org/zap" + "github.com/status-im/status-go/multiaccounts" "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/pushnotificationclient" diff --git a/protocol/persistence.go b/protocol/persistence.go index b436abd62..1f3aca6f0 100644 --- a/protocol/persistence.go +++ b/protocol/persistence.go @@ -768,8 +768,8 @@ func (db sqlitePersistence) TransactionsToValidate() ([]*TransactionToValidate, return transactions, nil } -func (db sqlitePersistence) GetWhenChatIdentityLastPublished(chatId string) (*int64, error) { - rows, err := db.db.Query("SELECT clock_value FROM chat_identity_last_published WHERE chat_id = ?", chatId) +func (db sqlitePersistence) GetWhenChatIdentityLastPublished(chatID string) (*int64, error) { + rows, err := db.db.Query("SELECT clock_value FROM chat_identity_last_published WHERE chat_id = ?", chatID) if err != nil { return nil, err } @@ -786,7 +786,7 @@ func (db sqlitePersistence) GetWhenChatIdentityLastPublished(chatId string) (*in return &t, nil } -func (db sqlitePersistence) SaveWhenChatIdentityLastPublished(chatId string) error { +func (db sqlitePersistence) SaveWhenChatIdentityLastPublished(chatID string) error { tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{}) if err != nil { return err @@ -806,7 +806,7 @@ func (db sqlitePersistence) SaveWhenChatIdentityLastPublished(chatId string) err } defer stmt.Close() - _, err = stmt.Exec(chatId, time.Now().Unix()) + _, err = stmt.Exec(chatID, time.Now().Unix()) if err != nil { return err } diff --git a/protocol/persistence_test.go b/protocol/persistence_test.go index 210b517dd..866a4d6bd 100644 --- a/protocol/persistence_test.go +++ b/protocol/persistence_test.go @@ -647,13 +647,13 @@ func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) { require.NoError(t, err) p := sqlitePersistence{db: db} - chatId := "abcd1234" + chatID := "0xabcd1234" now := time.Now().Unix() - err = p.SaveWhenChatIdentityLastPublished(chatId) + err = p.SaveWhenChatIdentityLastPublished(chatID) require.NoError(t, err) - ts, err := p.GetWhenChatIdentityLastPublished(chatId) + ts, err := p.GetWhenChatIdentityLastPublished(chatID) require.NoError(t, err) // Check that the save happened in the last 2 seconds @@ -661,7 +661,7 @@ func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) { require.LessOrEqual(t, diff, int64(2)) // Require unsaved values to be zero - ts2, err := p.GetWhenChatIdentityLastPublished("deadbeef") + ts2, err := p.GetWhenChatIdentityLastPublished("0xdeadbeef") require.NoError(t, err) require.Exactly(t, int64(0), *ts2) }