Use java.util.Optional in Manager interface

This commit is contained in:
AsamK 2021-10-31 18:01:17 +01:00
parent f39983f78a
commit 1e87240db8
8 changed files with 19 additions and 16 deletions

View file

@ -24,7 +24,6 @@ import org.asamk.signal.manager.storage.recipients.Profile;
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
@ -41,6 +40,7 @@ import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

View file

@ -358,9 +358,13 @@ public class ManagerImpl implements Manager {
*/
@Override
public void setProfile(
String givenName, final String familyName, String about, String aboutEmoji, Optional<File> avatar
String givenName, final String familyName, String about, String aboutEmoji, java.util.Optional<File> avatar
) throws IOException {
profileHelper.setProfile(givenName, familyName, about, aboutEmoji, avatar);
profileHelper.setProfile(givenName,
familyName,
about,
aboutEmoji,
avatar == null ? null : Optional.fromNullable(avatar.orElse(null)));
syncHelper.sendSyncFetchProfileMessage();
}
@ -443,7 +447,7 @@ public class ManagerImpl implements Manager {
}
@Override
public void setRegistrationLockPin(Optional<String> pin) throws IOException, UnauthenticatedResponseException {
public void setRegistrationLockPin(java.util.Optional<String> pin) throws IOException, UnauthenticatedResponseException {
if (!account.isMasterDevice()) {
throw new RuntimeException("Only master device can set a PIN");
}

View file

@ -8,10 +8,10 @@ import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.manager.Manager;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
import java.io.IOException;
import java.util.Optional;
public class RemovePinCommand implements JsonRpcLocalCommand {
@ -30,7 +30,7 @@ public class RemovePinCommand implements JsonRpcLocalCommand {
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
try {
m.setRegistrationLockPin(Optional.absent());
m.setRegistrationLockPin(Optional.empty());
} catch (UnauthenticatedResponseException e) {
throw new UnexpectedErrorException("Remove pin failed with unauthenticated response: " + e.getMessage(), e);
} catch (IOException e) {

View file

@ -8,10 +8,10 @@ import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.manager.Manager;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
import java.io.IOException;
import java.util.Optional;
public class SetPinCommand implements JsonRpcLocalCommand {

View file

@ -8,10 +8,10 @@ import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager;
import org.whispersystems.libsignal.util.guava.Optional;
import java.io.File;
import java.io.IOException;
import java.util.Optional;
public class UpdateProfileCommand implements JsonRpcLocalCommand {
@ -45,7 +45,7 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
boolean removeAvatar = Boolean.TRUE.equals(ns.getBoolean("remove-avatar"));
Optional<File> avatarFile = removeAvatar
? Optional.absent()
? Optional.empty()
: avatarPath == null ? null : Optional.of(new File(avatarPath));
try {

View file

@ -32,7 +32,6 @@ import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -48,6 +47,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@ -122,7 +122,7 @@ public class DbusManagerImpl implements Manager {
emptyIfNull(familyName),
emptyIfNull(about),
emptyIfNull(aboutEmoji),
avatar == null ? "" : avatar.transform(File::getPath).or(""),
avatar == null ? "" : avatar.map(File::getPath).orElse(""),
avatar != null && !avatar.isPresent());
}

View file

@ -31,7 +31,6 @@ import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.freedesktop.dbus.types.Variant;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
@ -50,6 +49,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@ -561,7 +561,7 @@ public class DbusSignalImpl implements Signal {
aboutEmoji = nullIfEmpty(aboutEmoji);
avatarPath = nullIfEmpty(avatarPath);
Optional<File> avatarFile = removeAvatar
? Optional.absent()
? Optional.empty()
: avatarPath == null ? null : Optional.of(new File(avatarPath));
m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile);
} catch (IOException e) {
@ -583,7 +583,7 @@ public class DbusSignalImpl implements Signal {
@Override
public void removePin() {
try {
m.setRegistrationLockPin(Optional.absent());
m.setRegistrationLockPin(Optional.empty());
} catch (UnauthenticatedResponseException e) {
throw new Error.Failure("Remove pin failed with unauthenticated response: " + e.getMessage());
} catch (IOException e) {

View file

@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Arrays;
@ -18,7 +17,7 @@ public class Util {
private Util() {
}
public static String getStringIfNotBlank(Optional<String> value) {
public static String getStringIfNotBlank(org.whispersystems.libsignal.util.guava.Optional<String> value) {
var string = value.orNull();
if (string == null || string.isBlank()) {
return null;