Remove blocking get from donation jobs.

This commit is contained in:
Alex Hart
2022-07-28 15:54:49 -03:00
committed by Greyson Parrelli
parent 8f12b2041a
commit f50bf3e9c2
17 changed files with 214 additions and 183 deletions

View File

@@ -18,8 +18,11 @@ import java.util.Locale
class GiftFlowRepository {
fun getGiftBadge(): Single<Pair<Long, Badge>> {
return ApplicationDependencies.getDonationsService()
.getGiftBadges(Locale.getDefault())
return Single
.fromCallable {
ApplicationDependencies.getDonationsService()
.getGiftBadges(Locale.getDefault())
}
.flatMap(ServiceResponse<Map<Long, SignalServiceProfile.Badge>>::flattenResult)
.map { gifts -> gifts.map { it.key to Badges.fromServiceBadge(it.value) } }
.map { it.first() }
@@ -27,8 +30,11 @@ class GiftFlowRepository {
}
fun getGiftPricing(): Single<Map<Currency, FiatMoney>> {
return ApplicationDependencies.getDonationsService()
.giftAmount
return Single
.fromCallable {
ApplicationDependencies.getDonationsService()
.giftAmount
}
.subscribeOn(Schedulers.io())
.flatMap { it.flattenResult() }
.map { result ->

View File

@@ -19,9 +19,12 @@ import java.util.Locale
class ViewGiftRepository {
fun getBadge(giftBadge: GiftBadge): Single<Badge> {
val presentation = ReceiptCredentialPresentation(giftBadge.redemptionToken.toByteArray())
return ApplicationDependencies
.getDonationsService()
.getGiftBadge(Locale.getDefault(), presentation.receiptLevel)
return Single
.fromCallable {
ApplicationDependencies
.getDonationsService()
.getGiftBadge(Locale.getDefault(), presentation.receiptLevel)
}
.flatMap { it.flattenResult() }
.map { Badges.fromServiceBadge(it) }
.subscribeOn(Schedulers.io())