Search in sources :

Example 31 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class RetrieveProfileJob method enqueueRoutineFetchIfNecessary.

/**
 * Will fetch some profiles to ensure we're decently up-to-date if we haven't done so within a
 * certain time period.
 */
public static void enqueueRoutineFetchIfNecessary(Application application) {
    if (!SignalStore.registrationValues().isRegistrationComplete() || !SignalStore.account().isRegistered() || SignalStore.account().getAci() == null) {
        Log.i(TAG, "Registration not complete. Skipping.");
        return;
    }
    long timeSinceRefresh = System.currentTimeMillis() - SignalStore.misc().getLastProfileRefreshTime();
    if (timeSinceRefresh < TimeUnit.HOURS.toMillis(12)) {
        Log.i(TAG, "Too soon to refresh. Did the last refresh " + timeSinceRefresh + " ms ago.");
        return;
    }
    SignalExecutors.BOUNDED.execute(() -> {
        RecipientDatabase db = SignalDatabase.recipients();
        long current = System.currentTimeMillis();
        List<RecipientId> ids = db.getRecipientsForRoutineProfileFetch(current - TimeUnit.DAYS.toMillis(30), current - TimeUnit.DAYS.toMillis(1), 50);
        ids.add(Recipient.self().getId());
        if (ids.size() > 0) {
            Log.i(TAG, "Optimistically refreshing " + ids.size() + " eligible recipient(s).");
            enqueue(new HashSet<>(ids));
        } else {
            Log.i(TAG, "No recipients to refresh.");
        }
        SignalStore.misc().setLastProfileRefreshTime(System.currentTimeMillis());
    });
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId)

Example 32 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class StorageSyncHelper method buildAccountRecord.

public static SignalStorageRecord buildAccountRecord(@NonNull Context context, @NonNull Recipient self) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    RecipientRecord record = recipientDatabase.getRecordForSync(self.getId());
    List<RecipientRecord> pinned = Stream.of(SignalDatabase.threads().getPinnedRecipientIds()).map(recipientDatabase::getRecordForSync).toList();
    SignalAccountRecord account = new SignalAccountRecord.Builder(self.getStorageServiceId(), record != null ? record.getSyncExtras().getStorageProto() : null).setProfileKey(self.getProfileKey()).setGivenName(self.getProfileName().getGivenName()).setFamilyName(self.getProfileName().getFamilyName()).setAvatarUrlPath(self.getProfileAvatar()).setNoteToSelfArchived(record != null && record.getSyncExtras().isArchived()).setNoteToSelfForcedUnread(record != null && record.getSyncExtras().isForcedUnread()).setTypingIndicatorsEnabled(TextSecurePreferences.isTypingIndicatorsEnabled(context)).setReadReceiptsEnabled(TextSecurePreferences.isReadReceiptsEnabled(context)).setSealedSenderIndicatorsEnabled(TextSecurePreferences.isShowUnidentifiedDeliveryIndicatorsEnabled(context)).setLinkPreviewsEnabled(SignalStore.settings().isLinkPreviewsEnabled()).setUnlistedPhoneNumber(SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode().isUnlisted()).setPhoneNumberSharingMode(StorageSyncModels.localToRemotePhoneNumberSharingMode(SignalStore.phoneNumberPrivacy().getPhoneNumberSharingMode())).setPinnedConversations(StorageSyncModels.localToRemotePinnedConversations(pinned)).setPreferContactAvatars(SignalStore.settings().isPreferSystemContactPhotos()).setPayments(SignalStore.paymentsValues().mobileCoinPaymentsEnabled(), Optional.fromNullable(SignalStore.paymentsValues().getPaymentsEntropy()).transform(Entropy::getBytes).orNull()).setPrimarySendsSms(Util.isDefaultSmsProvider(context)).setUniversalExpireTimer(SignalStore.settings().getUniversalExpireTimer()).setE164(self.requireE164()).setDefaultReactions(SignalStore.emojiValues().getReactions()).setSubscriber(StorageSyncModels.localToRemoteSubscriber(SignalStore.donationsValues().getSubscriber())).setDisplayBadgesOnProfile(SignalStore.donationsValues().getDisplayBadgesOnProfile()).setSubscriptionManuallyCancelled(SignalStore.donationsValues().isUserManuallyCancelled()).build();
    return SignalStorageRecord.forAccount(account);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) SignalAccountRecord(org.whispersystems.signalservice.api.storage.SignalAccountRecord) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) Entropy(org.thoughtcrime.securesms.payments.Entropy)

Example 33 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class ContactRecordProcessor method getMatching.

@Override
@NonNull
Optional<SignalContactRecord> getMatching(@NonNull SignalContactRecord remote, @NonNull StorageKeyGenerator keyGenerator) {
    SignalServiceAddress address = remote.getAddress();
    Optional<RecipientId> byUuid = recipientDatabase.getByServiceId(address.getServiceId());
    Optional<RecipientId> byE164 = address.getNumber().isPresent() ? recipientDatabase.getByE164(address.getNumber().get()) : Optional.absent();
    return byUuid.or(byE164).transform(recipientDatabase::getRecordForSync).transform(settings -> {
        if (settings.getStorageId() != null) {
            return StorageSyncModels.localToRemoteRecord(settings);
        } else {
            Log.w(TAG, "Newly discovering a registered user via storage service. Saving a storageId for them.");
            recipientDatabase.updateStorageId(settings.getId(), keyGenerator.generate());
            RecipientRecord updatedSettings = Objects.requireNonNull(recipientDatabase.getRecordForSync(settings.getId()));
            return StorageSyncModels.localToRemoteRecord(updatedSettings);
        }
    }).transform(r -> r.getContact().get());
}
Also used : Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Arrays(java.util.Arrays) ACI(org.whispersystems.signalservice.api.push.ACI) NonNull(androidx.annotation.NonNull) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) IdentityState(org.whispersystems.signalservice.internal.storage.protos.ContactRecord.IdentityState) Optional(org.whispersystems.libsignal.util.guava.Optional) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) Nullable(androidx.annotation.Nullable) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalContactRecord(org.whispersystems.signalservice.api.storage.SignalContactRecord) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) NonNull(androidx.annotation.NonNull)

Example 34 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class MultiDeviceBlockedUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    RecipientDatabase database = SignalDatabase.recipients();
    try (RecipientReader reader = database.readerForBlocked(database.getBlocked())) {
        List<SignalServiceAddress> blockedIndividuals = new LinkedList<>();
        List<byte[]> blockedGroups = new LinkedList<>();
        Recipient recipient;
        while ((recipient = reader.getNext()) != null) {
            if (recipient.isPushGroup()) {
                blockedGroups.add(recipient.requireGroupId().getDecodedId());
            } else if (recipient.isMaybeRegistered() && (recipient.hasServiceId() || recipient.hasE164())) {
                blockedIndividuals.add(RecipientUtil.toSignalServiceAddress(context, recipient));
            }
        }
        SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
        messageSender.sendSyncMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blockedIndividuals, blockedGroups)), UnidentifiedAccessUtil.getAccessForSync(context));
    }
}
Also used : RecipientReader(org.thoughtcrime.securesms.database.RecipientDatabase.RecipientReader) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) LinkedList(java.util.LinkedList)

Example 35 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class InsightsRepository method sendSmsInvite.

@Override
public void sendSmsInvite(@NonNull Recipient recipient, Runnable onSmsMessageSent) {
    SimpleTask.run(() -> {
        Recipient resolved = recipient.resolve();
        int subscriptionId = resolved.getDefaultSubscriptionId().or(-1);
        String message = context.getString(R.string.InviteActivity_lets_switch_to_signal, context.getString(R.string.install_url));
        MessageSender.send(context, new OutgoingTextMessage(resolved, message, subscriptionId), -1L, true, null, null);
        RecipientDatabase database = SignalDatabase.recipients();
        database.setHasSentInvite(recipient.getId());
        return null;
    }, v -> onSmsMessageSent.run());
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Aggregations

RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)72 Recipient (org.thoughtcrime.securesms.recipients.Recipient)32 WorkerThread (androidx.annotation.WorkerThread)30 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)20 NonNull (androidx.annotation.NonNull)18 IOException (java.io.IOException)14 Nullable (androidx.annotation.Nullable)10 ArrayList (java.util.ArrayList)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ACI (org.whispersystems.signalservice.api.push.ACI)10 Context (android.content.Context)8 Stream (com.annimon.stream.Stream)8 Collections (java.util.Collections)8 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 Optional (org.whispersystems.libsignal.util.guava.Optional)8 HashSet (java.util.HashSet)7