From b1e6cda6c077a95eab43ab371a75afd92ef820a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 23 Feb 2020 11:54:09 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=94=A5=20Remove=20setKnown()=20method=20fr?= =?utf8?q?om=20replies?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 8 ++++---- src/main/java/net/pterodactylus/sone/data/Reply.java | 9 --------- .../net/pterodactylus/sone/database/memory/MemoryPostReply.java | 9 --------- .../kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessor.kt | 2 +- .../kotlin/net/pterodactylus/sone/database/PostReplyStore.kt | 1 + .../net/pterodactylus/sone/database/memory/MemoryDatabase.kt | 7 ++----- .../net/pterodactylus/sone/core/UpdatedSoneProcessorTest.kt | 4 ++-- .../net/pterodactylus/sone/database/memory/MemoryDatabaseTest.kt | 6 +++--- src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt | 1 - 9 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c4cc9cf..da1b2f8 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -797,9 +797,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } for (PostReply postReply : soneComparison.getNewPostReplies()) { if (postReply.getSone().equals(newSone)) { - postReply.setKnown(true); + database.setPostReplyKnown(postReply); } else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) { - postReply.setKnown(true); + database.setPostReplyKnown(postReply); } else if (!postReply.isKnown()) { events.add(new NewPostReplyFoundEvent(postReply)); } @@ -976,7 +976,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, post.setKnown(true); } for (PostReply reply : replies) { - reply.setKnown(true); + database.setPostReplyKnown(reply); } logger.info(String.format("Sone loaded successfully: %s", sone)); @@ -1118,7 +1118,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, */ public void markReplyKnown(PostReply reply) { boolean previouslyKnown = reply.isKnown(); - reply.setKnown(true); + database.setPostReplyKnown(reply); eventBus.post(new MarkPostReplyKnownEvent(reply)); if (!previouslyKnown) { touchConfiguration(); diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index 918fd01..0cf2a52 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -60,13 +60,4 @@ public interface Reply> extends Identified { */ public boolean isKnown(); - /** - * Sets whether this reply is known. - * - * @param known - * {@code true} if this reply is known, {@code false} otherwise - * @return This reply - */ - public T setKnown(boolean known); - } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java index ef21a75..5764622 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java @@ -124,15 +124,6 @@ class MemoryPostReply implements PostReply { return database.isPostReplyKnown(this); } - /** - * {@inheritDocs} - */ - @Override - public PostReply setKnown(boolean known) { - database.setPostReplyKnown(this, known); - return this; - } - // // POSTREPLY METHODS // diff --git a/src/main/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessor.kt b/src/main/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessor.kt index 28bac6d..54af30a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessor.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessor.kt @@ -42,7 +42,7 @@ abstract class BasicUpdateSoneProcessor(private val database: Database, private .map { PostRemovedEvent(it) } .forEach(eventBus::post) newPostReplies - .onEach { postReply -> if (postReply.time <= sone.followingTime) postReply.isKnown = true } + .onEach { postReply -> if (postReply.time <= sone.followingTime) database.setPostReplyKnown(postReply) } .mapNotNull { postReply -> postReply.isKnown.ifFalse { NewPostReplyFoundEvent(postReply) } } .forEach(eventBus::post) removedPostReplies diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt index 671ab53..859cbb0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt @@ -26,5 +26,6 @@ interface PostReplyStore { fun storePostReply(postReply: PostReply) fun removePostReply(postReply: PostReply) + fun setPostReplyKnown(postReply: PostReply) } diff --git a/src/main/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabase.kt b/src/main/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabase.kt index e943b38..fd7ac48 100644 --- a/src/main/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabase.kt +++ b/src/main/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabase.kt @@ -297,12 +297,9 @@ class MemoryDatabase @Inject constructor(private val configuration: Configuratio protected fun isPostReplyKnown(postReply: PostReply) = readLock.withLock { postReply.id in knownPostReplies } - fun setPostReplyKnown(postReply: PostReply, known: Boolean): Unit = + override fun setPostReplyKnown(postReply: PostReply): Unit = writeLock.withLock { - if (known) - knownPostReplies.add(postReply.id) - else - knownPostReplies.remove(postReply.id) + knownPostReplies.add(postReply.id) saveKnownPostReplies() } diff --git a/src/test/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessorTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessorTest.kt index 9e7c71e..356ea9c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessorTest.kt @@ -123,14 +123,14 @@ class UpdatedSoneProcessorTest { @Test fun `updated Sone processor does not mark new reply as known if sone was not followed after reply`() { updatedSoneProcessor.updateSone(newSone) - verify(postReplies[2], never()).isKnown = true + verify(database, never()).setPostReplyKnown(postReplies[2]) } @Test fun `updated Sone processor marks new reply as known if sone was followed after reply`() { whenever(database.getFollowingTime("sone")).thenReturn(3500L) updatedSoneProcessor.updateSone(newSone) - verify(postReplies[2]).isKnown = true + verify(database).setPostReplyKnown(postReplies[2]) } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.kt b/src/test/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.kt index 150336f..973047f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.kt @@ -405,7 +405,7 @@ class MemoryDatabaseTest { prepareConfigurationValues() val postReply = mock() whenever(postReply.id).thenReturn("post-reply-id") - memoryDatabase.setPostReplyKnown(postReply, true) + memoryDatabase.setPostReplyKnown(postReply) assertThat(configuration.getStringValue("KnownReplies/0/ID").value, equalTo("post-reply-id")) assertThat(configuration.getStringValue("KnownReplies/1/ID").value, equalTo(null)) } @@ -435,8 +435,8 @@ class MemoryDatabaseTest { prepareConfigurationValues() val postReply = mock() whenever(postReply.id).thenReturn("post-reply-id") - memoryDatabase.setPostReplyKnown(postReply, true) - memoryDatabase.setPostReplyKnown(postReply, true) + memoryDatabase.setPostReplyKnown(postReply) + memoryDatabase.setPostReplyKnown(postReply) verify(configuration, times(1)).getStringValue("KnownReplies/1/ID") } diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt b/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt index ae2ecd6..d556f6b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt @@ -60,7 +60,6 @@ fun emptyPostReply(text: String = "", post: Post? = createPost(), sone: Sone = r override fun getTime() = time override fun getText() = text override fun isKnown() = known - override fun setKnown(known: Boolean): PostReply = this } fun createImage(sone: Sone): Image = -- 2.7.4