use of org.thoughtcrime.securesms.subscription.Subscriber in project Signal-Android by WhisperSystems.
the class SubscriptionKeepAliveJob method onRun.
@Override
protected void onRun() throws Exception {
Subscriber subscriber = SignalStore.donationsValues().getSubscriber();
if (subscriber == null) {
return;
}
ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().putSubscription(subscriber.getSubscriberId()).blockingGet();
verifyResponse(response);
Log.i(TAG, "Successful call to PUT subscription ID", true);
ServiceResponse<ActiveSubscription> activeSubscriptionResponse = ApplicationDependencies.getDonationsService().getSubscription(subscriber.getSubscriberId()).blockingGet();
verifyResponse(activeSubscriptionResponse);
Log.i(TAG, "Successful call to GET active subscription", true);
ActiveSubscription activeSubscription = activeSubscriptionResponse.getResult().get();
if (activeSubscription.getActiveSubscription() == null || !activeSubscription.getActiveSubscription().isActive()) {
Log.i(TAG, "User does not have an active subscription. Exiting.", true);
return;
}
if (activeSubscription.getActiveSubscription().getEndOfCurrentPeriod() > SignalStore.donationsValues().getLastEndOfPeriod()) {
Log.i(TAG, String.format(Locale.US, "Last end of period change. Requesting receipt refresh. (old: %d to new: %d)", SignalStore.donationsValues().getLastEndOfPeriod(), activeSubscription.getActiveSubscription().getEndOfCurrentPeriod()), true);
SubscriptionReceiptRequestResponseJob.createSubscriptionContinuationJobChain(true).enqueue();
}
}
use of org.thoughtcrime.securesms.subscription.Subscriber in project Signal-Android by signalapp.
the class SubscriptionReceiptRequestResponseJob method createSubscriptionContinuationJobChain.
public static JobManager.Chain createSubscriptionContinuationJobChain(boolean isForKeepAlive) {
Subscriber subscriber = SignalStore.donationsValues().requireSubscriber();
SubscriptionReceiptRequestResponseJob requestReceiptJob = createJob(subscriber.getSubscriberId(), isForKeepAlive);
DonationReceiptRedemptionJob redeemReceiptJob = DonationReceiptRedemptionJob.createJobForSubscription(requestReceiptJob.getErrorSource());
RefreshOwnProfileJob refreshOwnProfileJob = RefreshOwnProfileJob.forSubscription();
return ApplicationDependencies.getJobManager().startChain(requestReceiptJob).then(redeemReceiptJob).then(refreshOwnProfileJob);
}
use of org.thoughtcrime.securesms.subscription.Subscriber in project Signal-Android by WhisperSystems.
the class SubscriptionReceiptRequestResponseJob method createSubscriptionContinuationJobChain.
public static JobManager.Chain createSubscriptionContinuationJobChain(boolean isForKeepAlive) {
Subscriber subscriber = SignalStore.donationsValues().requireSubscriber();
SubscriptionReceiptRequestResponseJob requestReceiptJob = createJob(subscriber.getSubscriberId(), isForKeepAlive);
DonationReceiptRedemptionJob redeemReceiptJob = DonationReceiptRedemptionJob.createJobForSubscription(requestReceiptJob.getErrorSource());
RefreshOwnProfileJob refreshOwnProfileJob = RefreshOwnProfileJob.forSubscription();
return ApplicationDependencies.getJobManager().startChain(requestReceiptJob).then(redeemReceiptJob).then(refreshOwnProfileJob);
}
use of org.thoughtcrime.securesms.subscription.Subscriber in project Signal-Android by WhisperSystems.
the class StorageSyncHelper method applyAccountStorageSyncUpdates.
public static void applyAccountStorageSyncUpdates(@NonNull Context context, @NonNull Recipient self, @NonNull StorageRecordUpdate<SignalAccountRecord> update, boolean fetchProfile) {
SignalDatabase.recipients().applyStorageSyncAccountUpdate(update);
TextSecurePreferences.setReadReceiptsEnabled(context, update.getNew().isReadReceiptsEnabled());
TextSecurePreferences.setTypingIndicatorsEnabled(context, update.getNew().isTypingIndicatorsEnabled());
TextSecurePreferences.setShowUnidentifiedDeliveryIndicatorsEnabled(context, update.getNew().isSealedSenderIndicatorsEnabled());
SignalStore.settings().setLinkPreviewsEnabled(update.getNew().isLinkPreviewsEnabled());
SignalStore.phoneNumberPrivacy().setPhoneNumberListingMode(update.getNew().isPhoneNumberUnlisted() ? PhoneNumberPrivacyValues.PhoneNumberListingMode.UNLISTED : PhoneNumberPrivacyValues.PhoneNumberListingMode.LISTED);
SignalStore.phoneNumberPrivacy().setPhoneNumberSharingMode(StorageSyncModels.remoteToLocalPhoneNumberSharingMode(update.getNew().getPhoneNumberSharingMode()));
SignalStore.settings().setPreferSystemContactPhotos(update.getNew().isPreferContactAvatars());
SignalStore.paymentsValues().setEnabledAndEntropy(update.getNew().getPayments().isEnabled(), Entropy.fromBytes(update.getNew().getPayments().getEntropy().orNull()));
SignalStore.settings().setUniversalExpireTimer(update.getNew().getUniversalExpireTimer());
SignalStore.emojiValues().setReactions(update.getNew().getDefaultReactions());
SignalStore.donationsValues().setDisplayBadgesOnProfile(update.getNew().isDisplayBadgesOnProfile());
if (update.getNew().isSubscriptionManuallyCancelled()) {
SignalStore.donationsValues().markUserManuallyCancelled();
SignalStore.donationsValues().setUnexpectedSubscriptionCancelationReason(null);
} else {
SignalStore.donationsValues().clearUserManuallyCancelled();
}
Subscriber subscriber = StorageSyncModels.remoteToLocalSubscriber(update.getNew().getSubscriber());
if (subscriber != null) {
SignalStore.donationsValues().setSubscriber(subscriber);
}
if (fetchProfile && update.getNew().getAvatarUrlPath().isPresent()) {
ApplicationDependencies.getJobManager().add(new RetrieveProfileAvatarJob(self, update.getNew().getAvatarUrlPath().get()));
}
}
use of org.thoughtcrime.securesms.subscription.Subscriber in project Signal-Android by WhisperSystems.
the class RefreshOwnProfileJob method setProfileBadges.
private void setProfileBadges(@Nullable List<SignalServiceProfile.Badge> badges) {
if (badges == null) {
return;
}
Set<String> localDonorBadgeIds = Recipient.self().getBadges().stream().filter(badge -> badge.getCategory() == Badge.Category.Donor).map(Badge::getId).collect(Collectors.toSet());
Set<String> remoteDonorBadgeIds = badges.stream().filter(badge -> Objects.equals(badge.getCategory(), Badge.Category.Donor.getCode())).map(SignalServiceProfile.Badge::getId).collect(Collectors.toSet());
boolean remoteHasSubscriptionBadges = remoteDonorBadgeIds.stream().anyMatch(RefreshOwnProfileJob::isSubscription);
boolean localHasSubscriptionBadges = localDonorBadgeIds.stream().anyMatch(RefreshOwnProfileJob::isSubscription);
boolean remoteHasBoostBadges = remoteDonorBadgeIds.stream().anyMatch(RefreshOwnProfileJob::isBoost);
boolean localHasBoostBadges = localDonorBadgeIds.stream().anyMatch(RefreshOwnProfileJob::isBoost);
if (!remoteHasSubscriptionBadges && localHasSubscriptionBadges) {
Badge mostRecentExpiration = Recipient.self().getBadges().stream().filter(badge -> badge.getCategory() == Badge.Category.Donor).filter(badge -> isSubscription(badge.getId())).max(Comparator.comparingLong(Badge::getExpirationTimestamp)).get();
Log.d(TAG, "Marking subscription badge as expired, should notify next time the conversation list is open.", true);
SignalStore.donationsValues().setExpiredBadge(mostRecentExpiration);
if (!SignalStore.donationsValues().isUserManuallyCancelled()) {
Log.d(TAG, "Detected an unexpected subscription expiry.", true);
Subscriber subscriber = SignalStore.donationsValues().getSubscriber();
boolean isDueToPaymentFailure = false;
if (subscriber != null) {
ServiceResponse<ActiveSubscription> response = ApplicationDependencies.getDonationsService().getSubscription(subscriber.getSubscriberId()).blockingGet();
if (response.getResult().isPresent()) {
ActiveSubscription activeSubscription = response.getResult().get();
if (activeSubscription.isFailedPayment()) {
Log.d(TAG, "Unexpected expiry due to payment failure.", true);
SignalStore.donationsValues().setUnexpectedSubscriptionCancelationReason(activeSubscription.getActiveSubscription().getStatus());
isDueToPaymentFailure = true;
}
}
}
if (!isDueToPaymentFailure) {
Log.d(TAG, "Unexpected expiry due to inactivity.", true);
SignalStore.donationsValues().setUnexpectedSubscriptionCancelationReason(UnexpectedSubscriptionCancellation.INACTIVE.getStatus());
}
MultiDeviceSubscriptionSyncRequestJob.enqueue();
SignalStore.donationsValues().setShouldCancelSubscriptionBeforeNextSubscribeAttempt(true);
}
} else if (!remoteHasBoostBadges && localHasBoostBadges) {
Badge mostRecentExpiration = Recipient.self().getBadges().stream().filter(badge -> badge.getCategory() == Badge.Category.Donor).filter(badge -> isBoost(badge.getId())).max(Comparator.comparingLong(Badge::getExpirationTimestamp)).get();
Log.d(TAG, "Marking boost badge as expired, should notify next time the conversation list is open.", true);
SignalStore.donationsValues().setExpiredBadge(mostRecentExpiration);
}
boolean userHasVisibleBadges = badges.stream().anyMatch(SignalServiceProfile.Badge::isVisible);
boolean userHasInvisibleBadges = badges.stream().anyMatch(b -> !b.isVisible());
List<Badge> appBadges = badges.stream().map(Badges::fromServiceBadge).collect(Collectors.toList());
if (userHasVisibleBadges && userHasInvisibleBadges) {
boolean displayBadgesOnProfile = SignalStore.donationsValues().getDisplayBadgesOnProfile();
Log.d(TAG, "Detected mixed visibility of badges. Telling the server to mark them all " + (displayBadgesOnProfile ? "" : "not") + " visible.", true);
BadgeRepository badgeRepository = new BadgeRepository(context);
badgeRepository.setVisibilityForAllBadges(displayBadgesOnProfile, appBadges).blockingSubscribe();
} else {
SignalDatabase.recipients().setBadges(Recipient.self().getId(), appBadges);
}
}
Aggregations