Search in sources :

Example 6 with UnknownStorageIdDatabase

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

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)

Aggregations

UnknownStorageIdDatabase (org.thoughtcrime.securesms.database.UnknownStorageIdDatabase)6 SignalStorageRecord (org.whispersystems.signalservice.api.storage.SignalStorageRecord)6 StorageId (org.whispersystems.signalservice.api.storage.StorageId)6 NonNull (androidx.annotation.NonNull)4 ArrayList (java.util.ArrayList)4 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)4 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)4 SignalStorageManifest (org.whispersystems.signalservice.api.storage.SignalStorageManifest)4 StorageKey (org.whispersystems.signalservice.api.storage.StorageKey)4 Stream (com.annimon.stream.Stream)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Objects (java.util.Objects)2