Fix empty emoji search index.

This commit is contained in:
Cody Henthorne
2023-07-11 16:59:19 -04:00
committed by Clark Chen
parent 2c74ac8bfa
commit 648506fe04
5 changed files with 79 additions and 1 deletions

View File

@@ -134,9 +134,10 @@ public class ApplicationMigrations {
static final int EMOJI_VERSION_8 = 90;
static final int SVR2_MIRROR = 91;
static final int ATTACHMENT_CLEANUP_3 = 92;
static final int EMOJI_SEARCH_INDEX_CHECK = 93;
}
public static final int CURRENT_VERSION = 92;
public static final int CURRENT_VERSION = 93;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -606,6 +607,10 @@ public class ApplicationMigrations {
jobs.put(Version.ATTACHMENT_CLEANUP_3, new AttachmentCleanupMigrationJob());
}
if (lastSeenVersion < Version.EMOJI_SEARCH_INDEX_CHECK) {
jobs.put(Version.EMOJI_SEARCH_INDEX_CHECK, new EmojiSearchIndexCheckMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,59 @@
package org.thoughtcrime.securesms.migrations;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.signal.core.util.SqlUtil;
import org.thoughtcrime.securesms.database.EmojiSearchTable;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobs.DownloadLatestEmojiDataJob;
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
/**
* Schedules job to get the latest emoji search index if it's empty.
*/
public final class EmojiSearchIndexCheckMigrationJob extends MigrationJob {
public static final String KEY = "EmojiSearchIndexCheckMigrationJob";
EmojiSearchIndexCheckMigrationJob() {
this(new Parameters.Builder().build());
}
private EmojiSearchIndexCheckMigrationJob(@NonNull Parameters parameters) {
super(parameters);
}
@Override
public boolean isUiBlocking() {
return false;
}
@Override
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public void performMigration() {
if (SqlUtil.isEmpty(SignalDatabase.getRawDatabase(), EmojiSearchTable.TABLE_NAME)) {
SignalStore.emojiValues().clearSearchIndexMetadata();
EmojiSearchIndexDownloadJob.scheduleImmediately();
}
}
@Override
boolean shouldRetry(@NonNull Exception e) {
return false;
}
public static class Factory implements Job.Factory<EmojiSearchIndexCheckMigrationJob> {
@Override
public @NonNull EmojiSearchIndexCheckMigrationJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) {
return new EmojiSearchIndexCheckMigrationJob(parameters);
}
}
}