status-go/protocol/messenger_identity_image_te...

533 lines
16 KiB
Go
Raw Permalink Normal View History

2021-02-17 23:14:48 +00:00
package protocol
import (
"context"
"crypto/ecdsa"
"errors"
"fmt"
2021-02-17 23:14:48 +00:00
"testing"
"time"
"github.com/cenkalti/backoff/v3"
"github.com/stretchr/testify/require"
2021-02-17 23:14:48 +00:00
"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"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/multiaccounts"
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/params"
2021-02-17 23:14:48 +00:00
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
2021-02-17 23:14:48 +00:00
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/waku"
)
func TestMessengerProfilePictureHandlerSuite(t *testing.T) {
suite.Run(t, new(MessengerProfilePictureHandlerSuite))
}
type MessengerProfilePictureHandlerSuite struct {
suite.Suite
alice *Messenger // client instance of Messenger
bob *Messenger // server instance of Messenger
// If one wants to send messages between different instances of Messenger,
// a single Waku service should be shared.
shh types.Waku
logger *zap.Logger
}
func (s *MessengerProfilePictureHandlerSuite) SetupSuite() {
s.logger = tt.MustCreateTestLogger()
// Setup Waku things
config := waku.DefaultConfig
config.MinimumAcceptedPoW = 0
wakuLogger := s.logger.Named("Waku")
shh := waku.New(&config, wakuLogger)
s.shh = gethbridge.NewGethWakuWrapper(shh)
s.Require().NoError(shh.Start())
}
2021-02-17 23:14:48 +00:00
func (s *MessengerProfilePictureHandlerSuite) TearDownSuite() {
_ = gethbridge.GetGethWakuFrom(s.shh).Stop()
_ = s.logger.Sync()
}
2021-02-17 23:14:48 +00:00
func (s *MessengerProfilePictureHandlerSuite) newMessenger(name string) *Messenger {
m, err := newTestMessenger(s.shh, testMessengerConfig{
logger: s.logger.Named(fmt.Sprintf("messenger-%s", name)),
name: name,
extraOptions: []Option{
WithAppSettings(newTestSettings(), params.NodeConfig{}),
},
})
2021-02-17 23:14:48 +00:00
s.Require().NoError(err)
_, err = m.Start()
2021-02-17 23:14:48 +00:00
s.Require().NoError(err)
return m
}
func (s *MessengerProfilePictureHandlerSuite) SetupTest() {
// Generate Alice Messenger
s.alice = s.newMessenger("Alice")
s.bob = s.newMessenger("Bobby")
2021-02-17 23:14:48 +00:00
// Setup MultiAccount for Alice Messenger
s.setupMultiAccount(s.alice)
}
func (s *MessengerProfilePictureHandlerSuite) TearDownTest() {
2021-02-17 23:14:48 +00:00
// Shutdown messengers
TearDownMessenger(&s.Suite, s.alice)
2021-02-17 23:14:48 +00:00
s.alice = nil
TearDownMessenger(&s.Suite, s.bob)
2021-02-17 23:14:48 +00:00
s.bob = nil
_ = s.logger.Sync()
}
func (s *MessengerProfilePictureHandlerSuite) setupMultiAccount(m *Messenger) {
name, err := m.settings.DisplayName()
s.Require().NoError(err)
keyUID := m.IdentityPublicKeyString()
m.account = &multiaccounts.Account{
Name: name,
KeyUID: keyUID,
}
2021-02-17 23:14:48 +00:00
err = m.multiAccounts.SaveAccount(*m.account)
2021-02-17 23:14:48 +00:00
s.NoError(err)
}
func (s *MessengerProfilePictureHandlerSuite) generateAndStoreIdentityImages(m *Messenger) map[string]images.IdentityImage {
keyUID := m.IdentityPublicKeyString()
2021-02-17 23:14:48 +00:00
iis := images.SampleIdentityImages()
err := m.multiAccounts.StoreIdentityImages(keyUID, iis, false)
s.Require().NoError(err)
out := make(map[string]images.IdentityImage)
for _, ii := range iis {
out[ii.Name] = ii
}
s.Require().Contains(out, images.SmallDimName)
s.Require().Contains(out, images.LargeDimName)
return out
2021-02-17 23:14:48 +00:00
}
func (s *MessengerProfilePictureHandlerSuite) TestChatIdentity() {
iis := s.generateAndStoreIdentityImages(s.alice)
ci, err := s.alice.createChatIdentity(privateChat)
s.Require().NoError(err)
s.Require().Exactly(len(iis), len(ci.Images))
}
func (s *MessengerProfilePictureHandlerSuite) TestEncryptDecryptIdentityImagesWithContactPubKeys() {
smPayload := "hello small image"
lgPayload := "hello large image"
ci := protobuf.ChatIdentity{
Clock: uint64(time.Now().Unix()),
Images: map[string]*protobuf.IdentityImage{
"small": {
Payload: []byte(smPayload),
},
"large": {
Payload: []byte(lgPayload),
},
},
}
// Make contact keys and Contacts, set the Contacts to added
contactKeys := make([]*ecdsa.PrivateKey, 10)
for i := range contactKeys {
contactKey, err := crypto.GenerateKey()
s.Require().NoError(err)
contactKeys[i] = contactKey
contact, err := BuildContactFromPublicKey(&contactKey.PublicKey)
s.Require().NoError(err)
2023-01-20 14:28:30 +00:00
contact.ContactRequestLocalState = ContactRequestStateSent
2021-02-17 23:14:48 +00:00
s.alice.allContacts.Store(contact.ID, contact)
}
// Test EncryptIdentityImagesWithContactPubKeys
err := EncryptIdentityImagesWithContactPubKeys(ci.Images, s.alice)
s.Require().NoError(err)
for _, ii := range ci.Images {
s.Require().Equal(s.alice.allContacts.Len(), len(ii.EncryptionKeys))
}
s.Require().NotEqual([]byte(smPayload), ci.Images["small"].Payload)
s.Require().NotEqual([]byte(lgPayload), ci.Images["large"].Payload)
s.Require().True(ci.Images["small"].Encrypted)
s.Require().True(ci.Images["large"].Encrypted)
// Test DecryptIdentityImagesWithIdentityPrivateKey
err = DecryptIdentityImagesWithIdentityPrivateKey(ci.Images, contactKeys[2], &s.alice.identity.PublicKey)
s.Require().NoError(err)
s.Require().Equal(smPayload, string(ci.Images["small"].Payload))
s.Require().Equal(lgPayload, string(ci.Images["large"].Payload))
s.Require().False(ci.Images["small"].Encrypted)
s.Require().False(ci.Images["large"].Encrypted)
// RESET Messenger identity, Contacts and IdentityImage.EncryptionKeys
s.alice.allContacts = new(contactMap)
ci.Images["small"].EncryptionKeys = nil
ci.Images["large"].EncryptionKeys = nil
// Test EncryptIdentityImagesWithContactPubKeys with no contacts
err = EncryptIdentityImagesWithContactPubKeys(ci.Images, s.alice)
s.Require().NoError(err)
for _, ii := range ci.Images {
s.Require().Equal(0, len(ii.EncryptionKeys))
}
s.Require().NotEqual([]byte(smPayload), ci.Images["small"].Payload)
s.Require().NotEqual([]byte(lgPayload), ci.Images["large"].Payload)
s.Require().True(ci.Images["small"].Encrypted)
s.Require().True(ci.Images["large"].Encrypted)
// Test DecryptIdentityImagesWithIdentityPrivateKey with no valid identity
err = DecryptIdentityImagesWithIdentityPrivateKey(ci.Images, contactKeys[2], &s.alice.identity.PublicKey)
s.Require().NoError(err)
s.Require().NotEqual([]byte(smPayload), ci.Images["small"].Payload)
s.Require().NotEqual([]byte(lgPayload), ci.Images["large"].Payload)
s.Require().True(ci.Images["small"].Encrypted)
s.Require().True(ci.Images["large"].Encrypted)
}
2021-10-20 09:45:54 +00:00
func (s *MessengerProfilePictureHandlerSuite) TestPictureInPrivateChatOneSided() {
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
err := s.bob.settings.SaveSettingField(settings.ProfilePicturesVisibility, settings.ProfilePicturesShowToEveryone)
2021-10-20 09:45:54 +00:00
s.Require().NoError(err)
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
err = s.alice.settings.SaveSettingField(settings.ProfilePicturesVisibility, settings.ProfilePicturesShowToEveryone)
2021-10-20 09:45:54 +00:00
s.Require().NoError(err)
bChat := CreateOneToOneChat(s.alice.IdentityPublicKeyString(), s.alice.IdentityPublicKey(), s.alice.transport)
2021-10-20 09:45:54 +00:00
err = s.bob.SaveChat(bChat)
s.Require().NoError(err)
_, err = s.bob.Join(bChat)
s.Require().NoError(err)
// Alice sends a message to the public chat
message := buildTestMessage(*bChat)
response, err := s.bob.SendChatMessage(context.Background(), message)
s.Require().NoError(err)
s.Require().NotNil(response)
options := func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 2 * time.Second
}
err = tt.RetryWithBackOff(func() error {
response, err = s.alice.RetrieveAll()
if err != nil {
return err
}
s.Require().NotNil(response)
contacts := response.Contacts
s.logger.Debug("RetryWithBackOff contact data", zap.Any("contacts", contacts))
if len(contacts) > 0 && len(contacts[0].Images) > 0 {
s.logger.Debug("", zap.Any("contacts", contacts))
return nil
}
return errors.New("no new contacts with images received")
}, options)
}
2021-02-17 23:14:48 +00:00
func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePicture() {
profilePicShowSettings := []settings.ProfilePicturesShowToType{
settings.ProfilePicturesShowToContactsOnly,
settings.ProfilePicturesShowToEveryone,
settings.ProfilePicturesShowToNone,
2021-02-17 23:14:48 +00:00
}
profilePicViewSettings := []settings.ProfilePicturesVisibilityType{
settings.ProfilePicturesVisibilityContactsOnly,
settings.ProfilePicturesVisibilityEveryone,
settings.ProfilePicturesVisibilityNone,
2021-02-17 23:14:48 +00:00
}
isContactFor := map[string][]bool{
"alice": {true, false},
"bob": {true, false},
}
chatContexts := []ChatContext{
2021-02-17 23:14:48 +00:00
publicChat,
privateChat,
}
// TODO see if possible to push each test scenario into a go routine
for _, cc := range chatContexts {
for _, ss := range profilePicShowSettings {
for _, vs := range profilePicViewSettings {
2021-02-17 23:14:48 +00:00
for _, ac := range isContactFor["alice"] {
for _, bc := range isContactFor["bob"] {
args := &e2eArgs{
chatContext: cc,
showToType: ss,
visibilityType: vs,
aliceContact: ac,
bobContact: bc,
2021-02-17 23:14:48 +00:00
}
s.Run(args.TestCaseName(s.T()), func() {
s.testE2eSendingReceivingProfilePicture(args)
})
}
}
}
}
}
2021-02-17 23:14:48 +00:00
s.SetupTest()
}
2021-02-17 23:14:48 +00:00
func (s *MessengerProfilePictureHandlerSuite) testE2eSendingReceivingProfilePicture(args *e2eArgs) {
// Generate Alice Messenger
alice := s.newMessenger("Alice")
bob := s.newMessenger("Bobby")
2021-02-17 23:14:48 +00:00
// Setup MultiAccount for Alice Messenger
s.setupMultiAccount(alice)
2021-02-17 23:14:48 +00:00
defer func() {
TearDownMessenger(&s.Suite, alice)
alice = nil
TearDownMessenger(&s.Suite, bob)
bob = nil
_ = s.logger.Sync()
}()
2021-02-17 23:14:48 +00:00
s.logger.Info("testing with criteria:", zap.Any("args", args))
defer s.logger.Info("Completed testing with criteria:", zap.Any("args", args))
2021-02-17 23:14:48 +00:00
expectPicture, err := args.resultExpected()
s.Require().NoError(err)
2021-02-17 23:14:48 +00:00
s.logger.Debug("expect to receive a profile pic?",
zap.Bool("result", expectPicture),
zap.Error(err))
2021-02-17 23:14:48 +00:00
// Setting up Bob
err = bob.settings.SaveSettingField(settings.ProfilePicturesVisibility, args.visibilityType)
s.Require().NoError(err)
2021-02-17 23:14:48 +00:00
if args.bobContact {
_, err = bob.AddContact(context.Background(), &requests.AddContact{ID: alice.IdentityPublicKeyString()})
s.Require().NoError(err)
}
2021-02-17 23:14:48 +00:00
// Create Bob's chats
switch args.chatContext {
case publicChat:
// Bob opens up the public chat and joins it
bChat := CreatePublicChat("status", alice.transport)
err = bob.SaveChat(bChat)
s.Require().NoError(err)
2021-02-17 23:14:48 +00:00
_, err = bob.Join(bChat)
s.Require().NoError(err)
case privateChat:
bChat := CreateOneToOneChat(alice.IdentityPublicKeyString(), alice.IdentityPublicKey(), alice.transport)
err = bob.SaveChat(bChat)
s.Require().NoError(err)
_, err = bob.Join(bChat)
s.Require().NoError(err)
default:
s.Failf("unexpected chat context type", "%s", string(args.chatContext))
}
// Setting up Alice
err = alice.settings.SaveSettingField(settings.ProfilePicturesShowTo, args.showToType)
s.Require().NoError(err)
if args.aliceContact {
_, err = alice.AddContact(context.Background(), &requests.AddContact{ID: bob.IdentityPublicKeyString()})
s.Require().NoError(err)
}
iis := s.generateAndStoreIdentityImages(alice)
// Create chats
var aChat *Chat
switch args.chatContext {
case publicChat:
// Alice opens creates a public chat
aChat = CreatePublicChat("status", alice.transport)
err = alice.SaveChat(aChat)
s.Require().NoError(err)
// Alice sends a message to the public chat
message := buildTestMessage(*aChat)
response, err := alice.SendChatMessage(context.Background(), message)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.messages, 1)
case privateChat:
aChat = CreateOneToOneChat(bob.IdentityPublicKeyString(), bob.IdentityPublicKey(), bob.transport)
err = alice.SaveChat(aChat)
s.Require().NoError(err)
_, err = alice.Join(aChat)
s.Require().NoError(err)
err = alice.publishContactCode()
s.Require().NoError(err)
default:
s.Failf("unexpected chat context type", "%s", string(args.chatContext))
}
// Poll bob to see if he got the chatIdentity
// Retrieve ChatIdentity
var contacts []*Contact
options := func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 2 * time.Second
}
err = tt.RetryWithBackOff(func() error {
response, err := bob.RetrieveAll()
if err != nil {
return err
}
contacts = response.Contacts
if len(contacts) > 0 && len(contacts[0].Images) > 0 {
return nil
2021-02-17 23:14:48 +00:00
}
return errors.New("no new contacts with images received")
}, options)
if !expectPicture {
s.Require().EqualError(err, "no new contacts with images received")
return
2021-02-17 23:14:48 +00:00
}
s.Require().NoError(err)
s.Require().NotNil(contacts)
// Check if alice's contact data with profile picture is there
var contact *Contact
for _, c := range contacts {
if c.ID == alice.IdentityPublicKeyString() {
contact = c
}
}
s.Require().NotNil(contact)
// Check that Bob now has Alice's profile picture(s)
switch args.chatContext {
case publicChat:
// In public chat context we only need the images.SmallDimName, but also may have the large
s.Require().GreaterOrEqual(len(contact.Images), 1)
s.Require().Contains(contact.Images, images.SmallDimName)
s.Require().Equal(iis[images.SmallDimName].Payload, contact.Images[images.SmallDimName].Payload)
case privateChat:
s.Require().Equal(len(contact.Images), 2)
s.Require().Contains(contact.Images, images.SmallDimName)
s.Require().Contains(contact.Images, images.LargeDimName)
s.Require().Equal(iis[images.SmallDimName].Payload, contact.Images[images.SmallDimName].Payload)
s.Require().Equal(iis[images.LargeDimName].Payload, contact.Images[images.LargeDimName].Payload)
}
}
type e2eArgs struct {
chatContext ChatContext
showToType settings.ProfilePicturesShowToType
visibilityType settings.ProfilePicturesVisibilityType
aliceContact bool
bobContact bool
}
func (args *e2eArgs) String() string {
return fmt.Sprintf("ChatContext: %s, ShowTo: %s, Visibility: %s, AliceContact: %t, BobContact: %t",
string(args.chatContext),
profilePicShowSettingsMap[args.showToType],
profilePicViewSettingsMap[args.visibilityType],
args.aliceContact,
args.bobContact,
)
2021-02-17 23:14:48 +00:00
}
func (args *e2eArgs) TestCaseName(t *testing.T) string {
expected, err := args.resultExpected()
require.NoError(t, err)
return fmt.Sprintf("%s-%s-%s-ac.%t-bc.%t-exp.%t",
string(args.chatContext),
profilePicShowSettingsMap[args.showToType],
profilePicViewSettingsMap[args.visibilityType],
args.aliceContact,
args.bobContact,
expected,
)
}
func (args *e2eArgs) resultExpected() (bool, error) {
switch args.showToType {
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
case settings.ProfilePicturesShowToContactsOnly:
if args.aliceContact {
return args.resultExpectedVS()
2021-02-17 23:14:48 +00:00
}
return false, nil
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
case settings.ProfilePicturesShowToEveryone:
return args.resultExpectedVS()
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
case settings.ProfilePicturesShowToNone:
2021-02-17 23:14:48 +00:00
return false, nil
default:
return false, errors.New("unknown ProfilePicturesShowToType")
}
}
func (args *e2eArgs) resultExpectedVS() (bool, error) {
switch args.visibilityType {
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
case settings.ProfilePicturesVisibilityContactsOnly:
2021-02-17 23:14:48 +00:00
return true, nil
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
case settings.ProfilePicturesVisibilityEveryone:
2021-02-17 23:14:48 +00:00
return true, nil
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
case settings.ProfilePicturesVisibilityNone:
2021-10-12 11:18:15 +00:00
// If we are contacts, we save the image regardless
return args.bobContact, nil
2021-02-17 23:14:48 +00:00
default:
return false, errors.New("unknown ProfilePicturesVisibilityType")
}
}
var profilePicShowSettingsMap = map[settings.ProfilePicturesShowToType]string{
settings.ProfilePicturesShowToContactsOnly: "ShowToContactsOnly",
settings.ProfilePicturesShowToEveryone: "ShowToEveryone",
settings.ProfilePicturesShowToNone: "ShowToNone",
}
var profilePicViewSettingsMap = map[settings.ProfilePicturesVisibilityType]string{
settings.ProfilePicturesVisibilityContactsOnly: "ViewFromContactsOnly",
settings.ProfilePicturesVisibilityEveryone: "ViewFromEveryone",
settings.ProfilePicturesVisibilityNone: "ViewFromNone",
}