mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Add a migration to generate thumbnails for existing quotes.
This commit is contained in:
@@ -187,9 +187,10 @@ public class ApplicationMigrations {
|
||||
static final int SVR2_ENCLAVE_UPDATE_4 = 143;
|
||||
static final int RESET_ARCHIVE_TIER = 144;
|
||||
static final int ARCHIVE_BACKUP_ID = 145;
|
||||
static final int QUOTE_THUMBNAIL_BACKFILL = 146;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 145;
|
||||
public static final int CURRENT_VERSION = 146;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -864,6 +865,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.ARCHIVE_BACKUP_ID, new ArchiveBackupIdReservationMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.QUOTE_THUMBNAIL_BACKFILL) {
|
||||
jobs.put(Version.QUOTE_THUMBNAIL_BACKFILL, new QuoteThumbnailBackfillMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.update
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable.Companion.DATA_FILE
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable.Companion.QUOTE
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable.Companion.QUOTE_PENDING_TRANSCODE
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable.Companion.TABLE_NAME
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobs.QuoteThumbnailBackfillJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import java.lang.Exception
|
||||
|
||||
/**
|
||||
* Kicks off the quote attachment thumbnail generation process by marking quote attachments
|
||||
* for processing and enqueueing a [QuoteThumbnailBackfillJob].
|
||||
*/
|
||||
internal class QuoteThumbnailBackfillMigrationJob(parameters: Parameters = Parameters.Builder().build()) : MigrationJob(parameters) {
|
||||
|
||||
companion object {
|
||||
val TAG = Log.tag(QuoteThumbnailBackfillMigrationJob::class.java)
|
||||
const val KEY = "QuoteThumbnailBackfillMigrationJob"
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
val markedCount = SignalDatabase.attachments.migrationMarkQuoteAttachmentsForThumbnailProcessing()
|
||||
SignalStore.misc.startedQuoteThumbnailMigration = true
|
||||
|
||||
Log.i(TAG, "Marked $markedCount quote attachments for thumbnail processing")
|
||||
|
||||
if (markedCount > 0) {
|
||||
AppDependencies.jobManager.add(QuoteThumbnailBackfillJob())
|
||||
} else {
|
||||
Log.i(TAG, "No quote attachments to process.")
|
||||
}
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
private fun AttachmentTable.migrationMarkQuoteAttachmentsForThumbnailProcessing(): Int {
|
||||
return writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
.values(QUOTE to QUOTE_PENDING_TRANSCODE)
|
||||
.where("$QUOTE != 0 AND $DATA_FILE NOT NULL")
|
||||
.run()
|
||||
}
|
||||
|
||||
class Factory : Job.Factory<QuoteThumbnailBackfillMigrationJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): QuoteThumbnailBackfillMigrationJob {
|
||||
return QuoteThumbnailBackfillMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user