Skip to content

Commit

Permalink
Update BlockBlogUseCase.kt
Browse files Browse the repository at this point in the history
fix some problems
  • Loading branch information
Agoni-0 authored Oct 24, 2024
1 parent 96bdc5c commit 9093a7f
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ class BlockBlogUseCase @Inject constructor(
feedId: Long
) = flow {
performAction(blogId, feedId)
// Blocking multiple sites in parallel isn't supported as the user would lose the ability to undo the action
// if (continuation == null) {
// if (!networkUtilsWrapper.isNetworkAvailable()) {
// emit(NoNetwork)
// } else {
// performAction(blogId, feedId)
// }
// } else {
// emit(AlreadyRunning)
// }
if (continuation == null) {
if (!networkUtilsWrapper.isNetworkAvailable()) {
emit(NoNetwork)
} else {
performAction(blogId, feedId)
}
} else {
emit(AlreadyRunning)
}
}

private suspend fun FlowCollector<BlockSiteState>.performAction(
Expand All @@ -56,13 +55,13 @@ class BlockBlogUseCase @Inject constructor(
val blockedBlogData = readerBlogActionsWrapper.blockBlogFromReaderLocal(blogId, feedId)
emit(SiteBlockedInLocalDb(blockedBlogData))

// val succeeded = blockBlogAndWaitForResult(blockedBlogData)
//
// if (succeeded) {
// emit(Success)
// } else {
// emit(RequestFailed)
// }
val succeeded = blockBlogAndWaitForResult(blockedBlogData)

if (succeeded) {
emit(Success)
} else {
emit(RequestFailed)
}
}

private suspend fun blockBlogAndWaitForResult(blockedBlogResult: BlockedBlogResult): Boolean {
Expand Down

0 comments on commit 9093a7f

Please sign in to comment.