Add universal disappearing messages.

This commit is contained in:
Cody Henthorne
2021-05-18 15:19:33 -04:00
committed by Greyson Parrelli
parent 8c6a88374b
commit defd5e8047
70 changed files with 1513 additions and 251 deletions

View File

@@ -40,7 +40,7 @@ public class ApplicationMigrations {
private static final int LEGACY_CANONICAL_VERSION = 455;
public static final int CURRENT_VERSION = 33;
public static final int CURRENT_VERSION = 34;
private static final class Version {
static final int LEGACY = 1;
@@ -75,6 +75,7 @@ public class ApplicationMigrations {
static final int MUTE_SYNC = 31;
static final int PROFILE_SHARING_UPDATE = 32;
static final int SMS_STORAGE_SYNC = 33;
static final int APPLY_UNIVERSAL_EXPIRE = 34;
}
/**
@@ -317,6 +318,10 @@ public class ApplicationMigrations {
jobs.put(Version.SMS_STORAGE_SYNC, new AccountRecordMigrationJob());
}
if (lastSeenVersion < Version.APPLY_UNIVERSAL_EXPIRE) {
jobs.put(Version.SMS_STORAGE_SYNC, new ApplyUnknownFieldsToSelfMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,86 @@
package org.thoughtcrime.securesms.migrations;
import androidx.annotation.NonNull;
import com.google.protobuf.InvalidProtocolBufferException;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobs.StorageSyncJob;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.signalservice.api.storage.SignalAccountRecord;
import org.whispersystems.signalservice.api.storage.StorageId;
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord;
/**
* Check for unknown fields stored on self and attempt to apply them.
*/
public class ApplyUnknownFieldsToSelfMigrationJob extends MigrationJob {
private static final String TAG = Log.tag(ApplyUnknownFieldsToSelfMigrationJob.class);
public static final String KEY = "ApplyUnknownFieldsToSelfMigrationJob";
ApplyUnknownFieldsToSelfMigrationJob() {
this(new Parameters.Builder().build());
}
private ApplyUnknownFieldsToSelfMigrationJob(@NonNull Parameters parameters) {
super(parameters);
}
@Override
public boolean isUiBlocking() {
return false;
}
@Override
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public void performMigration() {
if (!TextSecurePreferences.isPushRegistered(context) || TextSecurePreferences.getLocalUuid(context) == null) {
Log.w(TAG, "Not registered!");
return;
}
Recipient self = Recipient.self();
RecipientDatabase.RecipientSettings settings = DatabaseFactory.getRecipientDatabase(context).getRecipientSettingsForSync(self.getId());
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);
}
}
@Override
boolean shouldRetry(@NonNull Exception e) {
return false;
}
public static class Factory implements Job.Factory<ApplyUnknownFieldsToSelfMigrationJob> {
@Override
public @NonNull ApplyUnknownFieldsToSelfMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
return new ApplyUnknownFieldsToSelfMigrationJob(parameters);
}
}
}