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;
}
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;
}
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);
}
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());
}
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);
}
}
Aggregations