mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 14:50:30 +05:30
fix: duplicated comments (#4422)
This commit is contained in:
parent
d532344c77
commit
8230c7598a
@ -98,6 +98,11 @@ class CommentsMainFragment : Fragment() {
|
|||||||
binding.errorTV.isVisible = true
|
binding.errorTV.isVisible = true
|
||||||
return@observe
|
return@observe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sometimes the received comments have the same size as the existing ones
|
||||||
|
// which causes comments.subList to throw InvalidArgumentException
|
||||||
|
if (commentsAdapter.itemCount > it.comments.size) return@observe
|
||||||
|
|
||||||
commentsAdapter.updateItems(
|
commentsAdapter.updateItems(
|
||||||
// only add the new comments to the recycler view
|
// only add the new comments to the recycler view
|
||||||
it.comments.subList(commentsAdapter.itemCount, it.comments.size)
|
it.comments.subList(commentsAdapter.itemCount, it.comments.size)
|
||||||
|
@ -56,9 +56,13 @@ class CommentsViewModel : ViewModel() {
|
|||||||
Log.e(TAG(), e.toString())
|
Log.e(TAG(), e.toString())
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
val updatedPage = commentsPage.value?.apply {
|
val updatedPage = commentsPage.value?.apply {
|
||||||
comments += response.comments.filterNonEmptyComments()
|
comments += response.comments
|
||||||
|
.filterNonEmptyComments()
|
||||||
|
.filter { comment -> comments.none { it.commentId == comment.commentId } }
|
||||||
}
|
}
|
||||||
|
|
||||||
nextPage = response.nextpage
|
nextPage = response.nextpage
|
||||||
commentsPage.postValue(updatedPage)
|
commentsPage.postValue(updatedPage)
|
||||||
isLoading = false
|
isLoading = false
|
||||||
|
Loading…
Reference in New Issue
Block a user