Skip to content

Commit

Permalink
fix vod chat double messages
Browse files Browse the repository at this point in the history
(cherry picked from commit ca3d443)
  • Loading branch information
crackededed committed Dec 10, 2024
1 parent b3065df commit 14a5fd9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
minSdk = 16
targetSdk = 35
versionCode = 121
versionName = "2.40.0"
versionName = "2.40.1"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
Expand Down Expand Up @@ -116,9 +117,7 @@ class ChatReplayManager @Inject constructor(
}

private fun startJob() {
coroutineScope.launch(Dispatchers.IO) {
messageJob?.join()
messageJob = this as Job
messageJob = coroutineScope.launch(Dispatchers.IO) {
while (isActive) {
val message = list.firstOrNull() ?: break
if (message.offsetSeconds != null) {
Expand All @@ -127,6 +126,9 @@ class ChatReplayManager @Inject constructor(
while (((runBlocking(Dispatchers.Main) { getCurrentPosition() } ?: 0).also { lastCheckedPosition = it } + startTime).also { currentPosition = it } < messageOffset) {
delay(max((messageOffset - currentPosition).div(playbackSpeed ?: 1f).toLong(), 0))
}
if (!isActive) {
break
}
messageListener.onMessage(ChatMessage(
id = message.id,
userId = message.userId,
Expand All @@ -142,7 +144,7 @@ class ChatReplayManager @Inject constructor(
if (list.size <= 25 && !cursor.isNullOrBlank() && !isLoading) {
load()
}
}
} else if (!isActive) break
list.remove(message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class ChatReplayManagerLocal @Inject constructor(
while (((runBlocking(Dispatchers.Main) { getCurrentPosition() } ?: 0).also { lastCheckedPosition = it } + startTime).also { currentPosition = it } < messageOffset) {
delay(max((messageOffset - currentPosition).div(playbackSpeed ?: 1f).toLong(), 0))
}
if (!isActive) {
break
}
messageListener.onMessage(ChatMessage(
id = message.id,
userId = message.userId,
Expand All @@ -83,7 +86,7 @@ class ChatReplayManagerLocal @Inject constructor(
reward = message.reward,
fullMsg = message.fullMsg
))
}
} else if (!isActive) break
list.remove(message)
}
}
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ draglistview = "1.7.3"
fragment = "1.8.5"
glide = "4.16.0"
glide-webpdecoder = "2.6.4.16.0"
hilt = "2.52"
hilt = "2.53.1"
hilt-extension-compiler = "1.2.0"
hilt-work = "1.2.0"
kotlin = "2.0.21"
ksp = "2.0.21-1.0.26"
kotlin = "2.1.0"
ksp = "2.1.0-1.0.29"
lifecycle = "2.8.7"
material = "1.12.0"
media3 = "1.5.0"
Expand Down

0 comments on commit 14a5fd9

Please sign in to comment.