Migrate existing raw contacts to add video call links.

This commit is contained in:
Ehren Kret 2024-05-17 14:36:44 -05:00 committed by Cody Henthorne
parent 870aa8e7b0
commit 6184cc0307
3 changed files with 66 additions and 1 deletions

View file

@ -50,6 +50,7 @@ import org.thoughtcrime.securesms.migrations.BackupNotificationMigrationJob;
import org.thoughtcrime.securesms.migrations.BlobStorageLocationMigrationJob;
import org.thoughtcrime.securesms.migrations.CachedAttachmentsMigrationJob;
import org.thoughtcrime.securesms.migrations.ClearGlideCacheMigrationJob;
import org.thoughtcrime.securesms.migrations.ContactLinkRebuildMigrationJob;
import org.thoughtcrime.securesms.migrations.CopyUsernameToSignalStoreMigrationJob;
import org.thoughtcrime.securesms.migrations.DatabaseMigrationJob;
import org.thoughtcrime.securesms.migrations.DeleteDeprecatedLogsMigrationJob;
@ -124,6 +125,7 @@ public final class JobManagerFactories {
put(CallSyncEventJob.KEY, new CallSyncEventJob.Factory());
put(CheckServiceReachabilityJob.KEY, new CheckServiceReachabilityJob.Factory());
put(CleanPreKeysJob.KEY, new CleanPreKeysJob.Factory());
put(ContactLinkRebuildMigrationJob.KEY, new ContactLinkRebuildMigrationJob.Factory());
put(ConversationShortcutRankingUpdateJob.KEY, new ConversationShortcutRankingUpdateJob.Factory());
put(ConversationShortcutUpdateJob.KEY, new ConversationShortcutUpdateJob.Factory());
put(CreateReleaseChannelJob.KEY, new CreateReleaseChannelJob.Factory());

View file

@ -147,9 +147,10 @@ public class ApplicationMigrations {
static final int EMOJI_VERSION_10 = 103;
static final int ATTACHMENT_HASH_BACKFILL = 104;
static final int SUBSCRIBER_ID = 105;
static final int CONTACT_LINK_REBUILD = 106;
}
public static final int CURRENT_VERSION = 105;
public static final int CURRENT_VERSION = 106;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@ -672,6 +673,10 @@ public class ApplicationMigrations {
jobs.put(Version.SUBSCRIBER_ID, new SubscriberIdMigrationJob());
}
if (lastSeenVersion < Version.CONTACT_LINK_REBUILD) {
jobs.put(Version.CONTACT_LINK_REBUILD, new ContactLinkRebuildMigrationJob());
}
return jobs;
}

View file

@ -0,0 +1,58 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.migrations
import org.signal.contacts.SystemContactsRepository
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.BuildConfig
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.jobs.SyncSystemContactLinksJob
/**
* This migration job is responsible for rebuilding the contact links for all contacts in the system. Contact links
* refers to the raw contact table entries that are used to place links into the system contacts app to message,
* voice, and video call a given contact on Signal. This job is necessary to ensure that all contacts have the correct
* links in the system contacts app. At the time of writing, this job is adding the video call link and changing the
* text of the voice call link to "Signal Voice Call" instead of "Signal Call". This job could be reused in the future
* if other links are added or changed.
*/
internal class ContactLinkRebuildMigrationJob(parameters: Parameters = Parameters.Builder().build()) : MigrationJob(parameters) {
companion object {
private val TAG = Log.tag(ContactLinkRebuildMigrationJob::class.java)
const val KEY = "ContactLinkRebuildMigrationJob"
}
override fun getFactoryKey(): String = KEY
override fun isUiBlocking(): Boolean = false
override fun performMigration() {
val account = SystemContactsRepository.getOrCreateSystemAccount(context, BuildConfig.APPLICATION_ID, context.getString(R.string.app_name))
if (account == null) {
Log.w(TAG, "Failed to create an account!")
return
}
SystemContactsRepository.addMessageAndCallLinksToContacts(
context = context,
config = SyncSystemContactLinksJob.buildContactLinkConfiguration(context, account),
targetE164s = emptySet(),
removeIfMissing = true
)
ApplicationDependencies.getJobManager().add(SyncSystemContactLinksJob())
}
override fun shouldRetry(e: Exception): Boolean = false
class Factory : Job.Factory<ContactLinkRebuildMigrationJob> {
override fun create(parameters: Parameters, serializedData: ByteArray?): ContactLinkRebuildMigrationJob {
return ContactLinkRebuildMigrationJob(parameters)
}
}
}