1 package net.pterodactylus.sone.data
3 import net.pterodactylus.sone.database.PostBuilder
4 import java.util.Comparator.comparing
7 * Predicate that returns whether a post is _not_ from the future,
8 * i.e. whether it should be visible now.
10 @get:JvmName("noFuturePost")
11 val noFuturePost: (Post) -> Boolean = { it.time <= System.currentTimeMillis() }
14 * Comparator that orders posts by their time, newest posts first.
16 @get:JvmName("newestPostFirst")
17 val newestPostFirst: Comparator<Post> = comparing(Post::getTime).reversed()
19 data class PostShell(val id: String, val soneId: String, val recipientId: String?, val time: Long, val text: String) {
21 fun build(postBuilder: PostBuilder) =
22 postBuilder.withId(id).from(soneId).let { if (recipientId != null) it.to(recipientId) else it }.withTime(time).withText(text).build()
26 fun Post.toShell() = PostShell(id, sone!!.id, recipient.orNull()?.id, time, text)