Skip to content

Commit

Permalink
Closes #799
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantcheese committed Jun 13, 2020
1 parent 591c34b commit 09d5e03
Showing 1 changed file with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1017,21 +1017,43 @@ public void onPostOptionClicked(View anchor, Post post, Object id, boolean inPop
requestDeletePost(post);
break;
case POST_OPTION_SAVE:
SavedReply savedReply = SavedReply.fromBoardNoPassword(post.board, post.no, "");
if (!isBound()) break;
Set<Post> matchingPosts = new HashSet<>(1);
if (TextUtils.isEmpty(post.id)) {
//just this post
matchingPosts.add(post);
} else {
//match all post IDs
//noinspection ConstantConditions, isBound check takes care of this
for (Post p : getChanThread().getPosts()) {
if (!TextUtils.isEmpty(p.id) && p.id.equals(post.id)) {
matchingPosts.add(p);
}
}
}

if (databaseManager.getDatabaseSavedReplyManager().isSaved(post.board, post.no)) {
databaseManager.runTask(databaseManager.getDatabaseSavedReplyManager().unsaveReply(savedReply));
Pin watchedPin = watchManager.getPinByLoadable(loadable);
if (watchedPin != null) {
synchronized (this) {
watchedPin.quoteLastCount -= post.repliesFrom.size();
//unsave all matching posts
for (Post p : matchingPosts) {
SavedReply saved = SavedReply.fromBoardNoPassword(p.board, p.no, "");
databaseManager.runTask(databaseManager.getDatabaseSavedReplyManager().unsaveReply(saved));
Pin watchedPin = watchManager.getPinByLoadable(loadable);
if (watchedPin != null) {
synchronized (this) {
watchedPin.quoteLastCount -= p.repliesFrom.size();
}
}
}
} else {
databaseManager.runTask(databaseManager.getDatabaseSavedReplyManager().saveReply(savedReply));
Pin watchedPin = watchManager.getPinByLoadable(loadable);
if (watchedPin != null) {
synchronized (this) {
watchedPin.quoteLastCount += post.repliesFrom.size();
//save all matching posts
for (Post p : matchingPosts) {
SavedReply saved = SavedReply.fromBoardNoPassword(p.board, p.no, "");
databaseManager.runTask(databaseManager.getDatabaseSavedReplyManager().saveReply(saved));
Pin watchedPin = watchManager.getPinByLoadable(loadable);
if (watchedPin != null) {
synchronized (this) {
watchedPin.quoteLastCount += p.repliesFrom.size();
}
}
}
}
Expand Down

0 comments on commit 09d5e03

Please sign in to comment.