fix(sync): Update SendPairInstallation method signature and calls

- 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
This commit is contained in:
frank 2024-09-26 12:39:40 +08:00
parent 5bfb6df876
commit 8a52a95339
19 changed files with 593 additions and 577 deletions

View File

@ -81,7 +81,7 @@ func (s *MessengerDeleteMessageForMeSuite) Pair() {
DeviceType: "alice2",
})
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().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -113,7 +113,7 @@ func (s *MessengerProfileDisplayNameHandlerSuite) TestDisplayNameSync() {
}
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
s.Require().NoError(err)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -43,7 +43,7 @@ func (s *MessengerInstallationSuite) TestReceiveInstallation() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)
@ -242,7 +242,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallation() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err = theirMessenger.SendPairInstallation(context.Background(), nil)
response, err = theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)
@ -366,7 +366,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallationNewMessages() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := bob2.SendPairInstallation(context.Background(), nil)
response, err := bob2.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -25,7 +25,8 @@ func (m *Messenger) EnableInstallationAndSync(request *requests.EnableInstallati
if err != nil {
return nil, err
}
response, err := m.SendPairInstallation(context.Background(), nil)
response, err := m.SendPairInstallation(context.Background(), request.InstallationID, nil)
if err != nil {
return nil, err
}
@ -69,7 +70,7 @@ func (m *Messenger) EnableInstallationAndPair(request *requests.EnableInstallati
i.Enabled = true
}
m.allInstallations.Store(request.InstallationID, i)
response, err := m.SendPairInstallation(context.Background(), nil)
response, err := m.SendPairInstallation(context.Background(), request.InstallationID, nil)
if err != nil {
return nil, err
}
@ -92,7 +93,7 @@ func (m *Messenger) EnableInstallationAndPair(request *requests.EnableInstallati
}
// 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 response MessengerResponse
@ -112,7 +113,9 @@ func (m *Messenger) SendPairInstallation(ctx context.Context, rawMessageHandler
Name: installation.InstallationMetadata.Name,
InstallationId: installation.ID,
DeviceType: installation.InstallationMetadata.DeviceType,
Version: installation.Version}
Version: installation.Version,
TargetInstallationId: targetInstallationID,
}
encodedMessage, err := proto.Marshal(pairMessage)
if err != nil {
return nil, err

View File

@ -40,7 +40,7 @@ func (s *MessengerSyncBookmarkSuite) TestSyncBookmark() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -82,7 +82,7 @@ func (s *MessengerSyncChatSuite) Pair() {
DeviceType: "alice2",
})
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().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -31,7 +31,7 @@ func (s *MessengerSyncClearHistory) pair() *Messenger {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)

View File

@ -58,7 +58,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
}
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
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().NotNil(response)

View File

@ -58,7 +58,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
}
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
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().NotNil(response)

View File

@ -35,7 +35,7 @@ func (s *MessengerSyncProfilePictureSuite) TestSyncProfilePicture() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -62,7 +62,7 @@ func (s *MessengerSyncSavedAddressesSuite) SetupTest() {
}
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
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().NotNil(response)

View File

@ -43,7 +43,7 @@ func (s *MessengerSyncVerificationRequests) TestSyncVerificationRequests() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)
@ -107,7 +107,7 @@ func (s *MessengerSyncVerificationRequests) TestSyncTrust() {
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
response, err := theirMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -101,7 +101,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
}
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
s.Require().NoError(err)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)
@ -321,7 +321,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
}
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
s.Require().NoError(err)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)
@ -511,7 +511,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
}
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
s.Require().NoError(err)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), nil)
response, err := alicesOtherDevice.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -276,7 +276,7 @@ func FindFirstByContentType(messages []*common.Message, contentType protobuf.Cha
func PairDevices(s *suite.Suite, device1, device2 *Messenger) {
// Send pairing data
response, err := device1.SendPairInstallation(context.Background(), nil)
response, err := device1.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Len(response.Chats(), 1)

File diff suppressed because it is too large Load Diff

View File

@ -91,8 +91,9 @@ message SyncPairInstallation {
string installation_id = 2;
string device_type = 3;
string name = 4;
// following fields used for local pairing
// used for local pairing
uint32 version = 5;
string target_installation_id = 6;
}
message SyncInstallationContactV2 {

View File

@ -36,7 +36,7 @@ func (s *SyncRawMessageHandler) CollectInstallationData(rawMessageCollector *Raw
if err != nil {
return err
}
_, err = messenger.SendPairInstallation(context.TODO(), rawMessageCollector.dispatchMessage)
_, err = messenger.SendPairInstallation(context.TODO(), "", rawMessageCollector.dispatchMessage)
return err
}

View File

@ -907,7 +907,7 @@ func (s *SyncDeviceSuite) TestTransferringKeystoreFilesAfterStopUisngKeycard() {
s.Require().NoError(err)
err = clientMessenger.SetInstallationMetadata(settings.InstallationID, im1)
s.Require().NoError(err)
response, err := clientMessenger.SendPairInstallation(context.Background(), nil)
response, err := clientMessenger.SendPairInstallation(context.Background(), "", nil)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Len(response.Chats(), 1)

View File

@ -1056,7 +1056,7 @@ func (api *PublicAPI) VerifiedUntrustworthy(ctx context.Context, request *reques
}
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 {