From 3b1f0bc7bb31d223d46ebbd4ab23f1a127fe91a6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 31 Mar 2025 15:04:17 +0200 Subject: [PATCH] fix: comment count doesn't reset to 0 if comments disabled --- .../libretube/ui/models/sources/CommentPagingSource.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/models/sources/CommentPagingSource.kt b/app/src/main/java/com/github/libretube/ui/models/sources/CommentPagingSource.kt index 38f2a8298..25b1e760c 100644 --- a/app/src/main/java/com/github/libretube/ui/models/sources/CommentPagingSource.kt +++ b/app/src/main/java/com/github/libretube/ui/models/sources/CommentPagingSource.kt @@ -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)