X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPost.kt;h=57815084303ef12841b07ee4e241b6e204efa7a5;hb=07643fdd510640d6c0b20963e4f4f36e06469fb5;hp=955196a0399325e7542c3c8eb337f8fc8d445c1e;hpb=37ac474440aec3141cf609af25ee2332724dc7e4;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 955196a..5781508 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Post.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Post.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.data +import net.pterodactylus.sone.database.PostBuilder import java.util.Comparator.comparing /** @@ -12,5 +13,14 @@ val noFuturePost: (Post) -> Boolean = { it.time <= System.currentTimeMillis() } /** * Comparator that orders posts by their time, newest posts first. */ -@get:JvmName("newestFirst") -val newestFirst: Comparator = comparing(Post::getTime).reversed() +@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)