projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
If no current Sone exists, return an error.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
ajax
/
LikeAjaxPage.java
diff --git
a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
index
1a49ccd
..
84a93e3
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
@@
-1,5
+1,5
@@
/*
/*
- * Sone - LikeAjaxPage.java - Copyright © 2010 David Roden
+ * Sone - LikeAjaxPage.java - Copyright © 2010
–2013
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,9
+18,12
@@
package net.pterodactylus.sone.web.ajax;
import net.pterodactylus.sone.data.Post;
package net.pterodactylus.sone.web.ajax;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.WebInterface;
-import net.pterodactylus.util.json.JsonObject;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+
+import com.google.common.base.Optional;
/**
* AJAX page that lets the user like a {@link Post}.
/**
* AJAX page that lets the user like a {@link Post}.
@@
-36,14
+39,11
@@
public class LikeAjaxPage extends JsonPage {
* The Sone web interface
*/
public LikeAjaxPage(WebInterface webInterface) {
* The Sone web interface
*/
public LikeAjaxPage(WebInterface webInterface) {
- super("
ajax/
like.ajax", webInterface);
+ super("like.ajax", webInterface);
}
}
- /**
- * {@inheritDoc}
- */
@Override
@Override
- protected Json
Object createJsonObject(
Request request) {
+ protected Json
ReturnObject createJsonObject(Freenet
Request request) {
String type = request.getHttpRequest().getParam("type", null);
String id = request.getHttpRequest().getParam(type, null);
if ((id == null) || (id.length() == 0)) {
String type = request.getHttpRequest().getParam("type", null);
String id = request.getHttpRequest().getParam(type, null);
if ((id == null) || (id.length() == 0)) {
@@
-54,9
+54,17
@@
public class LikeAjaxPage extends JsonPage {
return createErrorJsonObject("auth-required");
}
if ("post".equals(type)) {
return createErrorJsonObject("auth-required");
}
if ("post".equals(type)) {
- currentSone.addLikedPostId(id);
+ Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+ if (post.isPresent()) {
+ post.get().like(currentSone);
+ }
+ webInterface.getCore().touchConfiguration();
} else if ("reply".equals(type)) {
} else if ("reply".equals(type)) {
- currentSone.addLikedReplyId(id);
+ Optional<PostReply> postReply = webInterface.getCore().getDatabase().getPostReply(id);
+ if (postReply.isPresent()) {
+ postReply.get().like(currentSone);
+ }
+ webInterface.getCore().touchConfiguration();
} else {
return createErrorJsonObject("invalid-type");
}
} else {
return createErrorJsonObject("invalid-type");
}