kopia lustrzana https://github.com/ryukoposting/Signal-Android
Implement several badge job tweaks to align with iOS.
rodzic
3e358da83a
commit
0d4e109c72
|
@ -1,5 +1,7 @@
|
|||
package org.thoughtcrime.securesms.jobs;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
@ -19,7 +21,7 @@ import org.thoughtcrime.securesms.jobmanager.Data;
|
|||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.subscription.SubscriptionNotification;
|
||||
import org.thoughtcrime.securesms.subscription.DonorBadgeNotifications;
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -43,13 +45,15 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
|
|||
|
||||
private final String paymentIntentId;
|
||||
|
||||
private boolean isPaymentFailure;
|
||||
|
||||
static BoostReceiptRequestResponseJob createJob(StripeApi.PaymentIntent paymentIntent) {
|
||||
return new BoostReceiptRequestResponseJob(
|
||||
new Parameters
|
||||
.Builder()
|
||||
.addConstraint(NetworkConstraint.KEY)
|
||||
.setQueue("BoostReceiptRedemption")
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(30))
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
||||
.setMaxAttempts(Parameters.UNLIMITED)
|
||||
.build(),
|
||||
null,
|
||||
|
@ -95,7 +99,7 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
|
|||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
SubscriptionNotification.VerificationFailed.INSTANCE.show(context);
|
||||
DonorBadgeNotifications.RedemptionFailed.INSTANCE.show(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,6 +122,7 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
|
|||
|
||||
if (response.getApplicationError().isPresent()) {
|
||||
handleApplicationError(response);
|
||||
setOutputData(new Data.Builder().putBoolean(DonationReceiptRedemptionJob.INPUT_PAYMENT_FAILURE, true).build());
|
||||
} else if (response.getResult().isPresent()) {
|
||||
ReceiptCredential receiptCredential = getReceiptCredential(response.getResult().get());
|
||||
|
||||
|
@ -139,11 +144,14 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
|
|||
Throwable applicationException = response.getApplicationError().get();
|
||||
switch (response.getStatus()) {
|
||||
case 204:
|
||||
Log.w(TAG, "User does not have receipts available to exchange. Exiting.", applicationException, true);
|
||||
break;
|
||||
Log.w(TAG, "User payment not be completed yet.", applicationException, true);
|
||||
throw new RetryableException();
|
||||
case 400:
|
||||
Log.w(TAG, "Receipt credential request failed to validate.", applicationException, true);
|
||||
throw new Exception(applicationException);
|
||||
case 402:
|
||||
Log.w(TAG, "User payment failed.", applicationException, true);
|
||||
break;
|
||||
case 409:
|
||||
Log.w(TAG, "Receipt already redeemed with a different request credential.", response.getApplicationError().get(), true);
|
||||
throw new Exception(applicationException);
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.thoughtcrime.securesms.jobmanager.Data;
|
|||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.subscription.SubscriptionNotification;
|
||||
import org.thoughtcrime.securesms.subscription.DonorBadgeNotifications;
|
||||
import org.whispersystems.signalservice.internal.EmptyResponse;
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse;
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class DonationReceiptRedemptionJob extends BaseJob {
|
|||
public static final String SUBSCRIPTION_QUEUE = "ReceiptRedemption";
|
||||
public static final String KEY = "DonationReceiptRedemptionJob";
|
||||
public static final String INPUT_RECEIPT_CREDENTIAL_PRESENTATION = "data.receipt.credential.presentation";
|
||||
public static final String INPUT_PAYMENT_FAILURE = "data.payment.failure";
|
||||
|
||||
public static DonationReceiptRedemptionJob createJobForSubscription() {
|
||||
return new DonationReceiptRedemptionJob(
|
||||
|
@ -36,7 +37,7 @@ public class DonationReceiptRedemptionJob extends BaseJob {
|
|||
.setQueue(SUBSCRIPTION_QUEUE)
|
||||
.setMaxAttempts(Parameters.UNLIMITED)
|
||||
.setMaxInstancesForQueue(1)
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(7))
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,7 @@ public class DonationReceiptRedemptionJob extends BaseJob {
|
|||
.addConstraint(NetworkConstraint.KEY)
|
||||
.setQueue("BoostReceiptRedemption")
|
||||
.setMaxAttempts(Parameters.UNLIMITED)
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(30))
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,14 @@ public class DonationReceiptRedemptionJob extends BaseJob {
|
|||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
SubscriptionNotification.RedemptionFailed.INSTANCE.show(context);
|
||||
Data inputData = getInputData();
|
||||
|
||||
if (inputData != null && inputData.getBooleanOrDefault(INPUT_PAYMENT_FAILURE, false)) {
|
||||
DonorBadgeNotifications.PaymentFailed.INSTANCE.show(context);
|
||||
} else {
|
||||
DonorBadgeNotifications.RedemptionFailed.INSTANCE.show(context);
|
||||
}
|
||||
|
||||
if (isForSubscription()) {
|
||||
SignalStore.donationsValues().markSubscriptionRedemptionFailed();
|
||||
}
|
||||
|
@ -82,6 +90,10 @@ public class DonationReceiptRedemptionJob extends BaseJob {
|
|||
return;
|
||||
}
|
||||
|
||||
if (inputData.getBooleanOrDefault(INPUT_PAYMENT_FAILURE, false)) {
|
||||
throw new Exception("Payment failed.");
|
||||
}
|
||||
|
||||
byte[] presentationBytes = inputData.getStringAsBlob(INPUT_RECEIPT_CREDENTIAL_PRESENTATION);
|
||||
if (presentationBytes == null) {
|
||||
Log.d(TAG, "No response data. Exiting.", null, true);
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.thoughtcrime.securesms.jobmanager.JobManager;
|
|||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.subscription.Subscriber;
|
||||
import org.thoughtcrime.securesms.subscription.SubscriptionNotification;
|
||||
import org.thoughtcrime.securesms.subscription.DonorBadgeNotifications;
|
||||
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription;
|
||||
import org.whispersystems.signalservice.api.subscriptions.SubscriberId;
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse;
|
||||
|
@ -55,7 +55,7 @@ public class SubscriptionReceiptRequestResponseJob extends BaseJob {
|
|||
.addConstraint(NetworkConstraint.KEY)
|
||||
.setQueue("ReceiptRedemption")
|
||||
.setMaxInstancesForQueue(1)
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(7))
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
||||
.setMaxAttempts(Parameters.UNLIMITED)
|
||||
.build(),
|
||||
null,
|
||||
|
@ -102,7 +102,7 @@ public class SubscriptionReceiptRequestResponseJob extends BaseJob {
|
|||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
SubscriptionNotification.VerificationFailed.INSTANCE.show(context);
|
||||
DonorBadgeNotifications.RedemptionFailed.INSTANCE.show(context);
|
||||
SignalStore.donationsValues().markSubscriptionRedemptionFailed();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ public final class NotificationIds {
|
|||
public static final int USER_NOTIFICATION_MIGRATION = 525600;
|
||||
public static final int DEVICE_TRANSFER = 625420;
|
||||
public static final int SUBSCRIPTION_VERIFY_FAILED = 630001;
|
||||
public static final int BOOST_PAYMENT_FAILED = 630002;
|
||||
|
||||
private NotificationIds() { }
|
||||
|
||||
|
|
|
@ -11,34 +11,8 @@ import org.thoughtcrime.securesms.help.HelpFragment
|
|||
import org.thoughtcrime.securesms.notifications.NotificationChannels
|
||||
import org.thoughtcrime.securesms.notifications.NotificationIds
|
||||
|
||||
sealed class SubscriptionNotification {
|
||||
object VerificationFailed : SubscriptionNotification() {
|
||||
override fun show(context: Context) {
|
||||
val notification = NotificationCompat.Builder(context, NotificationChannels.FAILURES)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getString(R.string.Subscription__verification_failed))
|
||||
.setContentText(context.getString(R.string.Subscription__please_contact_support_for_more_information))
|
||||
.addAction(
|
||||
NotificationCompat.Action.Builder(
|
||||
null,
|
||||
context.getString(R.string.Subscription__contact_support),
|
||||
PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
AppSettingsActivity.help(context, HelpFragment.DONATION_INDEX),
|
||||
if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_ONE_SHOT else 0
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.build()
|
||||
|
||||
NotificationManagerCompat
|
||||
.from(context)
|
||||
.notify(NotificationIds.SUBSCRIPTION_VERIFY_FAILED, notification)
|
||||
}
|
||||
}
|
||||
|
||||
object RedemptionFailed : SubscriptionNotification() {
|
||||
sealed class DonorBadgeNotifications {
|
||||
object RedemptionFailed : DonorBadgeNotifications() {
|
||||
override fun show(context: Context) {
|
||||
val notification = NotificationCompat.Builder(context, NotificationChannels.FAILURES)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
|
@ -64,5 +38,31 @@ sealed class SubscriptionNotification {
|
|||
}
|
||||
}
|
||||
|
||||
object PaymentFailed : DonorBadgeNotifications() {
|
||||
override fun show(context: Context) {
|
||||
val notification = NotificationCompat.Builder(context, NotificationChannels.FAILURES)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getString(R.string.DonationsErrors__payment_failed))
|
||||
.setContentText(context.getString(R.string.Subscription__please_contact_support_for_more_information))
|
||||
.addAction(
|
||||
NotificationCompat.Action.Builder(
|
||||
null,
|
||||
context.getString(R.string.Subscription__contact_support),
|
||||
PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
AppSettingsActivity.help(context, HelpFragment.DONATION_INDEX),
|
||||
if (Build.VERSION.SDK_INT >= 23) PendingIntent.FLAG_ONE_SHOT else 0
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.build()
|
||||
|
||||
NotificationManagerCompat
|
||||
.from(context)
|
||||
.notify(NotificationIds.SUBSCRIPTION_VERIFY_FAILED, notification)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun show(context: Context)
|
||||
}
|
Ładowanie…
Reference in New Issue