mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-03-01 06:07:37 +00:00
Simplify SignalStorageRecord.
This commit is contained in:
@@ -116,7 +116,7 @@ public class UnknownStorageIdTable extends DatabaseTable {
|
||||
|
||||
for (SignalStorageRecord insert : inserts) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(TYPE, insert.getType());
|
||||
values.put(TYPE, insert.getId().getType());
|
||||
values.put(STORAGE_ID, Base64.encodeWithPadding(insert.getId().getRaw()));
|
||||
|
||||
db.insert(TABLE_NAME, null, values);
|
||||
|
||||
@@ -96,12 +96,12 @@ public class StorageAccountRestoreJob extends BaseJob {
|
||||
return;
|
||||
}
|
||||
|
||||
SignalAccountRecord accountRecord = record.getAccount().orElse(null);
|
||||
if (accountRecord == null) {
|
||||
if (record.getProto().account == null) {
|
||||
Log.w(TAG, "The storage record didn't actually have an account on it! Not restoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
SignalAccountRecord accountRecord = new SignalAccountRecord(record.getId(), record.getProto().account);
|
||||
|
||||
Log.i(TAG, "Applying changes locally...");
|
||||
SignalDatabase.getRawDatabase().beginTransaction();
|
||||
|
||||
@@ -37,6 +37,12 @@ import org.whispersystems.signalservice.api.storage.SignalStorageManifest
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageRecord
|
||||
import org.whispersystems.signalservice.api.storage.SignalStoryDistributionListRecord
|
||||
import org.whispersystems.signalservice.api.storage.StorageId
|
||||
import org.whispersystems.signalservice.api.storage.toSignalAccountRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalCallLinkRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalContactRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalGroupV1Record
|
||||
import org.whispersystems.signalservice.api.storage.toSignalGroupV2Record
|
||||
import org.whispersystems.signalservice.api.storage.toSignalStoryDistributionListRecord
|
||||
import org.whispersystems.signalservice.internal.push.SyncMessage
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ManifestRecord
|
||||
import java.io.IOException
|
||||
@@ -475,18 +481,18 @@ class StorageSyncJob private constructor(parameters: Parameters) : BaseJob(param
|
||||
|
||||
init {
|
||||
for (record in records) {
|
||||
if (record.contact.isPresent) {
|
||||
contacts += record.contact.get()
|
||||
} else if (record.groupV1.isPresent) {
|
||||
gv1 += record.groupV1.get()
|
||||
} else if (record.groupV2.isPresent) {
|
||||
gv2 += record.groupV2.get()
|
||||
} else if (record.account.isPresent) {
|
||||
account += record.account.get()
|
||||
} else if (record.storyDistributionList.isPresent) {
|
||||
storyDistributionLists += record.storyDistributionList.get()
|
||||
} else if (record.callLink.isPresent) {
|
||||
callLinkRecords += record.callLink.get()
|
||||
if (record.proto.contact != null) {
|
||||
contacts += record.proto.contact!!.toSignalContactRecord(record.id)
|
||||
} else if (record.proto.groupV1 != null) {
|
||||
gv1 += record.proto.groupV1!!.toSignalGroupV1Record(record.id)
|
||||
} else if (record.proto.groupV2 != null) {
|
||||
gv2 += record.proto.groupV2!!.toSignalGroupV2Record(record.id)
|
||||
} else if (record.proto.account != null) {
|
||||
account += record.proto.account!!.toSignalAccountRecord(record.id)
|
||||
} else if (record.proto.storyDistributionList != null) {
|
||||
storyDistributionLists += record.proto.storyDistributionList!!.toSignalStoryDistributionListRecord(record.id)
|
||||
} else if (record.proto.callLink != null) {
|
||||
callLinkRecords += record.proto.callLink!!.toSignalCallLinkRecord(record.id)
|
||||
} else if (record.id.isUnknown) {
|
||||
unknown += record
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.signal.core.util.nullIfEmpty
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper.applyAccountStorageSyncUpdates
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper.buildAccountRecord
|
||||
import org.whispersystems.signalservice.api.storage.SignalAccountRecord
|
||||
import org.whispersystems.signalservice.api.storage.StorageId
|
||||
import org.whispersystems.signalservice.api.storage.safeSetBackupsSubscriber
|
||||
@@ -35,7 +34,11 @@ class AccountRecordProcessor(
|
||||
|
||||
private var foundAccountRecord = false
|
||||
|
||||
constructor(context: Context, self: Recipient) : this(context, self, buildAccountRecord(context, self).account.get())
|
||||
constructor(context: Context, self: Recipient) : this(
|
||||
context = context,
|
||||
self = self,
|
||||
localAccountRecord = StorageSyncHelper.buildAccountRecord(context, self).let { it.proto.account!!.toSignalAccountRecord(it.id) }
|
||||
)
|
||||
|
||||
/**
|
||||
* We want to catch:
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
||||
return StorageSyncModels.localToRemoteRecord(updatedSettings);
|
||||
}
|
||||
})
|
||||
.map(r -> r.getContact().get());
|
||||
.map(r -> new SignalContactRecord(r.getId(), r.getProto().contact));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.thoughtcrime.securesms.groups.BadGroupIdException
|
||||
import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.whispersystems.signalservice.api.storage.SignalGroupV1Record
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalGroupV1Record
|
||||
import java.util.Optional
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,7 @@ class GroupV1RecordProcessor(private val groupDatabase: GroupTable, private val
|
||||
return recipientId
|
||||
.map { recipientTable.getRecordForSync(it)!! }
|
||||
.map { settings: RecipientRecord -> StorageSyncModels.localToRemoteRecord(settings) }
|
||||
.map { record: SignalStorageRecord -> record.groupV1.get() }
|
||||
.map { record: SignalStorageRecord -> record.proto.groupV1!!.toSignalGroupV1Record(record.id) }
|
||||
}
|
||||
|
||||
override fun merge(remote: SignalGroupV1Record, local: SignalGroupV1Record, keyGenerator: StorageKeyGenerator): SignalGroupV1Record {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.thoughtcrime.securesms.database.model.RecipientRecord
|
||||
import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.whispersystems.signalservice.api.storage.SignalGroupV2Record
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalGroupV2Record
|
||||
import org.whispersystems.signalservice.internal.storage.protos.GroupV2Record
|
||||
import java.util.Optional
|
||||
|
||||
@@ -39,7 +40,7 @@ class GroupV2RecordProcessor(private val recipientTable: RecipientTable, private
|
||||
StorageSyncModels.localToRemoteRecord(settings, remote.masterKeyOrThrow)
|
||||
}
|
||||
}
|
||||
.map { record: SignalStorageRecord -> record.groupV2.get() }
|
||||
.map { record: SignalStorageRecord -> record.proto.groupV2!!.toSignalGroupV2Record(record.id) }
|
||||
}
|
||||
|
||||
override fun merge(remote: SignalGroupV2Record, local: SignalGroupV2Record, keyGenerator: StorageKeyGenerator): SignalGroupV2Record {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.whispersystems.signalservice.api.storage.safeSetBackupsSubscriber
|
||||
import org.whispersystems.signalservice.api.storage.safeSetPayments
|
||||
import org.whispersystems.signalservice.api.storage.safeSetSubscriber
|
||||
import org.whispersystems.signalservice.api.storage.toSignalAccountRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalStorageRecord
|
||||
import org.whispersystems.signalservice.api.util.OptionalUtil.byteArrayEquals
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.api.util.toByteArray
|
||||
@@ -182,12 +183,12 @@ object StorageSyncHelper {
|
||||
safeSetPayments(SignalStore.payments.mobileCoinPaymentsEnabled(), Optional.ofNullable(SignalStore.payments.paymentsEntropy).map { obj: Entropy -> obj.bytes }.orElse(null))
|
||||
}
|
||||
|
||||
return SignalStorageRecord.forAccount(accountRecord.toSignalAccountRecord(StorageId.forAccount(storageId)))
|
||||
return accountRecord.toSignalAccountRecord(StorageId.forAccount(storageId)).toSignalStorageRecord()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun applyAccountStorageSyncUpdates(context: Context, self: Recipient, updatedRecord: SignalAccountRecord, fetchProfile: Boolean) {
|
||||
val localRecord = buildAccountRecord(context, self).account.get()
|
||||
val localRecord = buildAccountRecord(context, self).let { it.proto.account!!.toSignalAccountRecord(it.id) }
|
||||
applyAccountStorageSyncUpdates(context, self, StorageRecordUpdate(localRecord, updatedRecord), fetchProfile)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.whispersystems.signalservice.api.storage.SignalGroupV1Record
|
||||
import org.whispersystems.signalservice.api.storage.SignalGroupV2Record
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageRecord
|
||||
import org.whispersystems.signalservice.api.storage.SignalStoryDistributionListRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalStorageRecord
|
||||
import org.whispersystems.signalservice.api.subscriptions.SubscriberId
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord
|
||||
@@ -50,17 +51,17 @@ object StorageSyncModels {
|
||||
throw AssertionError("Must have a storage key!")
|
||||
}
|
||||
|
||||
return SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, settings.storageId, groupMasterKey))
|
||||
return localToRemoteGroupV2(settings, settings.storageId, groupMasterKey).toSignalStorageRecord()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun localToRemoteRecord(settings: RecipientRecord, rawStorageId: ByteArray): SignalStorageRecord {
|
||||
return when (settings.recipientType) {
|
||||
RecipientType.INDIVIDUAL -> SignalStorageRecord.forContact(localToRemoteContact(settings, rawStorageId))
|
||||
RecipientType.GV1 -> SignalStorageRecord.forGroupV1(localToRemoteGroupV1(settings, rawStorageId))
|
||||
RecipientType.GV2 -> SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, rawStorageId, settings.syncExtras.groupMasterKey!!))
|
||||
RecipientType.DISTRIBUTION_LIST -> SignalStorageRecord.forStoryDistributionList(localToRemoteStoryDistributionList(settings, rawStorageId))
|
||||
RecipientType.CALL_LINK -> SignalStorageRecord.forCallLink(localToRemoteCallLink(settings, rawStorageId))
|
||||
RecipientType.INDIVIDUAL -> localToRemoteContact(settings, rawStorageId).toSignalStorageRecord()
|
||||
RecipientType.GV1 -> localToRemoteGroupV1(settings, rawStorageId).toSignalStorageRecord()
|
||||
RecipientType.GV2 -> localToRemoteGroupV2(settings, rawStorageId, settings.syncExtras.groupMasterKey!!).toSignalStorageRecord()
|
||||
RecipientType.DISTRIBUTION_LIST -> localToRemoteStoryDistributionList(settings, rawStorageId).toSignalStorageRecord()
|
||||
RecipientType.CALL_LINK -> localToRemoteCallLink(settings, rawStorageId).toSignalStorageRecord()
|
||||
else -> throw AssertionError("Unsupported type!")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.signal.core.util.Base64;
|
||||
import org.signal.core.util.SetUtil;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.storage.SignalContactRecord;
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageManifest;
|
||||
import org.whispersystems.signalservice.api.storage.SignalStorageRecord;
|
||||
import org.whispersystems.signalservice.api.storage.StorageId;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ContactRecord;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ManifestRecord;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -166,18 +168,18 @@ public final class StorageSyncValidations {
|
||||
throw new UnknownInsertError();
|
||||
}
|
||||
|
||||
if (insert.getContact().isPresent()) {
|
||||
SignalContactRecord contact = insert.getContact().get();
|
||||
if (insert.getProto().contact != null) {
|
||||
ContactRecord contact = insert.getProto().contact;
|
||||
|
||||
if (self.requireAci().equals(contact.getAci().orElse(null)) ||
|
||||
self.requirePni().equals(contact.getPni().orElse(null)) ||
|
||||
self.requireE164().equals(contact.getNumber().orElse("")))
|
||||
if (self.requireAci().equals(ServiceId.ACI.parseOrNull(contact.aci)) ||
|
||||
self.requirePni().equals(ServiceId.PNI.parseOrNull(contact.pni)) ||
|
||||
self.requireE164().equals(contact.e164))
|
||||
{
|
||||
throw new SelfAddedAsContactError();
|
||||
}
|
||||
}
|
||||
|
||||
if (insert.getAccount().isPresent() && insert.getAccount().get().getProto().profileKey.size() == 0) {
|
||||
if (insert.getProto().account != null && insert.getProto().account.profileKey.size() == 0) {
|
||||
Log.w(TAG, "Uploading a null profile key in our AccountRecord!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.whispersystems.signalservice.api.push.DistributionId
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.api.storage.SignalStoryDistributionListRecord
|
||||
import org.whispersystems.signalservice.api.storage.toSignalStoryDistributionListRecord
|
||||
import org.whispersystems.signalservice.api.util.OptionalUtil.asOptional
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import java.io.IOException
|
||||
import java.util.Optional
|
||||
@@ -78,14 +80,7 @@ class StoryDistributionListRecordProcessor : DefaultStorageRecordProcessor<Signa
|
||||
throw InvalidGroupTypeException()
|
||||
}
|
||||
|
||||
val record = StorageSyncModels.localToRemoteRecord(recordForSync).storyDistributionList
|
||||
if (record.isPresent) {
|
||||
Log.d(TAG, "Found a matching record.")
|
||||
return record
|
||||
} else {
|
||||
Log.e(TAG, "Could not resolve the record")
|
||||
throw UnexpectedEmptyOptionalException()
|
||||
}
|
||||
return StorageSyncModels.localToRemoteRecord(recordForSync).let { it.proto.storyDistributionList!!.toSignalStoryDistributionListRecord(it.id) }.asOptional()
|
||||
} else {
|
||||
Log.d(TAG, "Could not find a matching record. Returning an empty.")
|
||||
return Optional.empty()
|
||||
|
||||
Reference in New Issue
Block a user