Improve code #2

This commit is contained in:
Benoit Marty 2021-01-22 17:37:25 +01:00
parent 07ffd3ded3
commit 887da0a3d6

View File

@ -63,7 +63,8 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
val pepper = identityData.hashLookupPepper val pepper = identityData.hashLookupPepper
val hashDetailResponse = if (pepper == null) { val hashDetailResponse = if (pepper == null) {
// We need to fetch the hash details first // We need to fetch the hash details first
fetchAndStoreHashDetails(identityAPI) fetchHashDetails(identityAPI)
.also { identityStore.setHashDetails(it) }
} else { } else {
IdentityHashDetailResponse(pepper, identityData.hashLookupAlgorithm) IdentityHashDetailResponse(pepper, identityData.hashLookupAlgorithm)
} }
@ -101,11 +102,11 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
val newHashDetailResponse = if (!failure.error.newLookupPepper.isNullOrEmpty()) { val newHashDetailResponse = if (!failure.error.newLookupPepper.isNullOrEmpty()) {
// Store it and use it right now // Store it and use it right now
hashDetailResponse.copy(pepper = failure.error.newLookupPepper) hashDetailResponse.copy(pepper = failure.error.newLookupPepper)
.also { identityStore.setHashDetails(it) }
} else { } else {
// Retrieve the new hash details // Retrieve the new hash details
fetchAndStoreHashDetails(identityAPI) fetchHashDetails(identityAPI)
} }
.also { identityStore.setHashDetails(it) }
if (newHashDetailResponse.algorithms.contains(IdentityHashDetailResponse.ALGORITHM_SHA256).not()) { 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 // 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 throw IdentityServiceError.BulkLookupSha256NotSupported
@ -118,11 +119,10 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
} }
} }
private suspend fun fetchAndStoreHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse { private suspend fun fetchHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse {
return executeRequest<IdentityHashDetailResponse>(null) { return executeRequest(null) {
apiCall = identityAPI.hashDetails() apiCall = identityAPI.hashDetails()
} }
.also { identityStore.setHashDetails(it) }
} }
private fun handleSuccess(threePids: List<ThreePid>, hashedAddresses: List<String>, identityLookUpResponse: IdentityLookUpResponse): List<FoundThreePid> { private fun handleSuccess(threePids: List<ThreePid>, hashedAddresses: List<String>, identityLookUpResponse: IdentityLookUpResponse): List<FoundThreePid> {