Skip to content

Commit

Permalink
Improve code #2
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Jan 22, 2021
1 parent 07ffd3d commit 887da0a
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
val pepper = identityData.hashLookupPepper
val hashDetailResponse = if (pepper == null) {
// We need to fetch the hash details first
fetchAndStoreHashDetails(identityAPI)
fetchHashDetails(identityAPI)
.also { identityStore.setHashDetails(it) }
} else {
IdentityHashDetailResponse(pepper, identityData.hashLookupAlgorithm)
}
Expand Down Expand Up @@ -101,11 +102,11 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
val newHashDetailResponse = if (!failure.error.newLookupPepper.isNullOrEmpty()) {
// Store it and use it right now
hashDetailResponse.copy(pepper = failure.error.newLookupPepper)
.also { identityStore.setHashDetails(it) }
} else {
// Retrieve the new hash details
fetchAndStoreHashDetails(identityAPI)
fetchHashDetails(identityAPI)
}
.also { identityStore.setHashDetails(it) }
if (newHashDetailResponse.algorithms.contains(IdentityHashDetailResponse.ALGORITHM_SHA256).not()) {
// TODO We should ask the user if he is ok to send their 3Pid in clear, but for the moment we do not do it
throw IdentityServiceError.BulkLookupSha256NotSupported
Expand All @@ -118,11 +119,10 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
}
}

private suspend fun fetchAndStoreHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse {
return executeRequest<IdentityHashDetailResponse>(null) {
private suspend fun fetchHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse {
return executeRequest(null) {
apiCall = identityAPI.hashDetails()
}
.also { identityStore.setHashDetails(it) }
}

private fun handleSuccess(threePids: List<ThreePid>, hashedAddresses: List<String>, identityLookUpResponse: IdentityLookUpResponse): List<FoundThreePid> {
Expand Down

0 comments on commit 887da0a

Please sign in to comment.