🔥 Remove setKnown() method from replies
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 23 Feb 2020 10:54:09 +0000 (11:54 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 23 Feb 2020 10:57:28 +0000 (11:57 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/data/Reply.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java
src/main/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessor.kt
src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt
src/main/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabase.kt
src/test/kotlin/net/pterodactylus/sone/core/UpdatedSoneProcessorTest.kt
src/test/kotlin/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.kt
src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt

index c4cc9cf..da1b2f8 100644 (file)
@@ -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();
index 918fd01..0cf2a52 100644 (file)
@@ -60,13 +60,4 @@ public interface Reply<T extends Reply<T>> 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);
-
 }
index ef21a75..5764622 100644 (file)
@@ -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
        //
index 28bac6d..54af30a 100644 (file)
@@ -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
index 671ab53..859cbb0 100644 (file)
@@ -26,5 +26,6 @@ interface PostReplyStore {
 
        fun storePostReply(postReply: PostReply)
        fun removePostReply(postReply: PostReply)
+       fun setPostReplyKnown(postReply: PostReply)
 
 }
index e943b38..fd7ac48 100644 (file)
@@ -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()
                        }
 
index 9e7c71e..356ea9c 100644 (file)
@@ -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
index 150336f..973047f 100644 (file)
@@ -405,7 +405,7 @@ class MemoryDatabaseTest {
                prepareConfigurationValues()
                val postReply = mock<PostReply>()
                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<Any>(null))
        }
@@ -435,8 +435,8 @@ class MemoryDatabaseTest {
                prepareConfigurationValues()
                val postReply = mock<PostReply>()
                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")
        }
 
index ae2ecd6..d556f6b 100644 (file)
@@ -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 =