🔀 Merge branch 'release/v82'
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / template / PostAccessor.kt
index 5222b94..42239aa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - PostAccessor.java - Copyright Â© 2010–2019 David Roden
+ * Sone - PostAccessor.kt - Copyright Â© 2010–2020 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 package net.pterodactylus.sone.template
 
 import net.pterodactylus.sone.core.*
 import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.utils.*
 import net.pterodactylus.util.template.*
 
 /**
@@ -39,9 +41,8 @@ class PostAccessor(private val core: Core) : ReflectionAccessor() {
                                        "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)
@@ -50,5 +51,5 @@ class PostAccessor(private val core: Core) : ReflectionAccessor() {
 
 }
 
-private fun Core.getReplies(post: Post) = getReplies(post.id).filter { Reply.FUTURE_REPLY_FILTER.apply(it) }
+private fun Core.getReplies(post: Post) = getReplies(post.id).filter(noFutureReply)
 private val TemplateContext?.currentSone: Sone? get() = this?.get("currentSone") as? Sone