Group atomic account creation operations

This commit is contained in:
Jon Chambers 2023-05-19 12:30:31 -04:00 committed by Jon Chambers
parent c9a9409b9a
commit fa8f19fd43
2 changed files with 8 additions and 17 deletions

View File

@ -158,9 +158,9 @@ public class RegistrationController {
account = accounts.update(account, a -> {
a.setIdentityKey(registrationRequest.aciIdentityKey().get());
a.setPhoneNumberIdentityKey(registrationRequest.pniIdentityKey().get());
});
account = accounts.updateDevice(account, Device.MASTER_ID, device -> {
final Device device = a.getMasterDevice().orElseThrow();
device.setSignedPreKey(registrationRequest.aciSignedPreKey().get());
device.setPhoneNumberIdentitySignedPreKey(registrationRequest.pniSignedPreKey().get());
@ -171,10 +171,10 @@ public class RegistrationController {
registrationRequest.gcmToken().ifPresent(gcmRegistrationId ->
device.setGcmId(gcmRegistrationId.gcmRegistrationId()));
});
keys.storePqLastResort(account.getUuid(), Map.of(Device.MASTER_ID, registrationRequest.aciPqLastResortPreKey().get()));
keys.storePqLastResort(account.getPhoneNumberIdentifier(), Map.of(Device.MASTER_ID, registrationRequest.pniPqLastResortPreKey().get()));
keys.storePqLastResort(a.getUuid(), Map.of(Device.MASTER_ID, registrationRequest.aciPqLastResortPreKey().get()));
keys.storePqLastResort(a.getPhoneNumberIdentifier(), Map.of(Device.MASTER_ID, registrationRequest.pniPqLastResortPreKey().get()));
});
}
Metrics.counter(ACCOUNT_CREATED_COUNTER_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),

View File

@ -588,16 +588,15 @@ class RegistrationControllerTest {
final UUID accountIdentifier = UUID.randomUUID();
final UUID phoneNumberIdentifier = UUID.randomUUID();
final Device device = mock(Device.class);
final Account account = MockUtils.buildMock(Account.class, a -> {
when(a.getUuid()).thenReturn(accountIdentifier);
when(a.getPhoneNumberIdentifier()).thenReturn(phoneNumberIdentifier);
when(a.getMasterDevice()).thenReturn(Optional.of(device));
});
final Device device = mock(Device.class);
when(accountsManager.create(any(), any(), any(), any(), any()))
.thenReturn(account);
when(accountsManager.create(any(), any(), any(), any(), any())).thenReturn(account);
when(accountsManager.update(eq(account), any())).thenAnswer(invocation -> {
final Consumer<Account> accountUpdater = invocation.getArgument(1);
@ -606,13 +605,6 @@ class RegistrationControllerTest {
return invocation.getArgument(0);
});
when(accountsManager.updateDevice(eq(account), eq(Device.MASTER_ID), any())).thenAnswer(invocation -> {
final Consumer<Device> deviceUpdater = invocation.getArgument(2);
deviceUpdater.accept(device);
return invocation.getArgument(0);
});
final Invocation.Builder request = resources.getJerseyTest()
.target("/v1/registration")
.request()
@ -623,7 +615,6 @@ class RegistrationControllerTest {
}
verify(accountsManager).create(any(), any(), any(), any(), any());
verify(accountsManager).updateDevice(eq(account), eq(Device.MASTER_ID), any());
verify(account).setIdentityKey(expectedAciIdentityKey);
verify(account).setPhoneNumberIdentityKey(expectedPniIdentityKey);