Skip to content

Commit 3b1f0bc

Browse files
committed
fix: comment count doesn't reset to 0 if comments disabled
1 parent ef2c07b commit 3b1f0bc

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

app/src/main/java/com/github/libretube/ui/models/sources/CommentPagingSource.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ class CommentPagingSource(
1818
val result = withContext(Dispatchers.IO) {
1919
params.key?.let {
2020
MediaServiceRepository.instance.getCommentsNextPage(videoId, it)
21-
} ?: MediaServiceRepository.instance.getComments(videoId)
21+
} ?: MediaServiceRepository.instance.getComments(videoId).also {
22+
// avoid negative comment counts, i.e. because they're disabled
23+
withContext(Dispatchers.Main) {
24+
onCommentCount(maxOf(0, it.commentCount))
25+
}
26+
}
2227
}
2328

24-
if (result.commentCount > 0) onCommentCount(result.commentCount)
25-
2629
LoadResult.Page(result.comments, null, result.nextpage)
2730
} catch (e: Exception) {
2831
LoadResult.Error(e)

0 commit comments

Comments
 (0)