diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/EmojiSearchIndexDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/EmojiSearchIndexDownloadJob.java index df4cc13cf8..2c8b2d7981 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/EmojiSearchIndexDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/EmojiSearchIndexDownloadJob.java @@ -103,6 +103,10 @@ public final class EmojiSearchIndexDownloadJob extends BaseJob { List searchIndex = downloadSearchIndex(manifest.getVersion(), remoteLanguage); + if (searchIndex.isEmpty()) { + throw new IOException("Emoji search data is empty"); + } + SignalDatabase.emojiSearch().setSearchIndex(searchIndex); SignalStore.emojiValues().onSearchIndexUpdated(manifest.getVersion(), remoteLanguage); SignalStore.emojiValues().setLastSearchIndexCheck(System.currentTimeMillis()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java index 9e7dc6149c..35f45d2383 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java @@ -51,6 +51,7 @@ import org.thoughtcrime.securesms.migrations.DecryptionsDrainedMigrationJob; import org.thoughtcrime.securesms.migrations.DeleteDeprecatedLogsMigrationJob; import org.thoughtcrime.securesms.migrations.DirectoryRefreshMigrationJob; import org.thoughtcrime.securesms.migrations.EmojiDownloadMigrationJob; +import org.thoughtcrime.securesms.migrations.EmojiSearchIndexCheckMigrationJob; import org.thoughtcrime.securesms.migrations.LegacyMigrationJob; import org.thoughtcrime.securesms.migrations.MigrationCompleteJob; import org.thoughtcrime.securesms.migrations.OptimizeMessageSearchIndexMigrationJob; @@ -234,6 +235,7 @@ public final class JobManagerFactories { put(DeleteDeprecatedLogsMigrationJob.KEY, new DeleteDeprecatedLogsMigrationJob.Factory()); put(DirectoryRefreshMigrationJob.KEY, new DirectoryRefreshMigrationJob.Factory()); put(EmojiDownloadMigrationJob.KEY, new EmojiDownloadMigrationJob.Factory()); + put(EmojiSearchIndexCheckMigrationJob.KEY, new EmojiSearchIndexCheckMigrationJob.Factory()); put(LegacyMigrationJob.KEY, new LegacyMigrationJob.Factory()); put(MigrationCompleteJob.KEY, new MigrationCompleteJob.Factory()); put(OptimizeMessageSearchIndexMigrationJob.KEY,new OptimizeMessageSearchIndexMigrationJob.Factory()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/keyvalue/EmojiValues.java b/app/src/main/java/org/thoughtcrime/securesms/keyvalue/EmojiValues.java index cd23edda63..3e3cb8eec7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/keyvalue/EmojiValues.java +++ b/app/src/main/java/org/thoughtcrime/securesms/keyvalue/EmojiValues.java @@ -123,6 +123,14 @@ public class EmojiValues extends SignalStoreValues { return getInteger(SEARCH_VERSION, 0); } + public void clearSearchIndexMetadata() { + getStore().beginWrite() + .remove(SEARCH_VERSION) + .remove(SEARCH_LANGUAGE) + .remove(LAST_SEARCH_CHECK) + .apply(); + } + public @Nullable String getSearchLanguage() { return getString(SEARCH_LANGUAGE, null); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java b/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java index 2d6be92f66..064eddc930 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java @@ -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; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/EmojiSearchIndexCheckMigrationJob.java b/app/src/main/java/org/thoughtcrime/securesms/migrations/EmojiSearchIndexCheckMigrationJob.java new file mode 100644 index 0000000000..926c3c9203 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/EmojiSearchIndexCheckMigrationJob.java @@ -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 { + @Override + public @NonNull EmojiSearchIndexCheckMigrationJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) { + return new EmojiSearchIndexCheckMigrationJob(parameters); + } + } +}