Bugfixes
This commit is contained in:
parent
619b7340bb
commit
e63b51e5a7
|
@ -14,6 +14,8 @@ import io.ktor.routing.Route
|
||||||
import io.ktor.routing.get
|
import io.ktor.routing.get
|
||||||
import kotlinx.html.currentTimeMillis
|
import kotlinx.html.currentTimeMillis
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
object PushService {
|
object PushService {
|
||||||
|
|
||||||
|
@ -35,14 +37,20 @@ object PushService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIndexOfTimestamp(timestamp: Long): Int {
|
private fun getIndexOfTimestamp(timestamp: Long): Int {
|
||||||
val index = messages.binarySearch(Pair(timestamp, Message.empty), compareBy { it.first })
|
var index = messages.binarySearch(Pair(timestamp, Message.empty), compareBy { it.first })
|
||||||
val i = if (index < 0) {
|
index = if (index < 0) {
|
||||||
-index - 1
|
-index - 1
|
||||||
} else {
|
} else {
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (i < 0) 0 else i
|
var element = messages.getOrNull(index - 1)
|
||||||
|
while (element != null && element.first >= timestamp) {
|
||||||
|
index--
|
||||||
|
element = messages.getOrNull(index - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return max(0, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue