Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing deduplication guard on profile #1269

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 10 additions & 28 deletions app/src/main/java/com/jerboa/feat/AccountVerificationState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ suspend fun checkIfSiteRetrievalSucceeded(
}

sealed class CheckState {
object Passed : CheckState()
object Failed : FailedMsg()
object ConnectionFailed : ConnectionFailedMsg()
data object Passed : CheckState()
data object Failed : FailedMsg()
data object ConnectionFailed : ConnectionFailedMsg()

open class ConnectionFailedMsg(val msg: String = "") : CheckState()
open class FailedMsg(val msg: String = "") : CheckState()
Expand Down Expand Up @@ -235,36 +235,17 @@ suspend fun Account.checkAccountVerification(
// Anon account does not do any checks
CheckState.from(this.id != -1)
}

AccountVerificationState.HAS_INTERNET -> {
checkInternet(ctx)
}

AccountVerificationState.INSTANCE_ALIVE -> {
checkInstance(this.instance)
}

AccountVerificationState.HAS_INTERNET -> checkInternet(ctx)
AccountVerificationState.INSTANCE_ALIVE -> checkInstance(this.instance)
AccountVerificationState.ACCOUNT_DELETED -> {
val p = checkIfAccountIsDeleted(this, api)
userRes = p.second
p.first
}

AccountVerificationState.ACCOUNT_BANNED -> {
checkIfAccountIsBanned(userRes!!.data)
}

AccountVerificationState.JWT_VERIFIED -> {
checkIfJWTValid(this, api)
}

AccountVerificationState.SITE_RETRIEVAL_SUCCEEDED -> {
checkIfSiteRetrievalSucceeded(siteViewModel, this).first
}

AccountVerificationState.CHECKS_COMPLETE -> {
CheckState.Passed
}
AccountVerificationState.ACCOUNT_BANNED -> checkIfAccountIsBanned(userRes!!.data)
AccountVerificationState.JWT_VERIFIED -> checkIfJWTValid(this, api)
AccountVerificationState.SITE_RETRIEVAL_SUCCEEDED -> checkIfSiteRetrievalSucceeded(siteViewModel, this).first
AccountVerificationState.CHECKS_COMPLETE -> CheckState.Passed
}

Log.d("verification", "Verified ${verifyState.name} with ${checkState::class.simpleName}")
Expand Down Expand Up @@ -487,6 +468,7 @@ suspend fun SnackbarHostState.doSnackbarAction(
actionPerform: suspend () -> Unit,
duration: SnackbarDuration = SnackbarDuration.Long,
) {
Log.d("verification", "Showing snackbar action with [$msg]")
if (this.showSnackbar(msg, btnText, true, duration) == SnackbarResult.ActionPerformed) {
actionPerform()
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.jerboa.db.entity.Account
import com.jerboa.db.entity.getJWT
import com.jerboa.findAndUpdateComment
import com.jerboa.findAndUpdatePost
import com.jerboa.getDeduplicateMerge
import com.jerboa.serializeToMap
import com.jerboa.showBlockCommunityToast
import com.jerboa.showBlockPersonToast
Expand Down Expand Up @@ -140,11 +141,10 @@ class PersonProfileViewModel(personArg: Either<PersonId, String>, savedMode: Boo

personDetailsRes = when (newRes) {
is ApiState.Success -> {
val appendedPosts = oldRes.data.posts.toMutableList()
appendedPosts.addAll(newRes.data.posts)

val appendedComments = oldRes.data.comments.toMutableList()
appendedComments.addAll(newRes.data.comments)
val appendedPosts = getDeduplicateMerge(oldRes.data.posts, newRes.data.posts) { it.post.id }
val appendedComments = getDeduplicateMerge(
oldRes.data.comments, newRes.data.comments,
) { it.comment.id }

ApiState.Success(
oldRes.data.copy(
Expand Down