Backported chat crash fixes and code improvements from video branch.

This commit is contained in:
Juha Heinanen
2020-05-31 14:24:50 +03:00
parent 366bfbb120
commit 3558fc0e03
5 changed files with 34 additions and 46 deletions
@@ -7,6 +7,22 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
var direction: Int, var responseCode: Int, var responseReason: String,
var new: Boolean): Serializable {
fun add() {
BaresipService.messages.add(this)
var count = 0
var firstIndex = -1
for (i in BaresipService.messages.indices)
if (BaresipService.messages[i].aor == this.aor) {
if (count == 0) firstIndex = i
count++
if (count > MESSAGE_HISTORY_SIZE) {
break
}
}
if (count > MESSAGE_HISTORY_SIZE)
BaresipService.messages.removeAt(firstIndex)
}
companion object {
val MESSAGE_HISTORY_SIZE = 100
@@ -15,22 +31,6 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
return BaresipService.messages
}
fun add(message: Message) {
BaresipService.messages.add(message)
var count = 0
var firstIndex = -1
for (i in BaresipService.messages.indices)
if (BaresipService.messages[i].aor == message.aor) {
if (count == 0) firstIndex = i
count++
if (count > MESSAGE_HISTORY_SIZE) {
break
}
}
if (count > MESSAGE_HISTORY_SIZE)
BaresipService.messages.removeAt(firstIndex)
}
fun clear(aor: String) {
val it = BaresipService.messages.iterator()
while (it.hasNext()) if (it.next().aor == aor) it.remove()