projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
8aa1dca
)
Move post liking from Sone to Post.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 5 Nov 2013 18:23:35 +0000
(19:23 +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/data/impl/DefaultSone.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/fcp/LikePostCommand.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/LikePage.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.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
20bf518
..
63b4908
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Post.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Post.java
@@
-124,6
+124,8
@@
public interface Post extends Identified {
*/
public Post setKnown(boolean known);
*/
public Post setKnown(boolean known);
+ public void like(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
dfeb019
..
cc32b7a
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);
/**
- * Adds the given post ID to the list of posts this Sone likes.
- *
- * @param postId
- * The ID of the post
- * @return This Sone (for method chaining)
- */
- Sone addLikedPostId(String postId);
-
- /**
* Removes the given post ID from the list of posts this Sone likes.
*
* @param postId
* Removes the given post ID from the list of posts this Sone likes.
*
* @param postId
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
abef0c4
..
2fe4308
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
@@
-128,6
+128,11
@@
public class DefaultPost implements Post {
}
@Override
}
@Override
+ public void like(Sone localSone) {
+ database.likePost(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/data/impl/DefaultSone.java
b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java
index
92d7d5f
..
08a9ac1
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java
@@
-319,11
+319,6
@@
public class DefaultSone implements Sone {
return likedPostIds.contains(postId);
}
return likedPostIds.contains(postId);
}
- public Sone addLikedPostId(String postId) {
- likedPostIds.add(postId);
- return this;
- }
-
public Sone removeLikedPostId(String postId) {
likedPostIds.remove(postId);
return this;
public Sone removeLikedPostId(String postId) {
likedPostIds.remove(postId);
return this;
diff --git
a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java
b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java
index
9480071
..
dc56dab
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
+++ b/
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
@@
-99,4
+99,6
@@
public interface PostDatabase {
*/
void removePosts(Sone sone);
*/
void removePosts(Sone sone);
+ void likePost(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
8343caf
..
7ede4fe
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
+++ b/
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
@@
-57,6
+57,7
@@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
+import com.google.common.collect.SetMultimap;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
import com.google.common.util.concurrent.AbstractService;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
import com.google.common.util.concurrent.AbstractService;
@@
-83,6
+84,7
@@
public class MemoryDatabase extends AbstractService implements Database {
/** All posts by their Sones. */
private final Multimap<String, Post> sonePosts = HashMultimap.create();
/** All posts by their Sones. */
private final Multimap<String, Post> sonePosts = HashMultimap.create();
+ private final SetMultimap<String, String> likedPosts = HashMultimap.create();
/** All posts by their recipient. */
private final Multimap<String, Post> recipientPosts = HashMultimap.create();
/** All posts by their recipient. */
private final Multimap<String, Post> recipientPosts = HashMultimap.create();
@@
-284,6
+286,16
@@
public class MemoryDatabase extends AbstractService implements Database {
}
}
}
}
+ @Override
+ public void likePost(Post post, Sone localSone) {
+ lock.writeLock().lock();
+ try {
+ likedPosts.put(localSone.getId(), post.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
//
// POSTSTORE METHODS
//
//
// POSTSTORE METHODS
//
diff --git
a/src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
b/src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
index
ed1d42e
..
d2acb4a
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
+++ b/
src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
@@
-46,7
+46,7
@@
public class LikePostCommand extends AbstractSoneCommand {
public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
Post post = getPost(parameters, "Post");
Sone sone = getMandatoryLocalSone(parameters, "Sone");
public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
Post post = getPost(parameters, "Post");
Sone sone = getMandatoryLocalSone(parameters, "Sone");
-
sone.addLikedPostId(post.getId()
);
+
post.like(sone
);
return new Response("PostLiked", new SimpleFieldSetBuilder().put("LikeCount", getCore().getLikes(post).size()).get());
}
return new Response("PostLiked", new SimpleFieldSetBuilder().put("LikeCount", getCore().getLikes(post).size()).get());
}
diff --git
a/src/main/java/net/pterodactylus/sone/web/LikePage.java
b/src/main/java/net/pterodactylus/sone/web/LikePage.java
index
d4dd401
..
970b4c5
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/LikePage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/LikePage.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 like a {@link Post}.
*
/**
* Page that lets the user like a {@link Post}.
*
@@
-56,7
+58,10
@@
public class LikePage 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.addLikedPostId(id);
+ Optional<Post> post = webInterface.getCore().getDatabase().getPost(id);
+ if (post.isPresent()) {
+ post.get().like(currentSone);
+ }
} else if ("reply".equals(type)) {
currentSone.addLikedReplyId(id);
}
} else if ("reply".equals(type)) {
currentSone.addLikedReplyId(id);
}
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
7e7a6a6
..
ceeaf16
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.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 like a {@link Post}.
*
/**
* AJAX page that lets the user like a {@link Post}.
*
@@
-51,7
+53,10
@@
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)) {
currentSone.addLikedReplyId(id);
webInterface.getCore().touchConfiguration();
} else if ("reply".equals(type)) {
currentSone.addLikedReplyId(id);