projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
🎨 Rename “newest first” post comparator
[Sone.git]
/
src
/
main
/
kotlin
/
net
/
pterodactylus
/
sone
/
template
/
PostAccessor.kt
diff --git
a/src/main/kotlin/net/pterodactylus/sone/template/PostAccessor.kt
b/src/main/kotlin/net/pterodactylus/sone/template/PostAccessor.kt
index
db26866
..
ab7f6ba
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/template/PostAccessor.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/template/PostAccessor.kt
@@
-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
*
* 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
@@
-14,10
+14,12
@@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* 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.*
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.*
/**
import net.pterodactylus.util.template.*
/**
@@
-34,13
+36,20
@@
class PostAccessor(private val core: Core) : ReflectionAccessor() {
override fun get(templateContext: TemplateContext?, `object`: Any?, member: String): Any? =
(`object` as Post).let { post ->
when (member) {
override fun get(templateContext: TemplateContext?, `object`: Any?, member: String): Any? =
(`object` as Post).let { post ->
when (member) {
- "replies" -> core.getReplies(post
.id).filter { Reply.FUTURE_REPLY_FILTER.apply(it) }
+ "replies" -> core.getReplies(post
)
"likes" -> core.getLikes(post)
"likes" -> core.getLikes(post)
- "liked" ->
(templateContext?.get("currentSone") as? Sone)
?.isLikedPostId(post.id) ?: false
+ "liked" ->
templateContext.currentSone
?.isLikedPostId(post.id) ?: false
"new" -> !post.isKnown
"bookmarked" -> core.isBookmarked(post)
"new" -> !post.isKnown
"bookmarked" -> core.isBookmarked(post)
+ "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)
}
}
}
else -> super.get(templateContext, `object`, member)
}
}
}
+
+private fun Core.getReplies(post: Post) = getReplies(post.id).filter { Reply.FUTURE_REPLY_FILTER.apply(it) }
+private val TemplateContext?.currentSone: Sone? get() = this?.get("currentSone") as? Sone