import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.utils.*
import net.pterodactylus.util.template.*
/**
"liked" -> templateContext.currentSone?.isLikedPostId(post.id) ?: false
"new" -> !post.isKnown
"bookmarked" -> core.isBookmarked(post)
- "replySone" -> core.getReplies(post)
- .lastOrNull { it.sone.isLocal }
- ?.sone
+ "replySone" -> core.getReplies(post).lastOrNull { it.sone.isLocal }?.sone
+ ?: post.recipient.let { it.takeIf { it.isLocal } }
?: post.sone.takeIf { it.isLocal }
?: templateContext.currentSone
else -> super.get(templateContext, `object`, member)
import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.test.*
+import net.pterodactylus.sone.utils.*
import net.pterodactylus.util.template.*
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
}
@Test
+ fun `reply sone for post directed at local sone is local sone`() {
+ val localSone = mockLocalSone()
+ val post = mockPostFrom(remoteSone, localSone)
+ assertThat(accessor[templateContext, post, "replySone"], equalTo<Any>(localSone))
+ }
+
+
+ @Test
fun `accessor returns other properties`() {
assertThat(accessor[null, post, "hashCode"], equalTo<Any>(post.hashCode()))
}
this["currentSone"] = currentSone
}
-private fun mockPostFrom(sone: Sone) = mock<Post>().apply {
+private fun mockPostFrom(sone: Sone, recipient: Sone? = null) = mock<Post>().apply {
whenever(id).thenReturn("post-id")
whenever(this.sone).thenReturn(sone)
+ whenever(this.recipient).thenReturn(recipient.asOptional())
}
private fun mockReplyFrom(sone: Sone) = mock<PostReply>().apply { whenever(this.sone).thenReturn(sone) }