Search in sources :

Example 1 with Badge

use of org.thoughtcrime.securesms.badges.models.Badge in project Signal-Android by WhisperSystems.

the class ProfileUtil method uploadProfile.

private static void uploadProfile(@NonNull Context context, @NonNull ProfileName profileName, @Nullable String about, @Nullable String aboutEmoji, @Nullable SignalServiceProtos.PaymentAddress paymentsAddress, @Nullable StreamDetails avatar, @NonNull List<Badge> badges) throws IOException {
    List<String> badgeIds = badges.stream().filter(Badge::getVisible).map(Badge::getId).collect(Collectors.toList());
    Log.d(TAG, "Uploading " + (!profileName.isEmpty() ? "non-" : "") + "empty profile name.");
    Log.d(TAG, "Uploading " + (!Util.isEmpty(about) ? "non-" : "") + "empty about.");
    Log.d(TAG, "Uploading " + (!Util.isEmpty(aboutEmoji) ? "non-" : "") + "empty emoji.");
    Log.d(TAG, "Uploading " + (paymentsAddress != null ? "non-" : "") + "empty payments address.");
    Log.d(TAG, "Uploading " + (avatar != null && avatar.getLength() != 0 ? "non-" : "") + "empty avatar.");
    Log.d(TAG, "Uploading " + ((!badgeIds.isEmpty()) ? "non-" : "") + "empty badge list");
    ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
    SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
    String avatarPath = accountManager.setVersionedProfile(SignalStore.account().requireAci(), profileKey, profileName.serialize(), about, aboutEmoji, Optional.fromNullable(paymentsAddress), avatar, badgeIds).orNull();
    SignalStore.registrationValues().markHasUploadedProfile();
    SignalDatabase.recipients().setProfileAvatar(Recipient.self().getId(), avatarPath);
}
Also used : SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) Badge(org.thoughtcrime.securesms.badges.models.Badge) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 2 with Badge

use of org.thoughtcrime.securesms.badges.models.Badge in project Signal-Android by WhisperSystems.

the class ConversationListFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    updateReminders();
    EventBus.getDefault().register(this);
    itemAnimator.disable();
    if (Util.isDefaultSmsProvider(requireContext())) {
        InsightsLauncher.showInsightsModal(requireContext(), requireFragmentManager());
    }
    SimpleTask.run(getViewLifecycleOwner().getLifecycle(), Recipient::self, this::initializeProfileIcon);
    initializeSettingsTouchTarget();
    if ((!searchToolbar.resolved() || !searchToolbar.get().isVisible()) && list.getAdapter() != defaultAdapter) {
        list.removeItemDecoration(searchAdapterDecoration);
        setAdapter(defaultAdapter);
    }
    if (activeAdapter != null) {
        activeAdapter.notifyDataSetChanged();
    }
    SignalProxyUtil.startListeningToWebsocket();
    if (SignalStore.rateLimit().needsRecaptcha()) {
        Log.i(TAG, "Recaptcha required.");
        RecaptchaProofBottomSheetFragment.show(getChildFragmentManager());
    }
    Badge expiredBadge = SignalStore.donationsValues().getExpiredBadge();
    String subscriptionCancellationReason = SignalStore.donationsValues().getUnexpectedSubscriptionCancelationReason();
    UnexpectedSubscriptionCancellation unexpectedSubscriptionCancellation = UnexpectedSubscriptionCancellation.fromStatus(subscriptionCancellationReason);
    if (expiredBadge != null) {
        SignalStore.donationsValues().setExpiredBadge(null);
        if (expiredBadge.isBoost() || !SignalStore.donationsValues().isUserManuallyCancelled()) {
            Log.w(TAG, "Displaying bottom sheet for an expired badge", true);
            ExpiredBadgeBottomSheetDialogFragment.show(expiredBadge, unexpectedSubscriptionCancellation, getParentFragmentManager());
        }
    } else if (unexpectedSubscriptionCancellation != null && !SignalStore.donationsValues().isUserManuallyCancelled() && SignalStore.donationsValues().getShowCantProcessDialog()) {
        Log.w(TAG, "Displaying bottom sheet for unexpected cancellation: " + unexpectedSubscriptionCancellation, true);
        new CantProcessSubscriptionPaymentBottomSheetDialogFragment().show(getChildFragmentManager(), BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG);
    }
}
Also used : CantProcessSubscriptionPaymentBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.CantProcessSubscriptionPaymentBottomSheetDialogFragment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Badge(org.thoughtcrime.securesms.badges.models.Badge) UnexpectedSubscriptionCancellation(org.thoughtcrime.securesms.components.settings.app.subscription.errors.UnexpectedSubscriptionCancellation)

Example 3 with Badge

use of org.thoughtcrime.securesms.badges.models.Badge 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);
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) ProfileName(org.thoughtcrime.securesms.profiles.ProfileName) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ProfileUtil(org.thoughtcrime.securesms.util.ProfileUtil) Badges(org.thoughtcrime.securesms.badges.Badges) Badge(org.thoughtcrime.securesms.badges.models.Badge) Recipient(org.thoughtcrime.securesms.recipients.Recipient) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) ActiveSubscription(org.whispersystems.signalservice.api.subscriptions.ActiveSubscription) ProfileKeyUtil(org.thoughtcrime.securesms.crypto.ProfileKeyUtil) Subscriber(org.thoughtcrime.securesms.subscription.Subscriber) Set(java.util.Set) TextUtils(android.text.TextUtils) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) IOException(java.io.IOException) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) Collectors(java.util.stream.Collectors) BadgeRepository(org.thoughtcrime.securesms.badges.BadgeRepository) Optional(org.whispersystems.libsignal.util.guava.Optional) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) UnexpectedSubscriptionCancellation(org.thoughtcrime.securesms.components.settings.app.subscription.errors.UnexpectedSubscriptionCancellation) Job(org.thoughtcrime.securesms.jobmanager.Job) Comparator(java.util.Comparator) ActiveSubscription(org.whispersystems.signalservice.api.subscriptions.ActiveSubscription) Subscriber(org.thoughtcrime.securesms.subscription.Subscriber) BadgeRepository(org.thoughtcrime.securesms.badges.BadgeRepository) Badge(org.thoughtcrime.securesms.badges.models.Badge) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile)

Aggregations

Badge (org.thoughtcrime.securesms.badges.models.Badge)3 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)2 UnexpectedSubscriptionCancellation (org.thoughtcrime.securesms.components.settings.app.subscription.errors.UnexpectedSubscriptionCancellation)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 TextUtils (android.text.TextUtils)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Log (org.signal.core.util.logging.Log)1 ProfileKeyCredential (org.signal.zkgroup.profiles.ProfileKeyCredential)1 BadgeRepository (org.thoughtcrime.securesms.badges.BadgeRepository)1 Badges (org.thoughtcrime.securesms.badges.Badges)1 CantProcessSubscriptionPaymentBottomSheetDialogFragment (org.thoughtcrime.securesms.badges.self.expired.CantProcessSubscriptionPaymentBottomSheetDialogFragment)1 ProfileKeyUtil (org.thoughtcrime.securesms.crypto.ProfileKeyUtil)1 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)1