Skip to content

Commit 5d3f8d9

Browse files
authored
setUpLocalIdentifiers should check for deregistered instances
1 parent 80a6816 commit 5d3f8d9

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

Signal/AppLaunch/AppDelegate.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,10 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
551551
hasInProgressRegistration = false
552552
}
553553

554-
switch finalContinuation.setUpLocalIdentifiers(willResumeInProgressRegistration: hasInProgressRegistration) {
554+
switch finalContinuation.setUpLocalIdentifiers(
555+
willResumeInProgressRegistration: hasInProgressRegistration,
556+
canInitiateRegistration: true
557+
) {
555558
case .corruptRegistrationState:
556559
let viewController = terminalErrorViewController()
557560
window.rootViewController = viewController

SignalNSE/NotificationService.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ class NotificationService: UNNotificationServiceExtension {
126126
// Re-warm the caches each time to pick up changes made by the main app.
127127
finalContinuation.runLaunchTasksIfNeededAndReloadCaches()
128128
// Re-set up the local identifiers to ensure they're propagated throughout the system.
129-
switch finalContinuation.setUpLocalIdentifiers(willResumeInProgressRegistration: false) {
129+
switch finalContinuation.setUpLocalIdentifiers(
130+
willResumeInProgressRegistration: false,
131+
canInitiateRegistration: false
132+
) {
130133
case .corruptRegistrationState:
131134
Logger.warn("Ignoring request to process notifications when the user isn't registered.")
132135
return UNNotificationContent()

SignalServiceKit/Environment/AppSetup.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,23 +1698,27 @@ extension AppSetup.FinalContinuation {
16981698
}
16991699

17001700
@MainActor
1701-
public func setUpLocalIdentifiers(willResumeInProgressRegistration: Bool) -> SetupError? {
1701+
public func setUpLocalIdentifiers(
1702+
willResumeInProgressRegistration: Bool,
1703+
canInitiateRegistration: Bool
1704+
) -> SetupError? {
17021705
let storageServiceManager = sskEnvironment.storageServiceManagerRef
17031706
let tsAccountManager = DependenciesBridge.shared.tsAccountManager
17041707

17051708
let registrationState = tsAccountManager.registrationStateWithMaybeSneakyTransaction
1709+
let canInitiateReregistration = registrationState.isDeregistered && canInitiateRegistration
17061710

17071711
if registrationState.isRegistered {
17081712
// TODO: Enforce already-true invariant "registered means LocalIdentifiers" via the compiler.
17091713
let localIdentifiers = tsAccountManager.localIdentifiersWithMaybeSneakyTransaction!
17101714
storageServiceManager.setLocalIdentifiers(localIdentifiers)
1711-
} else if !willResumeInProgressRegistration {
1715+
} else if !willResumeInProgressRegistration && !canInitiateReregistration {
17121716
// We aren't registered, and we're not in the middle of registration, so
17131717
// throw an error about corrupt registration.
17141718
return .corruptRegistrationState
17151719
}
17161720

1717-
if !willResumeInProgressRegistration {
1721+
if !willResumeInProgressRegistration && !canInitiateReregistration {
17181722
// We are fully registered, and we're not in the middle of registration, so
17191723
// ensure discoverability is configured.
17201724
setUpDefaultDiscoverability()

SignalShareExtension/ShareViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
9999

100100
let finalContinuation = await databaseContinuation.prepareDatabase()
101101
finalContinuation.runLaunchTasksIfNeededAndReloadCaches()
102-
switch finalContinuation.setUpLocalIdentifiers(willResumeInProgressRegistration: false) {
102+
switch finalContinuation.setUpLocalIdentifiers(
103+
willResumeInProgressRegistration: false,
104+
canInitiateRegistration: false
105+
) {
103106
case .corruptRegistrationState:
104107
self.showNotRegisteredView()
105108
return

0 commit comments

Comments
 (0)