Refactor repeated use of the UserCapabilities constructor

This commit is contained in:
Ehren Kret 2021-05-13 12:08:59 -05:00
parent bfd2c32d4e
commit 57ff9f86f5
2 changed files with 12 additions and 15 deletions

View File

@ -231,10 +231,6 @@ public class ProfileController {
Optional<ProfileKeyCredentialResponse> credential = getProfileCredential(credentialRequest, profile, uuid);
final UserCapabilities userCapabilities = new UserCapabilities(
accountProfile.get().isGroupsV2Supported(),
accountProfile.get().isGv1MigrationSupported(),
accountProfile.get().isSenderKeySupported());
return Optional.of(new Profile(name,
about,
aboutEmoji,
@ -243,7 +239,7 @@ public class ProfileController {
accountProfile.get().getIdentityKey(),
UnidentifiedAccessChecksum.generateFor(accountProfile.get().getUnidentifiedAccessKey()),
accountProfile.get().isUnrestrictedUnidentifiedAccess(),
userCapabilities,
UserCapabilities.createForAccount(accountProfile.get()),
username.orElse(null),
null,
credential.orElse(null)));
@ -275,10 +271,6 @@ public class ProfileController {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
final UserCapabilities userCapabilities = new UserCapabilities(
accountProfile.get().isGroupsV2Supported(),
accountProfile.get().isGv1MigrationSupported(),
accountProfile.get().isSenderKeySupported());
return new Profile(accountProfile.get().getProfileName(),
null,
null,
@ -287,7 +279,7 @@ public class ProfileController {
accountProfile.get().getIdentityKey(),
UnidentifiedAccessChecksum.generateFor(accountProfile.get().getUnidentifiedAccessKey()),
accountProfile.get().isUnrestrictedUnidentifiedAccess(),
userCapabilities,
UserCapabilities.createForAccount(accountProfile.get()),
username,
accountProfile.get().getUuid(),
null);
@ -354,10 +346,6 @@ public class ProfileController {
username = usernamesManager.get(accountProfile.get().getUuid());
}
final UserCapabilities userCapabilities = new UserCapabilities(
accountProfile.get().isGroupsV2Supported(),
accountProfile.get().isGv1MigrationSupported(),
accountProfile.get().isSenderKeySupported());
return new Profile(accountProfile.get().getProfileName(),
null,
null,
@ -366,7 +354,7 @@ public class ProfileController {
accountProfile.get().getIdentityKey(),
UnidentifiedAccessChecksum.generateFor(accountProfile.get().getUnidentifiedAccessKey()),
accountProfile.get().isUnrestrictedUnidentifiedAccess(),
userCapabilities,
UserCapabilities.createForAccount(accountProfile.get()),
username.orElse(null),
null,
null);

View File

@ -6,8 +6,17 @@
package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.textsecuregcm.storage.Account;
public class UserCapabilities {
public static UserCapabilities createForAccount(Account account) {
return new UserCapabilities(
account.isGroupsV2Supported(),
account.isGv1MigrationSupported(),
account.isSenderKeySupported());
}
@JsonProperty
private boolean gv2;