fix: comment count doesn't reset to 0 if comments disabled

This commit is contained in:
Bnyro 2025-03-31 15:04:17 +02:00
parent ef2c07bf03
commit 3b1f0bc7bb
No known key found for this signature in database

View File

@ -18,11 +18,14 @@ class CommentPagingSource(
val result = withContext(Dispatchers.IO) {
params.key?.let {
MediaServiceRepository.instance.getCommentsNextPage(videoId, it)
} ?: MediaServiceRepository.instance.getComments(videoId)
} ?: MediaServiceRepository.instance.getComments(videoId).also {
// avoid negative comment counts, i.e. because they're disabled
withContext(Dispatchers.Main) {
onCommentCount(maxOf(0, it.commentCount))
}
}
}
if (result.commentCount > 0) onCommentCount(result.commentCount)
LoadResult.Page(result.comments, null, result.nextpage)
} catch (e: Exception) {
LoadResult.Error(e)