projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
60d42fc
)
Move unliking a post from Sone to Post.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 5 Nov 2013 18:26:38 +0000
(19:26 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:53 +0000
(22:25 +0100)
src/main/java/net/pterodactylus/sone/data/Post.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/Sone.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/UnlikePage.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/data/Post.java
b/src/main/java/net/pterodactylus/sone/data/Post.java
index
63b4908
..
269c2e4
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Post.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Post.java
@@
-125,6
+125,7
@@
public interface Post extends Identified {
public Post setKnown(boolean known);
public void like(Sone localSone);
public Post setKnown(boolean known);
public void like(Sone localSone);
+ public void unlike(Sone localSone);
List<PostReply> getReplies();
List<PostReply> getReplies();
diff --git
a/src/main/java/net/pterodactylus/sone/data/Sone.java
b/src/main/java/net/pterodactylus/sone/data/Sone.java
index
cc32b7a
..
e340bdf
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Sone.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Sone.java
@@
-418,15
+418,6
@@
public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
boolean isLikedPostId(String postId);
/**
boolean isLikedPostId(String postId);
/**
- * Removes the given post ID from the list of posts this Sone likes.
- *
- * @param postId
- * The ID of the post
- * @return This Sone (for method chaining)
- */
- Sone removeLikedPostId(String postId);
-
- /**
* Returns the IDs of all liked replies.
*
* @return All liked replies’ IDs
* Returns the IDs of all liked replies.
*
* @return All liked replies’ IDs
diff --git
a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
index
2fe4308
..
fa21e7a
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
@@
-133,6
+133,11
@@
public class DefaultPost implements Post {
}
@Override
}
@Override
+ public void unlike(Sone localSone) {
+ database.unlikePost(this, localSone);
+ }
+
+ @Override
public List<PostReply> getReplies() {
return from(database.getReplies(getId())).toSortedList(Reply.TIME_COMPARATOR);
}
public List<PostReply> getReplies() {
return from(database.getReplies(getId())).toSortedList(Reply.TIME_COMPARATOR);
}
diff --git
a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java
b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java
index
dc56dab
..
8bdca6c
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
+++ b/
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
@@
-100,5
+100,6
@@
public interface PostDatabase {
void removePosts(Sone sone);
void likePost(Post post, Sone localSone);
void removePosts(Sone sone);
void likePost(Post post, Sone localSone);
+ void unlikePost(Post post, Sone localSone);
}
}
diff --git
a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
index
7ede4fe
..
c73513d
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
+++ b/
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
@@
-296,6
+296,16
@@
public class MemoryDatabase extends AbstractService implements Database {
}
}
}
}
+ @Override
+ public void unlikePost(Post post, Sone localSone) {
+ lock.writeLock().lock();
+ try {
+ likedPosts.remove(localSone.getId(), post.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
//
// POSTSTORE METHODS
//
//
// POSTSTORE METHODS
//
diff --git
a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java
b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java
index
0670a18
..
48e5ab7
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/UnlikePage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/UnlikePage.java
@@
-24,6
+24,8
@@
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.web.Method;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.web.Method;
+import com.google.common.base.Optional;
+
/**
* Page that lets the user unlike a {@link Post}.
*
/**
* Page that lets the user unlike a {@link Post}.
*
@@
-56,7
+58,10
@@
public class UnlikePage extends SoneTemplatePage {
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
Sone currentSone = getCurrentSone(request.getToadletContext());
if ("post".equals(type)) {
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
Sone currentSone = getCurrentSone(request.getToadletContext());
if ("post".equals(type)) {
- currentSone.removeLikedPostId(id);
+ Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+ if (post.isPresent()) {
+ post.get().unlike(currentSone);
+ }
} else if ("reply".equals(type)) {
currentSone.removeLikedReplyId(id);
}
} else if ("reply".equals(type)) {
currentSone.removeLikedReplyId(id);
}
diff --git
a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java
b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java
index
bd3c387
..
5ac0ca0
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java
@@
-22,6
+22,8
@@
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
+import com.google.common.base.Optional;
+
/**
* AJAX page that lets the user unlike a {@link Post}.
*
/**
* AJAX page that lets the user unlike a {@link Post}.
*
@@
-51,7
+53,10
@@
public class UnlikeAjaxPage extends JsonPage {
return createErrorJsonObject("auth-required");
}
if ("post".equals(type)) {
return createErrorJsonObject("auth-required");
}
if ("post".equals(type)) {
- currentSone.removeLikedPostId(id);
+ 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().touchConfiguration();
} else if ("reply".equals(type)) {
currentSone.removeLikedReplyId(id);