Return an optional from the Core already.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 15 Oct 2013 20:34:36 +0000 (22:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:27 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/fcp/CreatePostCommand.java
src/main/java/net/pterodactylus/sone/web/CreatePostPage.java
src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java

index e550652..48afb36 100644 (file)
@@ -1950,8 +1950,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                touchConfiguration();
        }
 
-       public PostCreated postCreated() {
-               return new PostCreated() {
+       public Optional<PostCreated> postCreated() {
+               return Optional.<PostCreated>of(new PostCreated() {
                        @Override
                        public void postCreated(final Post post) {
                                if (post.isKnown()) {
@@ -1967,7 +1967,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                        }, 10, TimeUnit.SECONDS);
                                }
                        }
-               };
+               });
        }
 
 }
index 01b52aa..fcad23c 100644 (file)
@@ -18,7 +18,6 @@
 package net.pterodactylus.sone.fcp;
 
 import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Optional.of;
 import static net.pterodactylus.sone.data.Identified.GET_ID;
 
 import net.pterodactylus.sone.core.Core;
@@ -61,7 +60,7 @@ public class CreatePostCommand extends AbstractSoneCommand {
                if (sone.equals(recipient)) {
                        return new ErrorResponse("Sone and Recipient must not be the same.");
                }
-               Post post = sone.newPostBuilder().to(fromNullable(recipient).transform(GET_ID)).withText(text).build(of(getCore().postCreated()));
+               Post post = sone.newPostBuilder().to(fromNullable(recipient).transform(GET_ID)).withText(text).build(getCore().postCreated());
                return new Response("PostCreated", new SimpleFieldSetBuilder().put("Post", post.getId()).get());
        }
 
index 73cd097..9348652 100644 (file)
@@ -72,7 +72,7 @@ public class CreatePostPage extends SoneTemplatePage {
                                }
                                Optional<Sone> recipient = webInterface.getCore().getSone(recipientId);
                                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
-                               sender.get().newPostBuilder().to(recipient.transform(Identified.GET_ID)).withText(text).build(of(webInterface.getCore().postCreated()));
+                               sender.get().newPostBuilder().to(recipient.transform(Identified.GET_ID)).withText(text).build(webInterface.getCore().postCreated());
                                throw new RedirectException(returnPage);
                        }
                        templateContext.set("errorTextEmpty", true);
index 536d4fb..afccd40 100644 (file)
@@ -66,7 +66,7 @@ public class CreatePostAjaxPage extends JsonPage {
                        return createErrorJsonObject("text-required");
                }
                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
-               Post newPost = sender.get().newPostBuilder().to(recipient.transform(GET_ID)).withText(text).build(of(webInterface.getCore().postCreated()));
+               Post newPost = sender.get().newPostBuilder().to(recipient.transform(GET_ID)).withText(text).build(webInterface.getCore().postCreated());
                return createSuccessJsonObject().put("postId", newPost.getId()).put("sone", sender.get().getId()).put("recipient", newPost.getRecipientId().orNull());
        }