From 042a6df867a153650600882cd0a5e5edbdffca1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 26 Nov 2015 18:43:38 +0100 Subject: [PATCH] Remove all posts and replies when Sone is removed The posts and replies would remain in the notifications but their Sone would be gone from the database, leading to exceptions in the web interface. --- .../net/pterodactylus/sone/web/WebInterface.java | 66 +++++++--------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index beba513..98cc99d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -884,72 +884,46 @@ public class WebInterface { newSoneNotification.remove(markSoneKnownEvent.sone()); } - /** - * Notifies the web interface that a {@link Post} was marked as known. - * - * @param markPostKnownEvent - * The event - */ @Subscribe public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) { - newPostNotification.remove(markPostKnownEvent.post()); - localPostNotification.remove(markPostKnownEvent.post()); - if (!localSoneMentionedInNewPostOrReply(markPostKnownEvent.post())) { - mentionNotification.remove(markPostKnownEvent.post()); - } + removePost(markPostKnownEvent.post()); } - /** - * Notifies the web interface that a {@link PostReply} was marked as known. - * - * @param markPostReplyKnownEvent - * The event - */ @Subscribe public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) { - PostReply postReply = markPostReplyKnownEvent.postReply(); - newReplyNotification.remove(postReply); - localReplyNotification.remove(postReply); - if (postReply.getPost().isPresent() && !localSoneMentionedInNewPostOrReply(postReply.getPost().get())) { - mentionNotification.remove(postReply.getPost().get()); - } + removeReply(markPostReplyKnownEvent.postReply()); } - /** - * Notifies the web interface that a {@link Sone} was removed. - * - * @param soneRemovedEvent - * The event - */ @Subscribe public void soneRemoved(SoneRemovedEvent soneRemovedEvent) { newSoneNotification.remove(soneRemovedEvent.sone()); + for (Post post : soneRemovedEvent.sone().getPosts()) { + removePost(post); + } + for (PostReply postReply : soneRemovedEvent.sone().getReplies()) { + removeReply(postReply); + } } - /** - * Notifies the web interface that a {@link Post} was removed. - * - * @param postRemovedEvent - * The event - */ @Subscribe public void postRemoved(PostRemovedEvent postRemovedEvent) { - newPostNotification.remove(postRemovedEvent.post()); - localPostNotification.remove(postRemovedEvent.post()); - if (!localSoneMentionedInNewPostOrReply(postRemovedEvent.post())) { - mentionNotification.remove(postRemovedEvent.post()); + removePost(postRemovedEvent.post()); + } + + private void removePost(Post post) { + newPostNotification.remove(post); + localPostNotification.remove(post); + if (!localSoneMentionedInNewPostOrReply(post)) { + mentionNotification.remove(post); } } - /** - * Notifies the web interface that a {@link PostReply} was removed. - * - * @param postReplyRemovedEvent - * The event - */ @Subscribe public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) { - PostReply reply = postReplyRemovedEvent.postReply(); + removeReply(postReplyRemovedEvent.postReply()); + } + + private void removeReply(PostReply reply) { newReplyNotification.remove(reply); localReplyNotification.remove(reply); if (reply.getPost().isPresent() && !localSoneMentionedInNewPostOrReply(reply.getPost().get())) { -- 2.7.4