idk
This commit is contained in:
@@ -18,6 +18,7 @@ val resourcesPath: String = System.getenv("RESOURCES") ?: "src/main/resources/"
|
||||
|
||||
object ConversationHandler {
|
||||
val ids = mutableListOf<Int>()
|
||||
val conversations = mutableListOf<Conversation>()
|
||||
|
||||
fun nextID(): Int
|
||||
{
|
||||
@@ -29,12 +30,23 @@ object ConversationHandler {
|
||||
return num
|
||||
}
|
||||
}
|
||||
val conversations = mutableListOf<Conversation>()
|
||||
fun listAllConversations(): String
|
||||
{
|
||||
val stringBuilder = StringBuilder()
|
||||
|
||||
for (conversation in conversations)
|
||||
{
|
||||
stringBuilder.append(conversation.list())
|
||||
}
|
||||
|
||||
return stringBuilder.toString()
|
||||
|
||||
}
|
||||
|
||||
fun newConv(id: Int = nextID())
|
||||
{
|
||||
conversations.add(Conversation(id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Conversation(val ID: Int)
|
||||
@@ -48,18 +60,39 @@ class Conversation(val ID: Int)
|
||||
newMsg = true
|
||||
}
|
||||
|
||||
fun list(): String
|
||||
{
|
||||
return """
|
||||
<div class="conversation">
|
||||
<p style="flex-grow: 1; background: ">$ID</p>
|
||||
<p style="flex-grow: 9;">${messages.last().text}</p>
|
||||
<div>
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
override fun toString(): String
|
||||
{
|
||||
newMsg = false
|
||||
|
||||
return messages.last().toString()
|
||||
val returnString = StringBuilder()
|
||||
|
||||
for (message in messages.reversed())
|
||||
{
|
||||
if (!message.read)
|
||||
{
|
||||
returnString.append(message.toString())
|
||||
returnString.append("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return returnString.toString()
|
||||
}
|
||||
|
||||
fun sendAll(): String
|
||||
{
|
||||
val returnString = StringBuilder()
|
||||
|
||||
for (message in messages)
|
||||
for (message in messages.reversed())
|
||||
{
|
||||
returnString.append(message.toString())
|
||||
returnString.append("\n")
|
||||
@@ -71,13 +104,18 @@ class Conversation(val ID: Int)
|
||||
|
||||
data class Message(val user: Boolean, val text: String)
|
||||
{
|
||||
var read: Boolean = false
|
||||
|
||||
override fun toString(): String
|
||||
{
|
||||
read = true
|
||||
|
||||
override fun toString() = """
|
||||
return """
|
||||
<div class="message-${if (user) "user" else "scott"}">
|
||||
<p>$text</p>
|
||||
</div>
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@@ -92,6 +130,14 @@ fun runEmbeddedServer()
|
||||
routing {
|
||||
staticFiles("/resources", File(resourcesPath))
|
||||
staticFiles("/", File(resourcesPath+"/index.html"))
|
||||
staticFiles("/admin", File(resourcesPath+"/admin.html"))
|
||||
|
||||
route("/admin")
|
||||
{
|
||||
get("/api/all_messages") {
|
||||
call.respondText(ConversationHandler.listAllConversations())
|
||||
}
|
||||
}
|
||||
|
||||
put("/api/write/{id}")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user