🚚 Move shells closer to the interfaces
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / data / Post.kt
index d87bd3c..5781508 100644 (file)
@@ -1,5 +1,6 @@
 package net.pterodactylus.sone.data
 
+import net.pterodactylus.sone.database.PostBuilder
 import java.util.Comparator.comparing
 
 /**
@@ -14,3 +15,12 @@ val noFuturePost: (Post) -> Boolean = { it.time <= System.currentTimeMillis() }
  */
 @get:JvmName("newestPostFirst")
 val newestPostFirst: Comparator<Post> = 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)