mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Add support for avatar colors in storage service.
This commit is contained in:
committed by
Michelle Tang
parent
93d18c1763
commit
83611414cc
@@ -173,9 +173,10 @@ public class ApplicationMigrations {
|
||||
static final int FTS_TRIGGER_FIX = 129;
|
||||
static final int THREAD_TABLE_PINNED_MIGRATION = 130;
|
||||
static final int GROUP_DECLINE_INVITE_FIX = 131;
|
||||
static final int AVATAR_COLOR_MIGRATION_JOB = 132;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 131;
|
||||
public static final int CURRENT_VERSION = 132;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -798,6 +799,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.GROUP_DECLINE_INVITE_FIX, new DatabaseMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.AVATAR_COLOR_MIGRATION_JOB) {
|
||||
jobs.put(Version.AVATAR_COLOR_MIGRATION_JOB, new AvatarColorStorageServiceMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.requireLong
|
||||
import org.signal.core.util.select
|
||||
import org.signal.core.util.withinTransaction
|
||||
import org.thoughtcrime.securesms.database.RecipientTable
|
||||
import org.thoughtcrime.securesms.database.RecipientTable.Companion.ID
|
||||
import org.thoughtcrime.securesms.database.RecipientTable.Companion.STORAGE_SERVICE_ID
|
||||
import org.thoughtcrime.securesms.database.RecipientTable.Companion.TABLE_NAME
|
||||
import org.thoughtcrime.securesms.database.RecipientTable.Companion.TYPE
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
|
||||
/**
|
||||
* A job that marks all contacts and groups as needing to be synced, so that we'll update the
|
||||
* storage records with the new avatar color field.
|
||||
*/
|
||||
internal class AvatarColorStorageServiceMigrationJob(
|
||||
parameters: Parameters = Parameters.Builder().build()
|
||||
) : MigrationJob(parameters) {
|
||||
|
||||
companion object {
|
||||
val TAG = Log.tag(AvatarColorStorageServiceMigrationJob::class.java)
|
||||
const val KEY = "AvatarColorStorageServiceMigrationJob"
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
if (!Recipient.isSelfSet) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!SignalStore.account.isRegistered) {
|
||||
return
|
||||
}
|
||||
|
||||
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||
SignalDatabase.recipients.markAllContactsAndGroupsAsNeedsSync()
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
private fun RecipientTable.markAllContactsAndGroupsAsNeedsSync() {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
db.select(ID)
|
||||
.from(TABLE_NAME)
|
||||
.where("$STORAGE_SERVICE_ID NOT NULL AND $TYPE IN (${RecipientTable.RecipientType.INDIVIDUAL.id}, ${RecipientTable.RecipientType.GV2.id})")
|
||||
.run()
|
||||
.use { cursor ->
|
||||
while (cursor.moveToNext()) {
|
||||
rotateStorageId(RecipientId.from(cursor.requireLong(ID)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Factory : Job.Factory<AvatarColorStorageServiceMigrationJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): AvatarColorStorageServiceMigrationJob {
|
||||
return AvatarColorStorageServiceMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user