Search in sources :

Example 1 with RecipientRecord

use of org.thoughtcrime.securesms.database.model.RecipientRecord in project Signal-Android by WhisperSystems.

the class LiveRecipient method fetchAndCacheRecipientFromDisk.

@NonNull
private Recipient fetchAndCacheRecipientFromDisk(@NonNull RecipientId id) {
    RecipientRecord settings = recipientDatabase.getRecord(id);
    RecipientDetails details = settings.getGroupId() != null ? getGroupRecipientDetails(settings) : RecipientDetails.forIndividual(context, settings);
    Recipient recipient = new Recipient(id, details, true);
    RecipientIdCache.INSTANCE.put(recipient);
    return recipient;
}
Also used : RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) NonNull(androidx.annotation.NonNull)

Example 2 with RecipientRecord

use of org.thoughtcrime.securesms.database.model.RecipientRecord in project Signal-Android by WhisperSystems.

the class StorageSyncJob method buildLocalStorageRecords.

@NonNull
private static List<SignalStorageRecord> buildLocalStorageRecords(@NonNull Context context, @NonNull Recipient self, @NonNull Collection<StorageId> ids) {
    if (ids.isEmpty()) {
        return Collections.emptyList();
    }
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    UnknownStorageIdDatabase storageIdDatabase = SignalDatabase.unknownStorageIds();
    List<SignalStorageRecord> records = new ArrayList<>(ids.size());
    for (StorageId id : ids) {
        switch(id.getType()) {
            case ManifestRecord.Identifier.Type.CONTACT_VALUE:
            case ManifestRecord.Identifier.Type.GROUPV1_VALUE:
            case ManifestRecord.Identifier.Type.GROUPV2_VALUE:
                RecipientRecord settings = recipientDatabase.getByStorageId(id.getRaw());
                if (settings != null) {
                    if (settings.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 && settings.getSyncExtras().getGroupMasterKey() == null) {
                        throw new MissingGv2MasterKeyError();
                    } else {
                        records.add(StorageSyncModels.localToRemoteRecord(settings));
                    }
                } else {
                    throw new MissingRecipientModelError("Missing local recipient model! Type: " + id.getType());
                }
                break;
            case ManifestRecord.Identifier.Type.ACCOUNT_VALUE:
                if (!Arrays.equals(self.getStorageServiceId(), id.getRaw())) {
                    throw new AssertionError("Local storage ID doesn't match self!");
                }
                records.add(StorageSyncHelper.buildAccountRecord(context, self));
                break;
            default:
                SignalStorageRecord unknown = storageIdDatabase.getById(id.getRaw());
                if (unknown != null) {
                    records.add(unknown);
                } else {
                    throw new MissingUnknownModelError("Missing local unknown model! Type: " + id.getType());
                }
                break;
        }
    }
    return records;
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) ArrayList(java.util.ArrayList) SignalStorageRecord(org.whispersystems.signalservice.api.storage.SignalStorageRecord) UnknownStorageIdDatabase(org.thoughtcrime.securesms.database.UnknownStorageIdDatabase) StorageId(org.whispersystems.signalservice.api.storage.StorageId) NonNull(androidx.annotation.NonNull)

Example 3 with RecipientRecord

use of org.thoughtcrime.securesms.database.model.RecipientRecord in project Signal-Android by WhisperSystems.

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 4 with RecipientRecord

use of org.thoughtcrime.securesms.database.model.RecipientRecord in project Signal-Android by WhisperSystems.

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 5 with RecipientRecord

use of org.thoughtcrime.securesms.database.model.RecipientRecord in project Signal-Android by WhisperSystems.

the class ApplyUnknownFieldsToSelfMigrationJob method performMigration.

@Override
public void performMigration() {
    if (!SignalStore.account().isRegistered() || SignalStore.account().getAci() == null) {
        Log.w(TAG, "Not registered!");
        return;
    }
    Recipient self;
    RecipientRecord settings;
    try {
        self = Recipient.self();
        settings = SignalDatabase.recipients().getRecordForSync(self.getId());
    } catch (RecipientDatabase.MissingRecipientException e) {
        Log.w(TAG, "Unable to find self");
        return;
    }
    if (settings == null || settings.getSyncExtras().getStorageProto() == null) {
        Log.d(TAG, "No unknowns to apply");
        return;
    }
    try {
        StorageId storageId = StorageId.forAccount(self.getStorageServiceId());
        AccountRecord accountRecord = AccountRecord.parseFrom(settings.getSyncExtras().getStorageProto());
        SignalAccountRecord signalAccountRecord = new SignalAccountRecord(storageId, accountRecord);
        Log.d(TAG, "Applying potentially now known unknowns");
        StorageSyncHelper.applyAccountStorageSyncUpdates(context, self, signalAccountRecord, false);
    } catch (InvalidProtocolBufferException e) {
        Log.w(TAG, e);
    }
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) SignalAccountRecord(org.whispersystems.signalservice.api.storage.SignalAccountRecord) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) SignalAccountRecord(org.whispersystems.signalservice.api.storage.SignalAccountRecord) AccountRecord(org.whispersystems.signalservice.internal.storage.protos.AccountRecord) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) StorageId(org.whispersystems.signalservice.api.storage.StorageId)

Aggregations

RecipientRecord (org.thoughtcrime.securesms.database.model.RecipientRecord)5 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)4 NonNull (androidx.annotation.NonNull)3 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 SignalAccountRecord (org.whispersystems.signalservice.api.storage.SignalAccountRecord)2 StorageId (org.whispersystems.signalservice.api.storage.StorageId)2 Context (android.content.Context)1 Nullable (androidx.annotation.Nullable)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Log (org.signal.core.util.logging.Log)1 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)1 UnknownStorageIdDatabase (org.thoughtcrime.securesms.database.UnknownStorageIdDatabase)1 Entropy (org.thoughtcrime.securesms.payments.Entropy)1 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)1 Optional (org.whispersystems.libsignal.util.guava.Optional)1 ACI (org.whispersystems.signalservice.api.push.ACI)1 ServiceId (org.whispersystems.signalservice.api.push.ServiceId)1