Update to the new username link spec.

This commit is contained in:
Greyson Parrelli
2023-08-25 09:33:57 -04:00
parent a6dd4345ab
commit 8a93814bac
47 changed files with 1283 additions and 463 deletions

View File

@@ -136,9 +136,10 @@ public class ApplicationMigrations {
static final int ATTACHMENT_CLEANUP_3 = 92;
static final int EMOJI_SEARCH_INDEX_CHECK = 93;
static final int IDENTITY_FIX = 94;
static final int COPY_USERNAME_TO_SIGNAL_STORE = 95;
}
public static final int CURRENT_VERSION = 94;
public static final int CURRENT_VERSION = 95;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -617,6 +618,10 @@ public class ApplicationMigrations {
jobs.put(Version.IDENTITY_FIX, new IdentityTableCleanupMigrationJob());
}
if (lastSeenVersion < Version.COPY_USERNAME_TO_SIGNAL_STORE) {
jobs.put(Version.COPY_USERNAME_TO_SIGNAL_STORE, new CopyUsernameToSignalStoreMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,54 @@
package org.thoughtcrime.securesms.migrations
import org.signal.core.util.logging.Log
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.storage.StorageSyncHelper
/**
* Migration to copy any existing username to [SignalStore.account]
*/
internal class CopyUsernameToSignalStoreMigrationJob(
parameters: Parameters = Parameters.Builder().build()
) : MigrationJob(parameters) {
companion object {
const val KEY = "CopyUsernameToSignalStore"
val TAG = Log.tag(CopyUsernameToSignalStoreMigrationJob::class.java)
}
override fun getFactoryKey(): String = KEY
override fun isUiBlocking(): Boolean = false
override fun performMigration() {
if (SignalStore.account().aci == null || SignalStore.account().pni == null) {
Log.i(TAG, "ACI/PNI are unset, skipping.")
return
}
val self = Recipient.self()
if (self.username.isEmpty) {
Log.i(TAG, "No username set, skipping.")
return
}
SignalStore.account().username = self.username.get()
// New fields in storage service, so we trigger a sync
SignalDatabase.recipients.markNeedsSync(self.id)
StorageSyncHelper.scheduleSyncForDataChange()
}
override fun shouldRetry(e: Exception): Boolean = false
class Factory : Job.Factory<CopyUsernameToSignalStoreMigrationJob> {
override fun create(parameters: Parameters, serializedData: ByteArray?): CopyUsernameToSignalStoreMigrationJob {
return CopyUsernameToSignalStoreMigrationJob(parameters)
}
}
}