chore: avoid showing read post after "clear read" option

This commit is contained in:
Diego Beraldin 2023-10-23 18:55:46 +02:00
parent e4ec9e6606
commit 6c8d335394
2 changed files with 18 additions and 0 deletions

View File

@ -38,6 +38,7 @@ class CommunityDetailViewModel(
private var currentPage: Int = 1
private var pageCursor: String? = null
private var hideReadPosts = false
override fun onStarted() {
mvi.onStarted()
@ -120,6 +121,7 @@ class CommunityDetailViewModel(
private fun refresh() {
currentPage = 1
pageCursor = null
hideReadPosts = false
mvi.updateState { it.copy(canFetchMore = true, refreshing = true) }
val auth = identityRepository.authToken.value
mvi.scope?.launch(Dispatchers.IO) {
@ -177,6 +179,12 @@ class CommunityDetailViewModel(
pageCursor = pageCursor,
sort = sort,
)
}?.let {
if (hideReadPosts) {
it.copy(first = it.first.filter { p -> !p.read })
} else {
it
}
}?.let {
if (refreshing) {
it
@ -470,6 +478,7 @@ class CommunityDetailViewModel(
}
private fun clearRead() {
hideReadPosts = true
mvi.updateState {
val newPosts = it.posts.filter { e -> !e.read }
it.copy(

View File

@ -42,6 +42,7 @@ class PostListViewModel(
private var currentPage: Int = 1
private var pageCursor: String? = null
private var firstLoad = true
private var hideReadPosts = false
init {
notificationCenter.addObserver({
@ -158,6 +159,7 @@ class PostListViewModel(
private fun refresh() {
currentPage = 1
pageCursor = null
hideReadPosts = false
mvi.updateState { it.copy(canFetchMore = true, refreshing = true) }
loadNextPage()
}
@ -183,6 +185,12 @@ class PostListViewModel(
type = type,
sort = sort,
)?.let {
if (hideReadPosts) {
it.copy(first = it.first.filter { p -> !p.read })
} else {
it
}
}?.let {
if (refreshing) {
it
} else {
@ -459,6 +467,7 @@ class PostListViewModel(
}
private fun clearRead() {
hideReadPosts = true
mvi.updateState {
val newPosts = it.posts.filter { e -> !e.read }
it.copy(