X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommand.java;h=108a80f600077f6a28a4721b73b6ef8da5294a33;hp=8afe7c4d4e3d8e535286ed0d046a31caa043e10b;hb=45803a1c678d6811f7bbf85d50c79844031be0f0;hpb=33cc85447797301e299e7ac444fe53538f09a69d diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 8afe7c4..108a80f 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -134,7 +134,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand { * or if the Sone ID is invalid */ protected Sone getSone(SimpleFieldSet simpleFieldSet, String parameterName, boolean localOnly) throws FcpException { - return getSone(simpleFieldSet, parameterName, localOnly, true); + return getSone(simpleFieldSet, parameterName, localOnly, true).get(); } /** @@ -158,13 +158,13 @@ public abstract class AbstractSoneCommand extends AbstractCommand { * or if {@code mandatory} is {@code true} and the Sone ID is * invalid */ - protected Sone getSone(SimpleFieldSet simpleFieldSet, String parameterName, boolean localOnly, boolean mandatory) throws FcpException { + protected Optional getSone(SimpleFieldSet simpleFieldSet, String parameterName, boolean localOnly, boolean mandatory) throws FcpException { String soneId = simpleFieldSet.get(parameterName); if (mandatory && (soneId == null)) { throw new FcpException("Could not load Sone ID from “" + parameterName + "”."); } - Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId); - if (mandatory && (sone == null)) { + Optional sone = core.getSone(soneId); + if ((mandatory && !sone.isPresent()) || (mandatory && sone.isPresent() && (localOnly && !sone.get().isLocal()))) { throw new FcpException("Could not load Sone from “" + soneId + "”."); } return sone; @@ -236,14 +236,14 @@ public abstract class AbstractSoneCommand extends AbstractCommand { * such as if the Sone is followed by the local Sone * @return The simple field set containing the given Sone */ - protected static SimpleFieldSet encodeSone(Sone sone, String prefix, Sone localSone) { + protected static SimpleFieldSet encodeSone(Sone sone, String prefix, Optional localSone) { SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder(); soneBuilder.put(prefix + "Name", sone.getName()); soneBuilder.put(prefix + "NiceName", SoneAccessor.getNiceName(sone)); soneBuilder.put(prefix + "LastUpdated", sone.getTime()); - if (localSone != null) { - soneBuilder.put(prefix + "Followed", String.valueOf(localSone.hasFriend(sone.getId()))); + if (localSone.isPresent()) { + soneBuilder.put(prefix + "Followed", String.valueOf(localSone.get().hasFriend(sone.getId()))); } Profile profile = sone.getProfile(); soneBuilder.put(prefix + "Field.Count", profile.getFields().size()); @@ -301,8 +301,8 @@ public abstract class AbstractSoneCommand extends AbstractCommand { postBuilder.put(prefix + "ID", post.getId()); postBuilder.put(prefix + "Sone", post.getSone().getId()); - if (post.getRecipient() != null) { - postBuilder.put(prefix + "Recipient", post.getRecipient().getId()); + if (post.hasRecipient()) { + postBuilder.put(prefix + "Recipient", post.getRecipientId().get()); } postBuilder.put(prefix + "Time", post.getTime()); postBuilder.put(prefix + "Text", encodeString(post.getText()));