mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Use java.util.Optional in Manager interface
This commit is contained in:
parent
f39983f78a
commit
1e87240db8
8 changed files with 19 additions and 16 deletions
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue