Resolved linting issues

This commit is contained in:
Samuel Hawksby-Robinson 2020-11-24 23:16:19 +00:00 committed by Andrea Maria Piana
parent 190b1a70f9
commit a77a40fdf4
11 changed files with 44 additions and 49 deletions

View File

@ -41,14 +41,13 @@ func EncodeToBestSize(bb *bytes.Buffer, img image.Image, size ResizeDimension) e
if q == MinJpegQuality { if q == MinJpegQuality {
if DimensionSizeLimit[size].Max > bb.Len() { if DimensionSizeLimit[size].Max > bb.Len() {
return nil return nil
} else { }
return fmt.Errorf( return fmt.Errorf(
"image size after processing exceeds max, expect < '%d', received < '%d'", "image size after processing exceeds max, expect < '%d', received < '%d'",
DimensionSizeLimit[size].Max, DimensionSizeLimit[size].Max,
bb.Len(), bb.Len(),
) )
} }
}
bb.Reset() bb.Reset()
q -= 2 q -= 2

View File

@ -81,8 +81,8 @@ func (db *Database) DeleteAccount(keyUID string) error {
// Account images // Account images
func (db *Database) GetIdentityImages(keyUid string) ([]*images.IdentityImage, error) { 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) 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 { if err != nil {
return nil, err return nil, err
} }
@ -102,8 +102,8 @@ func (db *Database) GetIdentityImages(keyUid string) ([]*images.IdentityImage, e
return iis, nil return iis, nil
} }
func (db *Database) GetIdentityImage(keyUid, it string) (*images.IdentityImage, error) { 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) 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 { if err != nil {
return nil, err return nil, err
} }
@ -120,7 +120,7 @@ func (db *Database) GetIdentityImage(keyUid, it string) (*images.IdentityImage,
return &ii, nil 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. // 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{}) tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
if err != nil { if err != nil {
@ -142,7 +142,7 @@ func (db *Database) StoreIdentityImages(keyUid string, iis []*images.IdentityIma
_, err := tx.Exec( _, err := tx.Exec(
"INSERT INTO identity_images (key_uid, name, image_payload, width, height, file_size, resize_target) VALUES (?, ?, ?, ?, ?, ?, ?)", "INSERT INTO identity_images (key_uid, name, image_payload, width, height, file_size, resize_target) VALUES (?, ?, ?, ?, ?, ?, ?)",
keyUid, keyUID,
ii.Name, ii.Name,
ii.Payload, ii.Payload,
ii.Width, ii.Width,
@ -158,7 +158,7 @@ func (db *Database) StoreIdentityImages(keyUid string, iis []*images.IdentityIma
return nil return nil
} }
func (db *Database) DeleteIdentityImage(keyUid string) error { func (db *Database) DeleteIdentityImage(keyUID string) error {
_, err := db.db.Exec(`DELETE FROM identity_images WHERE key_uid = ?`, keyUid) _, err := db.db.Exec(`DELETE FROM identity_images WHERE key_uid = ?`, keyUID)
return err return err
} }

View File

@ -66,13 +66,13 @@ func TestLoginUpdate(t *testing.T) {
// Profile Image tests // Profile Image tests
var ( var (
keyUid = "0xdeadbeef" keyUID = "0xdeadbeef"
keyUid2 = "0x1337beef" keyUID2 = "0x1337beef"
) )
func seedTestDB(t *testing.T, db *Database) { func seedTestDB(t *testing.T, db *Database) {
iis := images.SampleIdentityImages() iis := images.SampleIdentityImages()
require.NoError(t, db.StoreIdentityImages(keyUid, iis)) require.NoError(t, db.StoreIdentityImages(keyUID, iis))
} }
func TestDatabase_GetIdentityImages(t *testing.T) { 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}]` 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) require.NoError(t, err)
joiis, err := json.Marshal(oiis) joiis, err := json.Marshal(oiis)
require.NoError(t, err) require.NoError(t, err)
require.Exactly(t, expected, string(joiis)) require.Exactly(t, expected, string(joiis))
oiis, err = db.GetIdentityImages(keyUid2) oiis, err = db.GetIdentityImages(keyUID2)
require.NoError(t, err) require.NoError(t, err)
require.Exactly(t, 0, len(oiis)) require.Exactly(t, 0, len(oiis))
@ -106,17 +106,17 @@ func TestDatabase_GetIdentityImage(t *testing.T) {
Expected string Expected string
}{ }{
{ {
keyUid, keyUID,
images.SmallDimName, images.SmallDimName,
`{"key_uid":"0xdeadbeef","type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}`, `{"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, images.LargeDimName,
`{"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":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240}`,
}, },
{ {
keyUid2, keyUID2,
images.LargeDimName, images.LargeDimName,
`{"key_uid":"","type":"","uri":"","width":0,"height":0,"file_size":0,"resize_target":0}`, `{"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() defer stop()
seedTestDB(t, db) 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.NoError(t, err)
require.Empty(t, oii) require.Empty(t, oii)
} }

View File

@ -4,7 +4,7 @@
// 0001_accounts.up.sql (163B) // 0001_accounts.up.sql (163B)
// 1605007189_identity_images.down.sql (29B) // 1605007189_identity_images.down.sql (29B)
// 1605007189_identity_images.up.sql (268B) // 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) // 1606224181_drop_photo_path_from_accounts.up.sql (675B)
// doc.go (74B) // doc.go (74B)
@ -155,7 +155,7 @@ func _1605007189_identity_imagesUpSql() (*asset, error) {
return a, nil 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) { func _1606224181_drop_photo_path_from_accountsDownSqlBytes() ([]byte, error) {
return bindataRead( return bindataRead(
@ -170,8 +170,8 @@ func _1606224181_drop_photo_path_from_accountsDownSql() (*asset, error) {
return nil, err 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)} 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{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}} 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 return a, nil
} }

View File

@ -1,6 +1,2 @@
BEGIN TRANSACTION;
ALTER TABLE accounts ALTER TABLE accounts
ADD COLUMN photoPath TEXT; ADD COLUMN photoPath TEXT;
COMMIT;

View File

@ -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 { if err != nil {
return err return err
} }
contact.Photo = dataUri contact.Photo = dataURI
contact.LastUpdated = ci.Clock contact.LastUpdated = ci.Clock
state.ModifiedContacts[contact.ID] = true state.ModifiedContacts[contact.ID] = true
state.AllContacts[contact.ID] = contact state.AllContacts[contact.ID] = contact

View File

@ -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 // 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) { func (m *Messenger) shouldPublishChatIdentity(chatID string) (bool, error) {
lp, err := m.persistence.GetWhenChatIdentityLastPublished(chatId) lp, err := m.persistence.GetWhenChatIdentityLastPublished(chatID)
if err != nil { if err != nil {
return false, err return false, err
} }

View File

@ -2,10 +2,10 @@ package protocol
import ( import (
"database/sql" "database/sql"
"github.com/status-im/status-go/multiaccounts"
"go.uber.org/zap" "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/common"
"github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/pushnotificationclient" "github.com/status-im/status-go/protocol/pushnotificationclient"

View File

@ -768,8 +768,8 @@ func (db sqlitePersistence) TransactionsToValidate() ([]*TransactionToValidate,
return transactions, nil return transactions, nil
} }
func (db sqlitePersistence) GetWhenChatIdentityLastPublished(chatId string) (*int64, error) { 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) rows, err := db.db.Query("SELECT clock_value FROM chat_identity_last_published WHERE chat_id = ?", chatID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -786,7 +786,7 @@ func (db sqlitePersistence) GetWhenChatIdentityLastPublished(chatId string) (*in
return &t, nil 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{}) tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
if err != nil { if err != nil {
return err return err
@ -806,7 +806,7 @@ func (db sqlitePersistence) SaveWhenChatIdentityLastPublished(chatId string) err
} }
defer stmt.Close() defer stmt.Close()
_, err = stmt.Exec(chatId, time.Now().Unix()) _, err = stmt.Exec(chatID, time.Now().Unix())
if err != nil { if err != nil {
return err return err
} }

View File

@ -647,13 +647,13 @@ func TestSqlitePersistence_GetWhenChatIdentityLastPublished(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
p := sqlitePersistence{db: db} p := sqlitePersistence{db: db}
chatId := "abcd1234" chatID := "0xabcd1234"
now := time.Now().Unix() now := time.Now().Unix()
err = p.SaveWhenChatIdentityLastPublished(chatId) err = p.SaveWhenChatIdentityLastPublished(chatID)
require.NoError(t, err) require.NoError(t, err)
ts, err := p.GetWhenChatIdentityLastPublished(chatId) ts, err := p.GetWhenChatIdentityLastPublished(chatID)
require.NoError(t, err) require.NoError(t, err)
// Check that the save happened in the last 2 seconds // 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.LessOrEqual(t, diff, int64(2))
// Require unsaved values to be zero // Require unsaved values to be zero
ts2, err := p.GetWhenChatIdentityLastPublished("deadbeef") ts2, err := p.GetWhenChatIdentityLastPublished("0xdeadbeef")
require.NoError(t, err) require.NoError(t, err)
require.Exactly(t, int64(0), *ts2) require.Exactly(t, int64(0), *ts2)
} }