Reload page on server restart
This commit is contained in:
parent
f9149bef25
commit
8913ccc3ce
|
@ -9,6 +9,7 @@ import kotlinx.serialization.modules.SerializersModule
|
|||
@Serializable
|
||||
data class MessageBox(
|
||||
val timestamp: Long,
|
||||
val signature: String,
|
||||
val valid: Boolean,
|
||||
val messages: List<Message>
|
||||
)
|
||||
|
|
|
@ -20,6 +20,7 @@ class PushServiceClient {
|
|||
private val parser = DynamicObjectParser()
|
||||
|
||||
private var timestamp = body.dataset["timestamp"]?.toLongOrNull() ?: 0L
|
||||
private val signature = body.dataset["signature"] ?: ""
|
||||
private var intervalId: Int? = null
|
||||
|
||||
private fun reload() {
|
||||
|
@ -33,7 +34,7 @@ class PushServiceClient {
|
|||
private fun onMessage(messageBox: MessageBox) {
|
||||
body.classList.remove("offline")
|
||||
|
||||
if (messageBox.valid) {
|
||||
if (messageBox.valid && signature == messageBox.signature) {
|
||||
timestamp = messageBox.timestamp
|
||||
|
||||
for (message in messageBox.messages) {
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
.board-header {
|
||||
height: 8rem !important;
|
||||
margin-top:0.3rem;
|
||||
margin-top: 0.3rem;
|
||||
|
||||
& > div {
|
||||
height: 100%;
|
||||
|
@ -85,6 +85,22 @@
|
|||
.board-running {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
&:empty + .board-running-empty {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.board-running-empty {
|
||||
position: absolute !important;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 8rem;
|
||||
line-height: 8rem;
|
||||
width: 70%;
|
||||
text-align: center;
|
||||
font-size: 1.7rem;
|
||||
font-family: $headFont;
|
||||
}
|
||||
|
||||
.board-schedule {
|
||||
|
|
|
@ -89,13 +89,12 @@ fun Route.board() {
|
|||
val nowLocale = now.time + timeOffset
|
||||
respondMain(true, true) { theme ->
|
||||
content {
|
||||
|
||||
val announcement = AnnouncementRepository.getAnnouncement()
|
||||
var classes = "board-announcement announcement"
|
||||
var announcementClasses = "board-announcement announcement"
|
||||
if (announcement.isBlank()) {
|
||||
classes += " announcement-blank"
|
||||
announcementClasses += " announcement-blank"
|
||||
}
|
||||
div(classes) {
|
||||
div(announcementClasses) {
|
||||
span {
|
||||
+announcement
|
||||
}
|
||||
|
@ -155,6 +154,11 @@ fun Route.board() {
|
|||
}
|
||||
}
|
||||
}
|
||||
div("board-running-empty") {
|
||||
span {
|
||||
+"Es sind keine weiteren AKs geplant"
|
||||
}
|
||||
}
|
||||
div("board-logo") {
|
||||
img("KIF 47.0", "$prefix/static/images/logo.svg")
|
||||
div("board-header-date") {
|
||||
|
|
|
@ -7,6 +7,7 @@ import de.kif.common.Message
|
|||
import de.kif.common.MessageBox
|
||||
import de.kif.common.MessageType
|
||||
import de.kif.common.RepositoryType
|
||||
import de.kif.common.model.Post
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.routing.Route
|
||||
|
@ -16,7 +17,8 @@ import kotlin.concurrent.thread
|
|||
|
||||
object PushService {
|
||||
|
||||
private var leastValidTimestamp = System.currentTimeMillis()
|
||||
internal var leastValidTimestamp = System.currentTimeMillis()
|
||||
val signature = Post.generateUrl()
|
||||
|
||||
private val messages: MutableList<Pair<Long, Message>> = mutableListOf()
|
||||
|
||||
|
@ -52,6 +54,7 @@ object PushService {
|
|||
return if (timestamp < leastValidTimestamp) {
|
||||
MessageBox(
|
||||
System.currentTimeMillis(),
|
||||
signature,
|
||||
false,
|
||||
emptyList()
|
||||
)
|
||||
|
@ -63,6 +66,7 @@ object PushService {
|
|||
|
||||
MessageBox(
|
||||
System.currentTimeMillis(),
|
||||
signature,
|
||||
true,
|
||||
m.map { it.second }
|
||||
)
|
||||
|
@ -84,6 +88,8 @@ object PushService {
|
|||
}
|
||||
|
||||
fun Route.pushService() {
|
||||
PushService.leastValidTimestamp = System.currentTimeMillis()
|
||||
|
||||
get("/api/updates") {
|
||||
try {
|
||||
val timestamp = call.request.queryParameters["timestamp"]?.toLongOrNull() ?: 0
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.kif.backend.PortalSession
|
|||
import de.kif.backend.Resources
|
||||
import de.kif.backend.prefix
|
||||
import de.kif.backend.repository.AnnouncementRepository
|
||||
import de.kif.backend.util.PushService
|
||||
import de.kif.common.model.User
|
||||
import io.ktor.application.ApplicationCall
|
||||
import io.ktor.application.call
|
||||
|
@ -75,6 +76,7 @@ class MainTemplate(
|
|||
}
|
||||
body {
|
||||
attributes["data-timestamp"] = currentTimeMillis().toString()
|
||||
attributes["data-signature"] = PushService.signature
|
||||
|
||||
if (!noMenu) {
|
||||
insert(MenuTemplate(url, user)) {}
|
||||
|
|
Loading…
Reference in a new issue