From 6c8d3353949e778f1e8b1175e3222a39f1836813 Mon Sep 17 00:00:00 2001 From: Diego Beraldin Date: Mon, 23 Oct 2023 18:55:46 +0200 Subject: [PATCH] chore: avoid showing read post after "clear read" option --- .../commonui/communitydetail/CommunityDetailViewModel.kt | 9 +++++++++ .../feature/home/postlist/PostListViewModel.kt | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/communitydetail/CommunityDetailViewModel.kt b/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/communitydetail/CommunityDetailViewModel.kt index d92d7cd2e..f7bef3150 100644 --- a/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/communitydetail/CommunityDetailViewModel.kt +++ b/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/communitydetail/CommunityDetailViewModel.kt @@ -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( diff --git a/feature-home/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/home/postlist/PostListViewModel.kt b/feature-home/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/home/postlist/PostListViewModel.kt index d793a1030..d71993612 100644 --- a/feature-home/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/home/postlist/PostListViewModel.kt +++ b/feature-home/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/home/postlist/PostListViewModel.kt @@ -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(