Improve conditional logic around prekey refresh schedule.

This commit is contained in:
Greyson Parrelli
2023-05-09 15:35:48 -04:00
committed by GitHub
parent d38b7deeeb
commit 93d78b3b2e
9 changed files with 128 additions and 92 deletions

View File

@@ -128,9 +128,10 @@ public class ApplicationMigrations {
static final int INDEX_DATABASE_MIGRATION = 84;
static final int ACCOUNT_CONSISTENCY_CHECK = 85;
static final int BACKUP_JITTER = 86;
static final int PREKEY_SYNC = 87;
}
public static final int CURRENT_VERSION = 86;
public static final int CURRENT_VERSION = 87;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -576,6 +577,10 @@ public class ApplicationMigrations {
jobs.put(Version.BACKUP_JITTER, new BackupJitterMigrationJob());
}
if (lastSeenVersion < Version.PREKEY_SYNC) {
jobs.put(Version.PREKEY_SYNC, new PreKeysSyncMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,36 @@
package org.thoughtcrime.securesms.migrations
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.jobs.PreKeysSyncJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
/**
* Schedules a prekey sync.
*/
internal class PreKeysSyncMigrationJob(
parameters: Parameters = Parameters.Builder().build()
) : MigrationJob(parameters) {
companion object {
val TAG = Log.tag(PreKeysSyncMigrationJob::class.java)
const val KEY = "PreKeysSyncIndexMigrationJob"
}
override fun getFactoryKey(): String = KEY
override fun isUiBlocking(): Boolean = false
override fun performMigration() {
SignalStore.misc().lastFullPrekeyRefreshTime = 0
PreKeysSyncJob.enqueue()
}
override fun shouldRetry(e: Exception): Boolean = false
class Factory : Job.Factory<PreKeysSyncMigrationJob> {
override fun create(parameters: Parameters, serializedData: ByteArray?): PreKeysSyncMigrationJob {
return PreKeysSyncMigrationJob(parameters)
}
}
}