Skip to content

Commit

Permalink
Cancel in-flight delayed message jobs when manually seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed May 9, 2021
1 parent a196c24 commit 95a9ded
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/src/main/kotlin/com/livetl/android/data/chat/ChatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ChatService(
// Clear out messages if we seem to be manually seeking
if (currentSecond - 10 > second || second > currentSecond + 10) {
Timber.d("$videoId: manual seek")
_messages.value = emptyList()
clearMessages()
}

currentSecond = second
Expand All @@ -90,8 +90,7 @@ class ChatService(

fun stop() {
webview.loadUrl("")
jobs.forEach { it.cancel() }
_messages.value = emptyList()
clearMessages()
}

@ExperimentalTime
Expand Down Expand Up @@ -156,6 +155,11 @@ class ChatService(
Timber.d("Now: $now (${now.toDebugTimestampString()}), time: $microseconds (${microseconds.toDebugTimestampString()}), diff: $diff")
return diff
}

private fun clearMessages() {
jobs.forEach { it.cancel() }
_messages.value = emptyList()
}
}

class NoChatContinuationFoundException(videoId: String) : Exception("Continuation not found for $videoId")
Expand Down

0 comments on commit 95a9ded

Please sign in to comment.