}
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));
}
post.setKnown(true);
}
for (PostReply reply : replies) {
- reply.setKnown(true);
+ database.setPostReplyKnown(reply);
}
logger.info(String.format("Sone loaded successfully: %s", sone));
*/
public void markReplyKnown(PostReply reply) {
boolean previouslyKnown = reply.isKnown();
- reply.setKnown(true);
+ database.setPostReplyKnown(reply);
eventBus.post(new MarkPostReplyKnownEvent(reply));
if (!previouslyKnown) {
touchConfiguration();
*/
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);
-
}
return database.isPostReplyKnown(this);
}
- /**
- * {@inheritDocs}
- */
- @Override
- public PostReply setKnown(boolean known) {
- database.setPostReplyKnown(this, known);
- return this;
- }
-
//
// POSTREPLY METHODS
//
.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
fun storePostReply(postReply: PostReply)
fun removePostReply(postReply: PostReply)
+ fun setPostReplyKnown(postReply: PostReply)
}
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()
}
@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
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))
}
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")
}
override fun getTime() = time
override fun getText() = text
override fun isKnown() = known
- override fun setKnown(known: Boolean): PostReply = this
}
fun createImage(sone: Sone): Image =