/*
- * Sone - UnlikeAjaxPage.java - Copyright © 2010 David Roden
+ * Sone - UnlikeAjaxPage.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
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.util.json.JsonObject;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+
+import com.google.common.base.Optional;
/**
* AJAX page that lets the user unlike a {@link Post}.
super("unlike.ajax", webInterface);
}
- /**
- * {@inheritDoc}
- */
@Override
- protected JsonObject createJsonObject(Request request) {
+ protected JsonReturnObject createJsonObject(FreenetRequest request) {
String type = request.getHttpRequest().getParam("type", null);
String id = request.getHttpRequest().getParam(type, null);
if ((id == null) || (id.length() == 0)) {
return createErrorJsonObject("auth-required");
}
if ("post".equals(type)) {
- currentSone.removeLikedPostId(id);
- webInterface.getCore().saveSone(currentSone);
+ Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+ if (post.isPresent()) {
+ post.get().unlike(currentSone);
+ }
+ webInterface.getCore().touchConfiguration();
} else if ("reply".equals(type)) {
- currentSone.removeLikedReplyId(id);
- webInterface.getCore().saveSone(currentSone);
+ Optional<PostReply> postReply = webInterface.getCore().getDatabase().getPostReply(id);
+ if (postReply.isPresent()) {
+ postReply.get().unlike(currentSone);
+ }
+ webInterface.getCore().touchConfiguration();
} else {
return createErrorJsonObject("invalid-type");
}