Filter out null comments returned from Piped API. (#3061)

* Made improvement to player double-tap further.

* Minor fixes.

* fix ktlint

* Filter out null comments returned from Piped API.
This commit is contained in:
Faisal Khan 2023-02-13 22:38:56 +05:30 committed by GitHub
parent 582ab70bd1
commit 6053eae99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,7 @@
package com.github.libretube.ui.extensions
import com.github.libretube.api.obj.Comment
fun List<Comment>.filterNonEmptyComments(): List<Comment> {
return filter { !it.commentText.isNullOrEmpty() }
}

View File

@ -17,6 +17,7 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentCommentsBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.ui.adapters.CommentsAdapter
import com.github.libretube.ui.extensions.filterNonEmptyComments
import com.github.libretube.ui.models.CommentsViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -97,6 +98,7 @@ class CommentsRepliesFragment : Fragment() {
Log.e(TAG(), "IOException, you might not have internet connection")
return@launch
}
repliesPage.comments = repliesPage.comments.filterNonEmptyComments()
withContext(Dispatchers.Main) {
onFinished.invoke(repliesPage)
}

View File

@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.CommentsPage
import com.github.libretube.extensions.TAG
import com.github.libretube.ui.extensions.filterNonEmptyComments
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -33,6 +34,7 @@ class CommentsViewModel : ViewModel() {
return@launch
}
nextPage = response.nextpage
response.comments = response.comments.filterNonEmptyComments()
commentsPage.postValue(response)
isLoading = false
}
@ -49,7 +51,7 @@ class CommentsViewModel : ViewModel() {
return@launch
}
val updatedPage = commentsPage.value?.apply {
comments += response.comments
comments += response.comments.filterNonEmptyComments()
}
nextPage = response.nextpage
commentsPage.postValue(updatedPage)