Resolving fix for receiving chat identities with empty images map

This commit is contained in:
Samuel Hawksby-Robinson 2020-11-30 11:03:44 +00:00 committed by Andrea Maria Piana
parent 43b8e94b2b
commit 5d0906b9d8
2 changed files with 23 additions and 13 deletions

View File

@ -4,7 +4,6 @@ import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"github.com/pkg/errors"
"github.com/status-im/status-go/eth-node/crypto"
@ -833,21 +832,24 @@ func (m *MessageHandler) HandleChatIdentity(state *ReceivedMessageState, ci prot
contact.ENSVerified = false
} */
// Get the largest
var name string
var iiSize int
for n, ii := range ci.Images {
if iiSize < len(ii.Payload) {
iiSize = len(ii.Payload)
name = n
if len(ci.Images) > 0 {
// Get the largest
var name string
var iiSize int
for n, ii := range ci.Images {
if iiSize < len(ii.Payload) {
iiSize = len(ii.Payload)
name = n
}
}
dataURI, err := images.GetPayloadDataURI(ci.Images[name].Payload)
if err != nil {
return err
}
contact.Photo = dataURI
}
dataURI, err := images.GetPayloadDataURI(ci.Images[name].Payload)
if err != nil {
return err
}
contact.Photo = dataURI
contact.LastUpdated = ci.Clock
state.ModifiedContacts[contact.ID] = true
state.AllContacts[contact.ID] = contact

View File

@ -5,6 +5,7 @@ import (
"crypto/ecdsa"
"encoding/hex"
"errors"
"io/ioutil"
"testing"
"github.com/google/uuid"
@ -14,6 +15,7 @@ import (
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"
"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"
@ -78,12 +80,18 @@ func (s *MessengerPushNotificationSuite) newMessengerWithOptions(shh types.Waku,
}
func (s *MessengerPushNotificationSuite) newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey) *Messenger {
tmpfile, err := ioutil.TempFile("", "accounts-tests-")
s.Require().NoError(err)
madb, err := multiaccounts.InitializeDB(tmpfile.Name())
s.Require().NoError(err)
options := []Option{
WithCustomLogger(s.logger),
WithMessagesPersistenceEnabled(),
WithDatabaseConfig(sqlite.InMemoryPath, ""),
WithDatasync(),
WithPushNotifications(),
WithMultiAccounts(madb),
}
return s.newMessengerWithOptions(shh, privateKey, options)
}