-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix contact details large image is always empty (#4864)
fixes #13563 contact details largeImage is always empty
- Loading branch information
Showing
5 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package protocol | ||
|
||
import ( | ||
_ "github.com/mutecomm/go-sqlcipher/v4" // require go-sqlcipher that overrides default implementation | ||
|
||
"github.com/status-im/status-go/eth-node/crypto" | ||
"github.com/status-im/status-go/eth-node/types" | ||
"github.com/status-im/status-go/images" | ||
"github.com/status-im/status-go/multiaccounts/settings" | ||
"github.com/status-im/status-go/protocol/protobuf" | ||
) | ||
|
||
func isImageWithNamePresent(imgs map[string]*protobuf.IdentityImage, name string) bool { | ||
for k, v := range imgs { | ||
if k == name && len(v.Payload) > 0 { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (s *MessengerSuite) retrieveIdentityImages(alice, bob *Messenger, chat *Chat) map[string]*protobuf.IdentityImage { | ||
s.Require().NoError(alice.settings.SaveSettingField(settings.DisplayName, "alice")) | ||
|
||
identityImages := images.SampleIdentityImages() | ||
identityImagesMap := make(map[string]images.IdentityImage) | ||
for _, img := range identityImages { | ||
img.KeyUID = s.m.account.KeyUID | ||
identityImagesMap[img.Name] = img | ||
} | ||
|
||
err := s.m.multiAccounts.StoreIdentityImages(s.m.account.KeyUID, identityImages, true) | ||
s.Require().NoError(err) | ||
s.Require().NoError(alice.SaveChat(chat)) | ||
s.Require().NoError(bob.settings.SaveSettingField(settings.DisplayName, "bob")) | ||
s.Require().NoError(bob.SaveChat(chat)) | ||
|
||
chatContext := GetChatContextFromChatType(chat.ChatType) | ||
|
||
chatIdentity, err := alice.createChatIdentity(chatContext) | ||
s.Require().NoError(err) | ||
|
||
imgs := chatIdentity.Images | ||
s.Require().NoError(err) | ||
|
||
return imgs | ||
} | ||
|
||
func (s *MessengerSuite) TestTwoImagesAreAddedToChatIdentityForPrivateChat() { | ||
alice := s.m | ||
bob := s.newMessenger() | ||
defer TearDownMessenger(&s.Suite, bob) | ||
|
||
bobPkString := types.EncodeHex(crypto.FromECDSAPub(&bob.identity.PublicKey)) | ||
|
||
chat := CreateOneToOneChat(bobPkString, &bob.identity.PublicKey, alice.transport) | ||
s.Require().Equal(privateChat, GetChatContextFromChatType(chat.ChatType)) | ||
|
||
imgs := s.retrieveIdentityImages(alice, bob, chat) | ||
s.Require().Len(imgs, 2) | ||
s.Require().Equal(true, isImageWithNamePresent(imgs, "thumbnail")) | ||
s.Require().Equal(true, isImageWithNamePresent(imgs, "large")) | ||
} | ||
|
||
func (s *MessengerSuite) TestOneImageIsAddedToChatIdentityForPublicChat() { | ||
alice := s.m | ||
bob := s.newMessenger() | ||
defer TearDownMessenger(&s.Suite, bob) | ||
|
||
chat := CreatePublicChat("alic-and-bob-chat", &testTimeSource{}) | ||
s.Require().Equal(publicChat, GetChatContextFromChatType(chat.ChatType)) | ||
|
||
imgs := s.retrieveIdentityImages(alice, bob, chat) | ||
s.Require().Len(imgs, 1) | ||
s.Require().Equal(true, isImageWithNamePresent(imgs, "thumbnail")) | ||
s.Require().Equal(false, isImageWithNamePresent(imgs, "large")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters