mirror of
https://github.com/status-im/status-go.git
synced 2025-02-22 03:38:27 +00:00
fix(sync)_: sync fallback notification (#5888)
* fix(sync)_: Improve EnableInstallationAndSync and add EnableInstallationV2 - Refactor EnableInstallationAndSync for better error handling and response merging - Add new EnableInstallationV2 method returning the installation - Update tests to check for installation in response - Deprecate old EnableInstallation method * chore_: remove EnableInstallationV2 * fix(sync)_: create/delete AC notification only when targetInstallationID match - Add targetInstallationID parameter to SendPairInstallation function - Update protobuf SyncPairInstallation struct with TargetInstallationId field - Modify method calls across multiple test files to include new parameter - Update pairing.proto and pairing.pb.go with new field for local pairing * chore_: rename stubEnableInstallationAndPair chore_: move InstallationIDProvider chore_: revert endpoints.go test_: check AC with resp chore_: rename ModifiedInstallationsTargetedToThisDevice test_: add InstallationIDProvider chore_: revert endpoints.go chore_: remove comment test_: add TestNewInstallationCreatedIsNotDeleted
This commit is contained in:
parent
94ff99d727
commit
a08319f615
@ -3148,8 +3148,9 @@ type ReceivedMessageState struct {
|
|||||||
ModifiedContacts *stringBoolMap
|
ModifiedContacts *stringBoolMap
|
||||||
// All installations in memory
|
// All installations in memory
|
||||||
AllInstallations *installationMap
|
AllInstallations *installationMap
|
||||||
// List of communities modified
|
|
||||||
ModifiedInstallations *stringBoolMap
|
ModifiedInstallations *stringBoolMap
|
||||||
|
// List of installations targeted to this device modified
|
||||||
|
TargetedInstallations *stringBoolMap
|
||||||
// Map of existing messages
|
// Map of existing messages
|
||||||
ExistingMessagesMap map[string]bool
|
ExistingMessagesMap map[string]bool
|
||||||
// EmojiReactions is a list of emoji reactions for the current batch
|
// EmojiReactions is a list of emoji reactions for the current batch
|
||||||
@ -3322,6 +3323,7 @@ func (m *Messenger) buildMessageState() *ReceivedMessageState {
|
|||||||
ModifiedContacts: new(stringBoolMap),
|
ModifiedContacts: new(stringBoolMap),
|
||||||
AllInstallations: m.allInstallations,
|
AllInstallations: m.allInstallations,
|
||||||
ModifiedInstallations: m.modifiedInstallations,
|
ModifiedInstallations: m.modifiedInstallations,
|
||||||
|
TargetedInstallations: new(stringBoolMap),
|
||||||
ExistingMessagesMap: make(map[string]bool),
|
ExistingMessagesMap: make(map[string]bool),
|
||||||
EmojiReactions: make(map[string]*EmojiReaction),
|
EmojiReactions: make(map[string]*EmojiReaction),
|
||||||
GroupChatInvitations: make(map[string]*GroupChatInvitation),
|
GroupChatInvitations: make(map[string]*GroupChatInvitation),
|
||||||
@ -3735,6 +3737,8 @@ func (m *Messenger) saveDataAndPrepareResponse(messageState *ReceivedMessageStat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targeted, _ := messageState.TargetedInstallations.Load(id)
|
||||||
|
if targeted {
|
||||||
if installation.Enabled {
|
if installation.Enabled {
|
||||||
// Delete AC notif since the installation is now enabled
|
// Delete AC notif since the installation is now enabled
|
||||||
err = m.deleteNotification(messageState.Response, id)
|
err = m.deleteNotification(messageState.Response, id)
|
||||||
@ -3759,6 +3763,7 @@ func (m *Messenger) saveDataAndPrepareResponse(messageState *ReceivedMessageStat
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -81,7 +81,7 @@ func (s *MessengerDeleteMessageForMeSuite) Pair() {
|
|||||||
DeviceType: "alice2",
|
DeviceType: "alice2",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := s.alice2.SendPairInstallation(context.Background(), nil)
|
response, err := s.alice2.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -101,7 +101,7 @@ func (s *MessengerDeleteMessageForMeSuite) Pair() {
|
|||||||
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.alice1.EnableInstallation(s.alice2.installationID)
|
_, err = s.alice1.EnableInstallation(s.alice2.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,6 +1321,8 @@ func (m *Messenger) HandleSyncPairInstallation(state *ReceivedMessageState, mess
|
|||||||
// TODO(samyoul) remove storing of an updated reference pointer?
|
// TODO(samyoul) remove storing of an updated reference pointer?
|
||||||
state.AllInstallations.Store(message.InstallationId, installation)
|
state.AllInstallations.Store(message.InstallationId, installation)
|
||||||
state.ModifiedInstallations.Store(message.InstallationId, true)
|
state.ModifiedInstallations.Store(message.InstallationId, true)
|
||||||
|
targeted := message.TargetInstallationId == m.installationID
|
||||||
|
state.TargetedInstallations.Store(message.InstallationId, targeted)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func (s *MessengerProfileDisplayNameHandlerSuite) TestDisplayNameSync() {
|
|||||||
}
|
}
|
||||||
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
|
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -133,7 +133,7 @@ func (s *MessengerProfileDisplayNameHandlerSuite) TestDisplayNameSync() {
|
|||||||
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
_, err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Set new display name on alice's device
|
// Set new display name on alice's device
|
||||||
|
@ -43,7 +43,7 @@ func (s *MessengerInstallationSuite) TestReceiveInstallation() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -63,7 +63,7 @@ func (s *MessengerInstallationSuite) TestReceiveInstallation() {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
contactKey, err := crypto.GenerateKey()
|
contactKey, err := crypto.GenerateKey()
|
||||||
@ -242,7 +242,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallation() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err = theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err = theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -262,7 +262,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallation() {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
@ -366,7 +366,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallationNewMessages() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := bob2.SendPairInstallation(context.Background(), nil)
|
response, err := bob2.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -382,7 +382,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallationNewMessages() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
actualInstallation := response.Installations()[0]
|
actualInstallation := response.Installations()[0]
|
||||||
s.Require().Equal(bob2.installationID, actualInstallation.ID)
|
s.Require().Equal(bob2.installationID, actualInstallation.ID)
|
||||||
err = bob1.EnableInstallation(bob2.installationID)
|
_, err = bob1.EnableInstallation(bob2.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// send a message from bob1 to alice, it should be received on both bob1 and bob2
|
// send a message from bob1 to alice, it should be received on both bob1 and bob2
|
||||||
|
@ -17,42 +17,55 @@ import (
|
|||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type InstallationIDProvider interface {
|
||||||
|
GetInstallationID() string
|
||||||
|
Validate() error
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Messenger) EnableInstallationAndSync(request *requests.EnableInstallationAndSync) (*MessengerResponse, error) {
|
func (m *Messenger) EnableInstallationAndSync(request *requests.EnableInstallationAndSync) (*MessengerResponse, error) {
|
||||||
if err := request.Validate(); err != nil {
|
if err := request.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err := m.EnableInstallation(request.InstallationID)
|
|
||||||
if err != nil {
|
installation, err := m.EnableInstallation(request.InstallationID)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response, err := m.SendPairInstallation(context.Background(), nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = m.SyncDevices(context.Background(), "", "", nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete AC notif
|
response := &MessengerResponse{}
|
||||||
err = m.deleteNotification(response, request.InstallationID)
|
response.AddInstallation(installation)
|
||||||
|
|
||||||
|
pairResponse, err := m.SendPairInstallation(context.Background(), request.InstallationID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
if err = m.SyncDevices(context.Background(), "", "", nil); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = m.deleteNotification(pairResponse, request.InstallationID); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = pairResponse.Merge(response); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pairResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) EnableInstallationAndPair(request *requests.EnableInstallationAndPair) (*MessengerResponse, error) {
|
func (m *Messenger) EnableInstallationAndPair(request InstallationIDProvider) (*MessengerResponse, error) {
|
||||||
if err := request.Validate(); err != nil {
|
if err := request.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
myIdentity := crypto.CompressPubkey(&m.identity.PublicKey)
|
myIdentity := crypto.CompressPubkey(&m.identity.PublicKey)
|
||||||
timestamp := time.Now().UnixNano()
|
timestamp := time.Now().UnixNano()
|
||||||
|
installationID := request.GetInstallationID()
|
||||||
|
|
||||||
installation := &multidevice.Installation{
|
installation := &multidevice.Installation{
|
||||||
ID: request.InstallationID,
|
ID: installationID,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
@ -62,20 +75,20 @@ func (m *Messenger) EnableInstallationAndPair(request *requests.EnableInstallati
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
i, ok := m.allInstallations.Load(request.InstallationID)
|
i, ok := m.allInstallations.Load(installationID)
|
||||||
if !ok {
|
if !ok {
|
||||||
i = installation
|
i = installation
|
||||||
} else {
|
} else {
|
||||||
i.Enabled = true
|
i.Enabled = true
|
||||||
}
|
}
|
||||||
m.allInstallations.Store(request.InstallationID, i)
|
m.allInstallations.Store(installationID, i)
|
||||||
response, err := m.SendPairInstallation(context.Background(), nil)
|
response, err := m.SendPairInstallation(context.Background(), request.GetInstallationID(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
notification := &ActivityCenterNotification{
|
notification := &ActivityCenterNotification{
|
||||||
ID: types.FromHex(request.InstallationID),
|
ID: types.FromHex(installationID),
|
||||||
Type: ActivityCenterNotificationTypeNewInstallationCreated,
|
Type: ActivityCenterNotificationTypeNewInstallationCreated,
|
||||||
InstallationID: m.installationID, // Put our own installation ID, as we're the initiator of the pairing
|
InstallationID: m.installationID, // Put our own installation ID, as we're the initiator of the pairing
|
||||||
Timestamp: m.getTimesource().GetCurrentTime(),
|
Timestamp: m.getTimesource().GetCurrentTime(),
|
||||||
@ -92,7 +105,7 @@ func (m *Messenger) EnableInstallationAndPair(request *requests.EnableInstallati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendPairInstallation sends a pair installation message
|
// SendPairInstallation sends a pair installation message
|
||||||
func (m *Messenger) SendPairInstallation(ctx context.Context, rawMessageHandler RawMessageHandler) (*MessengerResponse, error) {
|
func (m *Messenger) SendPairInstallation(ctx context.Context, targetInstallationID string, rawMessageHandler RawMessageHandler) (*MessengerResponse, error) {
|
||||||
var err error
|
var err error
|
||||||
var response MessengerResponse
|
var response MessengerResponse
|
||||||
|
|
||||||
@ -112,7 +125,9 @@ func (m *Messenger) SendPairInstallation(ctx context.Context, rawMessageHandler
|
|||||||
Name: installation.InstallationMetadata.Name,
|
Name: installation.InstallationMetadata.Name,
|
||||||
InstallationId: installation.ID,
|
InstallationId: installation.ID,
|
||||||
DeviceType: installation.InstallationMetadata.DeviceType,
|
DeviceType: installation.InstallationMetadata.DeviceType,
|
||||||
Version: installation.Version}
|
Version: installation.Version,
|
||||||
|
TargetInstallationId: targetInstallationID,
|
||||||
|
}
|
||||||
encodedMessage, err := proto.Marshal(pairMessage)
|
encodedMessage, err := proto.Marshal(pairMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -496,20 +511,21 @@ func (m *Messenger) SetInstallationName(id string, name string) error {
|
|||||||
return m.encryptor.SetInstallationName(m.IdentityPublicKey(), id, name)
|
return m.encryptor.SetInstallationName(m.IdentityPublicKey(), id, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) EnableInstallation(id string) error {
|
// EnableInstallation enables an installation and returns the installation
|
||||||
|
func (m *Messenger) EnableInstallation(id string) (*multidevice.Installation, error) {
|
||||||
installation, ok := m.allInstallations.Load(id)
|
installation, ok := m.allInstallations.Load(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("no installation found")
|
return nil, errors.New("no installation found")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := m.encryptor.EnableInstallation(&m.identity.PublicKey, id)
|
err := m.encryptor.EnableInstallation(&m.identity.PublicKey, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
installation.Enabled = true
|
installation.Enabled = true
|
||||||
// TODO(samyoul) remove storing of an updated reference pointer?
|
// TODO(samyoul) remove storing of an updated reference pointer?
|
||||||
m.allInstallations.Store(id, installation)
|
m.allInstallations.Store(id, installation)
|
||||||
return nil
|
return installation, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) DisableInstallation(id string) error {
|
func (m *Messenger) DisableInstallation(id string) error {
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||||
"github.com/status-im/status-go/multiaccounts/settings"
|
"github.com/status-im/status-go/multiaccounts/settings"
|
||||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||||
@ -58,12 +59,127 @@ func (s *MessengerPairingSuite) TestEnableNonExistingInstallation() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestMessengerPairAfterSeedPhrase tests the scenario where alice2 wants to sync with alice1
|
type stubEnableInstallationAndPair struct {
|
||||||
|
installationID string
|
||||||
|
getInstallationIDInvokedFirst bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *stubEnableInstallationAndPair) GetInstallationID() string {
|
||||||
|
if !m.getInstallationIDInvokedFirst {
|
||||||
|
m.getInstallationIDInvokedFirst = true
|
||||||
|
return m.installationID
|
||||||
|
}
|
||||||
|
return "wrong installation ID"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *stubEnableInstallationAndPair) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestNewInstallationReceivedIsNotCreated tests the scenario where alice2 wants to pair with alice1
|
||||||
|
// but the target installation ID is wrong so no AC notification(ActivityCenterNotificationTypeNewInstallationReceived)
|
||||||
|
// should be created for alice1
|
||||||
|
func (s *MessengerPairingSuite) TestNewInstallationReceivedIsNotCreated() {
|
||||||
|
alice1 := s.m
|
||||||
|
alice2, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
defer TearDownMessenger(&s.Suite, alice2)
|
||||||
|
|
||||||
|
mockRequest := &stubEnableInstallationAndPair{installationID: alice1.installationID}
|
||||||
|
_, err = alice2.EnableInstallationAndPair(mockRequest)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
resp, err := WaitOnMessengerResponse(
|
||||||
|
alice1,
|
||||||
|
func(r *MessengerResponse) bool {
|
||||||
|
for _, i := range r.Installations() {
|
||||||
|
if i.ID == alice2.installationID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
"no messages",
|
||||||
|
)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(resp.ActivityCenterNotifications(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestNewInstallationCreatedIsNotDeleted tests the scenario
|
||||||
|
// 1. prepare AC NewInstallationCreated for alice2
|
||||||
|
// 2. prepare AC NewInstallationCreated for alice3
|
||||||
|
// 3. alice1.EnableInstallationAndSync
|
||||||
|
// 4. check AC NewInstallationCreated for alice3 is not deleted
|
||||||
|
func (s *MessengerPairingSuite) TestNewInstallationCreatedIsNotDeleted() {
|
||||||
|
alice1 := s.m
|
||||||
|
alice2, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
alice3, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
defer TearDownMessenger(&s.Suite, alice2)
|
||||||
|
defer TearDownMessenger(&s.Suite, alice3)
|
||||||
|
|
||||||
|
// prepare AC NewInstallationCreated for alice2
|
||||||
|
_, err = alice2.EnableInstallationAndPair(&requests.EnableInstallationAndPair{InstallationID: alice1.installationID})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// alice1 should get the installationID2 from alice2
|
||||||
|
s.expectInstallationReceived(alice1, alice2.installationID)
|
||||||
|
|
||||||
|
// prepare AC NewInstallationCreated for alice3
|
||||||
|
_, err = alice3.EnableInstallationAndPair(&requests.EnableInstallationAndPair{InstallationID: alice1.installationID})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// alice1 should get the installationID3 from alice3
|
||||||
|
s.expectInstallationReceived(alice1, alice3.installationID)
|
||||||
|
|
||||||
|
_, err = alice1.EnableInstallationAndSync(&requests.EnableInstallationAndSync{InstallationID: alice2.installationID})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
_, err = WaitOnMessengerResponse(
|
||||||
|
alice3,
|
||||||
|
func(r *MessengerResponse) bool {
|
||||||
|
for _, i := range r.Installations() {
|
||||||
|
if i.ID == alice1.installationID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
"alice3 should get the installationID from alice1",
|
||||||
|
)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
ac, err := alice3.ActivityCenterNotification(types.FromHex(alice1.installationID))
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(ActivityCenterNotificationTypeNewInstallationCreated, ac.Type)
|
||||||
|
s.Require().False(ac.Deleted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MessengerPairingSuite) expectInstallationReceived(m *Messenger, installationID string) {
|
||||||
|
resp, err := WaitOnMessengerResponse(
|
||||||
|
m,
|
||||||
|
func(r *MessengerResponse) bool {
|
||||||
|
for _, i := range r.Installations() {
|
||||||
|
if i.ID == installationID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
"installation not received",
|
||||||
|
)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(resp.ActivityCenterNotifications(), 1)
|
||||||
|
s.Require().Equal(ActivityCenterNotificationTypeNewInstallationReceived, resp.ActivityCenterNotifications()[0].Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestMessengerSyncFallback tests the scenario where alice2 wants to sync with alice1
|
||||||
// alice1 generated the connection string for bootstraping alice2
|
// alice1 generated the connection string for bootstraping alice2
|
||||||
// alice2 failed to connect to alice1 and restored from seed phrase
|
// alice2 failed to connect to alice1 and restored from seed phrase
|
||||||
// alice2 get the installationID1 from alice1 via parsing the connection string
|
// alice2 get the installationID1 from alice1 via parsing the connection string
|
||||||
// alice2 should get the display name from alice1 after pairing
|
// alice2 should get the display name from alice1 after pairing
|
||||||
func (s *MessengerPairingSuite) TestMessengerPairAfterSeedPhrase() {
|
func (s *MessengerPairingSuite) TestMessengerSyncFallback() {
|
||||||
alice1 := s.m
|
alice1 := s.m
|
||||||
alice2, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
|
alice2, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
@ -87,23 +203,20 @@ func (s *MessengerPairingSuite) TestMessengerPairAfterSeedPhrase() {
|
|||||||
_, err = alice2.EnableInstallationAndPair(&requests.EnableInstallationAndPair{InstallationID: installationID1})
|
_, err = alice2.EnableInstallationAndPair(&requests.EnableInstallationAndPair{InstallationID: installationID1})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// alice1 should get the installationID1 from alice2
|
// alice1 should get the installationID2 from alice2
|
||||||
_, err = WaitOnMessengerResponse(
|
s.expectInstallationReceived(alice1, installationID2)
|
||||||
alice1,
|
|
||||||
func(r *MessengerResponse) bool {
|
|
||||||
for _, i := range r.Installations() {
|
|
||||||
if i.ID == installationID2 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
"no messages",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
_, err = alice1.EnableInstallationAndSync(&requests.EnableInstallationAndSync{InstallationID: installationID2})
|
// check response from alice1
|
||||||
|
resp, err := alice1.EnableInstallationAndSync(&requests.EnableInstallationAndSync{InstallationID: installationID2})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
installationID2Exist := false
|
||||||
|
for _, i := range resp.Installations() {
|
||||||
|
if i.ID == installationID2 {
|
||||||
|
installationID2Exist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Require().True(installationID2Exist)
|
||||||
|
|
||||||
// check if the display name is synced
|
// check if the display name is synced
|
||||||
err = tt.RetryWithBackOff(func() error {
|
err = tt.RetryWithBackOff(func() error {
|
||||||
|
@ -40,7 +40,7 @@ func (s *MessengerSyncBookmarkSuite) TestSyncBookmark() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -60,7 +60,7 @@ func (s *MessengerSyncBookmarkSuite) TestSyncBookmark() {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
|
@ -82,7 +82,7 @@ func (s *MessengerSyncChatSuite) Pair() {
|
|||||||
DeviceType: "alice2",
|
DeviceType: "alice2",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := s.alice2.SendPairInstallation(context.Background(), nil)
|
response, err := s.alice2.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -102,7 +102,7 @@ func (s *MessengerSyncChatSuite) Pair() {
|
|||||||
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("alice2", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.alice1.EnableInstallation(s.alice2.installationID)
|
_, err = s.alice1.EnableInstallation(s.alice2.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func (s *MessengerSyncClearHistory) pair() *Messenger {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ func (s *MessengerSyncClearHistory) pair() *Messenger {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
return theirMessenger
|
return theirMessenger
|
||||||
|
@ -58,7 +58,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := s.other.SendPairInstallation(context.Background(), nil)
|
response, err := s.other.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
|
|||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = s.main.EnableInstallation(s.other.installationID)
|
_, err = s.main.EnableInstallation(s.other.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
||||||
|
@ -58,7 +58,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := s.other.SendPairInstallation(context.Background(), nil)
|
response, err := s.other.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
|
|||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = s.main.EnableInstallation(s.other.installationID)
|
_, err = s.main.EnableInstallation(s.other.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
||||||
|
@ -35,7 +35,7 @@ func (s *MessengerSyncProfilePictureSuite) TestSyncProfilePicture() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -55,7 +55,7 @@ func (s *MessengerSyncProfilePictureSuite) TestSyncProfilePicture() {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Sync happens via subscription triggered from within StoreIdentityImages
|
// Sync happens via subscription triggered from within StoreIdentityImages
|
||||||
|
@ -312,7 +312,7 @@ func (m *Messenger) HandleSyncRawMessages(rawMessages []*protobuf.RawMessage) er
|
|||||||
}
|
}
|
||||||
// if receiver already logged in before local pairing, we need force enable the installation,
|
// if receiver already logged in before local pairing, we need force enable the installation,
|
||||||
// AddInstallations won't make sure enable it, e.g. installation maybe already exist in db but not enabled yet
|
// AddInstallations won't make sure enable it, e.g. installation maybe already exist in db but not enabled yet
|
||||||
err = m.EnableInstallation(message.InstallationId)
|
_, err = m.EnableInstallation(message.InstallationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (s *MessengerSyncSavedAddressesSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := s.other.SendPairInstallation(context.Background(), nil)
|
response, err := s.other.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func (s *MessengerSyncSavedAddressesSuite) SetupTest() {
|
|||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = s.main.EnableInstallation(s.other.installationID)
|
_, err = s.main.EnableInstallation(s.other.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func (s *MessengerSyncVerificationRequests) TestSyncVerificationRequests() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -63,7 +63,7 @@ func (s *MessengerSyncVerificationRequests) TestSyncVerificationRequests() {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
@ -107,7 +107,7 @@ func (s *MessengerSyncVerificationRequests) TestSyncTrust() {
|
|||||||
DeviceType: "their-device-type",
|
DeviceType: "their-device-type",
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -127,7 +127,7 @@ func (s *MessengerSyncVerificationRequests) TestSyncTrust() {
|
|||||||
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(theirMessenger.installationID)
|
_, err = s.m.EnableInstallation(theirMessenger.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
|
@ -101,7 +101,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
|
|||||||
}
|
}
|
||||||
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
|
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -121,7 +121,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
|
|||||||
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
_, err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Store seed phrase keypair with accounts on alice's device
|
// Store seed phrase keypair with accounts on alice's device
|
||||||
@ -321,7 +321,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
|
|||||||
}
|
}
|
||||||
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
|
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -341,7 +341,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
|
|||||||
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
_, err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Move down account from position 1 to position 4
|
// Move down account from position 1 to position 4
|
||||||
@ -511,7 +511,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
|
|||||||
}
|
}
|
||||||
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
|
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -531,7 +531,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
|
|||||||
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
s.Require().Equal("alice's-other-device", actualInstallation.InstallationMetadata.Name)
|
||||||
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
s.Require().Equal("alice's-other-device-type", actualInstallation.InstallationMetadata.DeviceType)
|
||||||
|
|
||||||
err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
_, err = s.m.EnableInstallation(alicesOtherDevice.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Trigger's a sync between devices
|
// Trigger's a sync between devices
|
||||||
|
@ -277,7 +277,7 @@ func FindFirstByContentType(messages []*common.Message, contentType protobuf.Cha
|
|||||||
|
|
||||||
func PairDevices(s *suite.Suite, device1, device2 *Messenger) {
|
func PairDevices(s *suite.Suite, device1, device2 *Messenger) {
|
||||||
// Send pairing data
|
// Send pairing data
|
||||||
response, err := device1.SendPairInstallation(context.Background(), nil)
|
response, err := device1.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Len(response.Chats(), 1)
|
s.Len(response.Chats(), 1)
|
||||||
@ -306,7 +306,7 @@ func PairDevices(s *suite.Suite, device1, device2 *Messenger) {
|
|||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
|
|
||||||
// Ensure installation is enabled
|
// Ensure installation is enabled
|
||||||
err = device2.EnableInstallation(device1.installationID)
|
_, err = device2.EnableInstallation(device1.installationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +91,9 @@ message SyncPairInstallation {
|
|||||||
string installation_id = 2;
|
string installation_id = 2;
|
||||||
string device_type = 3;
|
string device_type = 3;
|
||||||
string name = 4;
|
string name = 4;
|
||||||
// following fields used for local pairing
|
// used for local pairing
|
||||||
uint32 version = 5;
|
uint32 version = 5;
|
||||||
|
string target_installation_id = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SyncInstallationContactV2 {
|
message SyncInstallationContactV2 {
|
||||||
|
@ -17,3 +17,7 @@ func (j *EnableInstallationAndPair) Validate() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *EnableInstallationAndPair) GetInstallationID() string {
|
||||||
|
return j.InstallationID
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ func (s *SyncRawMessageHandler) CollectInstallationData(rawMessageCollector *Raw
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = messenger.SendPairInstallation(context.TODO(), rawMessageCollector.dispatchMessage)
|
_, err = messenger.SendPairInstallation(context.TODO(), "", rawMessageCollector.dispatchMessage)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -907,7 +907,7 @@ func (s *SyncDeviceSuite) TestTransferringKeystoreFilesAfterStopUisngKeycard() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
err = clientMessenger.SetInstallationMetadata(settings.InstallationID, im1)
|
err = clientMessenger.SetInstallationMetadata(settings.InstallationID, im1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
response, err := clientMessenger.SendPairInstallation(context.Background(), nil)
|
response, err := clientMessenger.SendPairInstallation(context.Background(), "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(response)
|
s.Require().NotNil(response)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
@ -940,7 +940,7 @@ func (s *SyncDeviceSuite) TestTransferringKeystoreFilesAfterStopUisngKeycard() {
|
|||||||
}
|
}
|
||||||
s.Require().True(found)
|
s.Require().True(found)
|
||||||
|
|
||||||
err = serverMessenger.EnableInstallation(settings.InstallationID)
|
_, err = serverMessenger.EnableInstallation(settings.InstallationID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Check if the logged in account is the same on server and client
|
// Check if the logged in account is the same on server and client
|
||||||
|
@ -373,7 +373,8 @@ func (api *PublicAPI) RemoveFilters(parent context.Context, chats []*transport.F
|
|||||||
|
|
||||||
// EnableInstallation enables an installation for multi-device sync.
|
// EnableInstallation enables an installation for multi-device sync.
|
||||||
func (api *PublicAPI) EnableInstallation(installationID string) error {
|
func (api *PublicAPI) EnableInstallation(installationID string) error {
|
||||||
return api.service.messenger.EnableInstallation(installationID)
|
_, err := api.service.messenger.EnableInstallation(installationID)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableInstallation disables an installation for multi-device sync.
|
// DisableInstallation disables an installation for multi-device sync.
|
||||||
@ -1056,7 +1057,7 @@ func (api *PublicAPI) VerifiedUntrustworthy(ctx context.Context, request *reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) SendPairInstallation(ctx context.Context) (*protocol.MessengerResponse, error) {
|
func (api *PublicAPI) SendPairInstallation(ctx context.Context) (*protocol.MessengerResponse, error) {
|
||||||
return api.service.messenger.SendPairInstallation(ctx, nil)
|
return api.service.messenger.SendPairInstallation(ctx, "", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) SyncDevices(ctx context.Context, name, picture string) error {
|
func (api *PublicAPI) SyncDevices(ctx context.Context, name, picture string) error {
|
||||||
|
@ -332,7 +332,8 @@ func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) EnableInstallation(installationID string) error {
|
func (s *Service) EnableInstallation(installationID string) error {
|
||||||
return s.messenger.EnableInstallation(installationID)
|
_, err := s.messenger.EnableInstallation(installationID)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableInstallation disables an installation for multi-device sync.
|
// DisableInstallation disables an installation for multi-device sync.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user