projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change dates in file headers
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
ajax
/
GetPostAjaxPage.java
diff --git
a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
index
f46ec6b
..
60e94ce
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
@@
-1,5
+1,5
@@
/*
/*
- * Sone - GetPostAjaxPage.java - Copyright © 2010 David Roden
+ * Sone - GetPostAjaxPage.java - Copyright © 2010
–2016
David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@
-18,16
+18,22
@@
package net.pterodactylus.sone.web.ajax;
import java.io.StringWriter;
package net.pterodactylus.sone.web.ajax;
import java.io.StringWriter;
+import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
+
+import com.google.common.base.Optional;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.io.Closer;
-import net.pterodactylus.util.json.JsonObject;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateException;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
/**
* This AJAX handler retrieves information and rendered representation of a
* {@link Post}.
/**
* This AJAX handler retrieves information and rendered representation of a
* {@link Post}.
@@
-56,13
+62,13
@@
public class GetPostAjaxPage extends JsonPage {
* {@inheritDoc}
*/
@Override
* {@inheritDoc}
*/
@Override
- protected Json
Object createJsonObject(
Request request) {
+ protected Json
ReturnObject createJsonObject(Freenet
Request request) {
String postId = request.getHttpRequest().getParam("post");
String postId = request.getHttpRequest().getParam("post");
-
Post post = webInterface.getCore().getPost(postId, false
);
- if (
post == null
) {
+
Optional<Post> post = webInterface.getCore().getPost(postId
);
+ if (
!post.isPresent()
) {
return createErrorJsonObject("invalid-post-id");
}
return createErrorJsonObject("invalid-post-id");
}
- return createSuccessJsonObject().put("post", createJsonPost(request, post, getCurrentSone(request.getToadletContext())));
+ return createSuccessJsonObject().put("post", createJsonPost(request, post
.get()
, getCurrentSone(request.getToadletContext())));
}
/**
}
/**
@@
-89,14
+95,15
@@
public class GetPostAjaxPage extends JsonPage {
* The currently logged in Sone (to store in the template)
* @return The JSON representation of the post
*/
* The currently logged in Sone (to store in the template)
* @return The JSON representation of the post
*/
- private Json
Object createJsonPost(
Request request, Post post, Sone currentSone) {
-
JsonObject jsonPost = new JsonObject(
);
+ private Json
Node createJsonPost(Freenet
Request request, Post post, Sone currentSone) {
+
ObjectNode jsonPost = new ObjectNode(instance
);
jsonPost.put("id", post.getId());
jsonPost.put("sone", post.getSone().getId());
jsonPost.put("id", post.getId());
jsonPost.put("sone", post.getSone().getId());
- jsonPost.put("recipient",
(post.getRecipient() == null) ? null : post.getRecipient().getId
());
+ jsonPost.put("recipient",
post.getRecipientId().orNull
());
jsonPost.put("time", post.getTime());
StringWriter stringWriter = new StringWriter();
TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
jsonPost.put("time", post.getTime());
StringWriter stringWriter = new StringWriter();
TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
+ templateContext.set("core", webInterface.getCore());
templateContext.set("request", request);
templateContext.set("post", post);
templateContext.set("currentSone", currentSone);
templateContext.set("request", request);
templateContext.set("post", post);
templateContext.set("currentSone", currentSone);