X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPost.kt;h=57815084303ef12841b07ee4e241b6e204efa7a5;hb=549af4fa7323c58e0660f21dd8605cbc812db286;hp=70415618621a326f713b386b5eb3697df2fe8c99;hpb=ee39c03a6a811300728183552afcede1d9f8e79a;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Post.kt b/src/main/kotlin/net/pterodactylus/sone/data/Post.kt index 7041561..5781508 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Post.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Post.kt @@ -1,8 +1,26 @@ package net.pterodactylus.sone.data +import net.pterodactylus.sone.database.PostBuilder +import java.util.Comparator.comparing + /** * Predicate that returns whether a post is _not_ from the future, * i.e. whether it should be visible now. */ @get:JvmName("noFuturePost") val noFuturePost: (Post) -> Boolean = { it.time <= System.currentTimeMillis() } + +/** + * Comparator that orders posts by their time, newest posts first. + */ +@get:JvmName("newestPostFirst") +val newestPostFirst: Comparator = comparing(Post::getTime).reversed() + +data class PostShell(val id: String, val soneId: String, val recipientId: String?, val time: Long, val text: String) { + + fun build(postBuilder: PostBuilder) = + postBuilder.withId(id).from(soneId).let { if (recipientId != null) it.to(recipientId) else it }.withTime(time).withText(text).build() + +} + +fun Post.toShell() = PostShell(id, sone!!.id, recipient.orNull()?.id, time, text)