🚚 Move shells closer to the interfaces
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / data / Reply.kt
index 9a3ec64..d570f48 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.data
 
+import net.pterodactylus.sone.database.PostReplyBuilder
 import java.util.Comparator.comparing
 
 /**
@@ -25,3 +26,20 @@ import java.util.Comparator.comparing
 @get:JvmName("newestReplyFirst")
 val newestReplyFirst: Comparator<Reply<*>> =
                comparing(Reply<*>::getTime).reversed()
+
+/**
+ * Predicate that returns whether a reply is _not_ from the future,
+ * i.e. whether it should be visible now.
+ */
+val noFutureReply: (Reply<*>) -> Boolean =
+               { it.getTime() <= System.currentTimeMillis() }
+
+data class PostReplyShell(val id: String, val soneId: String, val postId: String, val time: Long, val text: String) {
+
+       fun build(postReplyBuilder: PostReplyBuilder): PostReply {
+               return postReplyBuilder.withId(id).from(soneId).to(postId).withTime(time).withText(text).build()
+       }
+
+}
+
+fun PostReply.toShell() = PostReplyShell(id, sone.id, postId, time, text)