mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use pattern matching switch cases
This commit is contained in:
parent
80c1a6d2af
commit
8d55dfb66b
27 changed files with 395 additions and 380 deletions
|
@ -224,52 +224,55 @@ public class GroupHelper {
|
|||
var group = getGroupForUpdating(groupId);
|
||||
final var avatarBytes = readAvatarBytes(avatarFile);
|
||||
|
||||
if (group instanceof GroupInfoV2) {
|
||||
try {
|
||||
return updateGroupV2((GroupInfoV2) group,
|
||||
name,
|
||||
description,
|
||||
members,
|
||||
removeMembers,
|
||||
admins,
|
||||
removeAdmins,
|
||||
banMembers,
|
||||
unbanMembers,
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
addMemberPermission,
|
||||
editDetailsPermission,
|
||||
avatarBytes,
|
||||
expirationTimer,
|
||||
isAnnouncementGroup);
|
||||
} catch (ConflictException e) {
|
||||
// Detected conflicting update, refreshing group and trying again
|
||||
group = getGroup(groupId, true);
|
||||
return updateGroupV2((GroupInfoV2) group,
|
||||
name,
|
||||
description,
|
||||
members,
|
||||
removeMembers,
|
||||
admins,
|
||||
removeAdmins,
|
||||
banMembers,
|
||||
unbanMembers,
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
addMemberPermission,
|
||||
editDetailsPermission,
|
||||
avatarBytes,
|
||||
expirationTimer,
|
||||
isAnnouncementGroup);
|
||||
switch (group) {
|
||||
case GroupInfoV2 gv2 -> {
|
||||
try {
|
||||
return updateGroupV2(gv2,
|
||||
name,
|
||||
description,
|
||||
members,
|
||||
removeMembers,
|
||||
admins,
|
||||
removeAdmins,
|
||||
banMembers,
|
||||
unbanMembers,
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
addMemberPermission,
|
||||
editDetailsPermission,
|
||||
avatarBytes,
|
||||
expirationTimer,
|
||||
isAnnouncementGroup);
|
||||
} catch (ConflictException e) {
|
||||
// Detected conflicting update, refreshing group and trying again
|
||||
group = getGroup(groupId, true);
|
||||
return updateGroupV2((GroupInfoV2) group,
|
||||
name,
|
||||
description,
|
||||
members,
|
||||
removeMembers,
|
||||
admins,
|
||||
removeAdmins,
|
||||
banMembers,
|
||||
unbanMembers,
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
addMemberPermission,
|
||||
editDetailsPermission,
|
||||
avatarBytes,
|
||||
expirationTimer,
|
||||
isAnnouncementGroup);
|
||||
}
|
||||
}
|
||||
|
||||
case GroupInfoV1 gv1 -> {
|
||||
final var result = updateGroupV1(gv1, name, members, avatarBytes);
|
||||
if (expirationTimer != null) {
|
||||
setExpirationTimer(gv1, expirationTimer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final var gv1 = (GroupInfoV1) group;
|
||||
final var result = updateGroupV1(gv1, name, members, avatarBytes);
|
||||
if (expirationTimer != null) {
|
||||
setExpirationTimer(gv1, expirationTimer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateGroupProfileKey(GroupIdV2 groupId) throws GroupNotFoundException, NotAGroupMemberException, IOException {
|
||||
|
|
|
@ -25,19 +25,19 @@ public class PinHelper {
|
|||
String pin, MasterKey masterKey
|
||||
) throws IOException {
|
||||
final var backupResponse = secureValueRecoveryV2.setPin(pin, masterKey).execute();
|
||||
if (backupResponse instanceof SecureValueRecovery.BackupResponse.Success) {
|
||||
} else if (backupResponse instanceof SecureValueRecovery.BackupResponse.ServerRejected) {
|
||||
logger.warn("Backup svr2 failed: ServerRejected");
|
||||
} else if (backupResponse instanceof SecureValueRecovery.BackupResponse.EnclaveNotFound) {
|
||||
logger.warn("Backup svr2 failed: EnclaveNotFound");
|
||||
} else if (backupResponse instanceof SecureValueRecovery.BackupResponse.ExposeFailure) {
|
||||
logger.warn("Backup svr2 failed: ExposeFailure");
|
||||
} else if (backupResponse instanceof SecureValueRecovery.BackupResponse.ApplicationError error) {
|
||||
throw new IOException(error.getException());
|
||||
} else if (backupResponse instanceof SecureValueRecovery.BackupResponse.NetworkError error) {
|
||||
throw error.getException();
|
||||
} else {
|
||||
throw new AssertionError("Unexpected response");
|
||||
switch (backupResponse) {
|
||||
case SecureValueRecovery.BackupResponse.Success success -> {
|
||||
}
|
||||
case SecureValueRecovery.BackupResponse.ServerRejected serverRejected ->
|
||||
logger.warn("Backup svr2 failed: ServerRejected");
|
||||
case SecureValueRecovery.BackupResponse.EnclaveNotFound enclaveNotFound ->
|
||||
logger.warn("Backup svr2 failed: EnclaveNotFound");
|
||||
case SecureValueRecovery.BackupResponse.ExposeFailure exposeFailure ->
|
||||
logger.warn("Backup svr2 failed: ExposeFailure");
|
||||
case SecureValueRecovery.BackupResponse.ApplicationError error ->
|
||||
throw new IOException(error.getException());
|
||||
case SecureValueRecovery.BackupResponse.NetworkError error -> throw error.getException();
|
||||
case null, default -> throw new AssertionError("Unexpected response");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,17 +47,17 @@ public class PinHelper {
|
|||
|
||||
public void removeRegistrationLockPin() throws IOException {
|
||||
final var deleteResponse = secureValueRecoveryV2.deleteData();
|
||||
if (deleteResponse instanceof SecureValueRecovery.DeleteResponse.Success) {
|
||||
} else if (deleteResponse instanceof SecureValueRecovery.DeleteResponse.ServerRejected) {
|
||||
logger.warn("Delete svr2 failed: ServerRejected");
|
||||
} else if (deleteResponse instanceof SecureValueRecovery.DeleteResponse.EnclaveNotFound) {
|
||||
logger.warn("Delete svr2 failed: EnclaveNotFound");
|
||||
} else if (deleteResponse instanceof SecureValueRecovery.DeleteResponse.ApplicationError error) {
|
||||
throw new IOException(error.getException());
|
||||
} else if (deleteResponse instanceof SecureValueRecovery.DeleteResponse.NetworkError error) {
|
||||
throw error.getException();
|
||||
} else {
|
||||
throw new AssertionError("Unexpected response");
|
||||
switch (deleteResponse) {
|
||||
case SecureValueRecovery.DeleteResponse.Success success -> {
|
||||
}
|
||||
case SecureValueRecovery.DeleteResponse.ServerRejected serverRejected ->
|
||||
logger.warn("Delete svr2 failed: ServerRejected");
|
||||
case SecureValueRecovery.DeleteResponse.EnclaveNotFound enclaveNotFound ->
|
||||
logger.warn("Delete svr2 failed: EnclaveNotFound");
|
||||
case SecureValueRecovery.DeleteResponse.ApplicationError error ->
|
||||
throw new IOException(error.getException());
|
||||
case SecureValueRecovery.DeleteResponse.NetworkError error -> throw error.getException();
|
||||
case null, default -> throw new AssertionError("Unexpected response");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,19 +77,21 @@ public class PinHelper {
|
|||
) throws IOException, IncorrectPinException {
|
||||
final var restoreResponse = secureValueRecovery.restoreDataPreRegistration(authCredentials, pin);
|
||||
|
||||
if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.Success s) {
|
||||
return s;
|
||||
} else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.PinMismatch pinMismatch) {
|
||||
throw new IncorrectPinException(pinMismatch.getTriesRemaining());
|
||||
} else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.ApplicationError error) {
|
||||
throw new IOException(error.getException());
|
||||
} else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.NetworkError error) {
|
||||
throw error.getException();
|
||||
} else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.Missing) {
|
||||
logger.debug("No SVR data stored for the given credentials.");
|
||||
return null;
|
||||
} else {
|
||||
throw new AssertionError("Unexpected response: " + restoreResponse.getClass().getSimpleName());
|
||||
switch (restoreResponse) {
|
||||
case SecureValueRecovery.RestoreResponse.Success s -> {
|
||||
return s;
|
||||
}
|
||||
case SecureValueRecovery.RestoreResponse.PinMismatch pinMismatch ->
|
||||
throw new IncorrectPinException(pinMismatch.getTriesRemaining());
|
||||
case SecureValueRecovery.RestoreResponse.ApplicationError error ->
|
||||
throw new IOException(error.getException());
|
||||
case SecureValueRecovery.RestoreResponse.NetworkError error -> throw error.getException();
|
||||
case SecureValueRecovery.RestoreResponse.Missing missing -> {
|
||||
logger.debug("No SVR data stored for the given credentials.");
|
||||
return null;
|
||||
}
|
||||
case null, default ->
|
||||
throw new AssertionError("Unexpected response: " + restoreResponse.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1252,18 +1252,15 @@ public class ManagerImpl implements Manager {
|
|||
public boolean trustIdentityVerified(
|
||||
RecipientIdentifier.Single recipient, IdentityVerificationCode verificationCode
|
||||
) throws UnregisteredRecipientException {
|
||||
if (verificationCode instanceof IdentityVerificationCode.Fingerprint fingerprint) {
|
||||
return trustIdentity(recipient,
|
||||
return switch (verificationCode) {
|
||||
case IdentityVerificationCode.Fingerprint fingerprint -> trustIdentity(recipient,
|
||||
r -> context.getIdentityHelper().trustIdentityVerified(r, fingerprint.fingerprint()));
|
||||
} else if (verificationCode instanceof IdentityVerificationCode.SafetyNumber safetyNumber) {
|
||||
return trustIdentity(recipient,
|
||||
case IdentityVerificationCode.SafetyNumber safetyNumber -> trustIdentity(recipient,
|
||||
r -> context.getIdentityHelper().trustIdentityVerifiedSafetyNumber(r, safetyNumber.safetyNumber()));
|
||||
} else if (verificationCode instanceof IdentityVerificationCode.ScannableSafetyNumber safetyNumber) {
|
||||
return trustIdentity(recipient,
|
||||
case IdentityVerificationCode.ScannableSafetyNumber safetyNumber -> trustIdentity(recipient,
|
||||
r -> context.getIdentityHelper().trustIdentityVerifiedSafetyNumber(r, safetyNumber.safetyNumber()));
|
||||
} else {
|
||||
throw new AssertionError("Invalid verification code type");
|
||||
}
|
||||
case null, default -> throw new AssertionError("Invalid verification code type");
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue