From 95a9ded16a6023cc18a75f5c43e9290a6bd4e89f Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 9 May 2021 11:27:31 -0400 Subject: [PATCH] Cancel in-flight delayed message jobs when manually seeking --- .../kotlin/com/livetl/android/data/chat/ChatService.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/livetl/android/data/chat/ChatService.kt b/app/src/main/kotlin/com/livetl/android/data/chat/ChatService.kt index d796c89..74831e6 100644 --- a/app/src/main/kotlin/com/livetl/android/data/chat/ChatService.kt +++ b/app/src/main/kotlin/com/livetl/android/data/chat/ChatService.kt @@ -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 @@ -90,8 +90,7 @@ class ChatService( fun stop() { webview.loadUrl("") - jobs.forEach { it.cancel() } - _messages.value = emptyList() + clearMessages() } @ExperimentalTime @@ -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")