|
|
@ -9,6 +9,8 @@ class OWS106EnsureProfileComplete: OWSDatabaseMigration {
|
|
|
|
|
|
|
|
|
|
|
|
let TAG = "[OWS106EnsureProfileComplete]"
|
|
|
|
let TAG = "[OWS106EnsureProfileComplete]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static var sharedCompleteRegistrationFixerJob: CompleteRegistrationFixerJob?
|
|
|
|
|
|
|
|
|
|
|
|
// increment a similar constant for each migration.
|
|
|
|
// increment a similar constant for each migration.
|
|
|
|
class func migrationId() -> String {
|
|
|
|
class func migrationId() -> String {
|
|
|
|
return "106"
|
|
|
|
return "106"
|
|
|
@ -17,10 +19,19 @@ class OWS106EnsureProfileComplete: OWSDatabaseMigration {
|
|
|
|
// Overriding runUp since we have some specific completion criteria which
|
|
|
|
// Overriding runUp since we have some specific completion criteria which
|
|
|
|
// is more likely to fail since it involves network requests.
|
|
|
|
// is more likely to fail since it involves network requests.
|
|
|
|
override func runUp() {
|
|
|
|
override func runUp() {
|
|
|
|
CompleteRegistrationFixerJob(completionHandler: {
|
|
|
|
guard type(of: self).sharedCompleteRegistrationFixerJob == nil else {
|
|
|
|
|
|
|
|
owsFail("\(self.TAG) should only be called once.")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let job = CompleteRegistrationFixerJob(completionHandler: {
|
|
|
|
Logger.info("\(self.TAG) Completed. Saving.")
|
|
|
|
Logger.info("\(self.TAG) Completed. Saving.")
|
|
|
|
self.save()
|
|
|
|
self.save()
|
|
|
|
}).start()
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type(of: self).sharedCompleteRegistrationFixerJob = job
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
job.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -38,14 +49,14 @@ class OWS106EnsureProfileComplete: OWSDatabaseMigration {
|
|
|
|
var timer: Timer?
|
|
|
|
var timer: Timer?
|
|
|
|
let completionHandler: () -> Void
|
|
|
|
let completionHandler: () -> Void
|
|
|
|
|
|
|
|
|
|
|
|
init (completionHandler: @escaping () -> Void) {
|
|
|
|
init(completionHandler: @escaping () -> Void) {
|
|
|
|
self.completionHandler = completionHandler
|
|
|
|
self.completionHandler = completionHandler
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func start() {
|
|
|
|
func start() {
|
|
|
|
assert(self.timer == nil)
|
|
|
|
assert(self.timer == nil)
|
|
|
|
|
|
|
|
|
|
|
|
let timer = WeakTimer.scheduledTimer(timeInterval: CompleteRegistrationFixerJob.kRetryInterval, target: self, userInfo: nil, repeats: true) { [weak self] timer in
|
|
|
|
let timer = WeakTimer.scheduledTimer(timeInterval: CompleteRegistrationFixerJob.kRetryInterval, target: self, userInfo: nil, repeats: true) { [weak self] aTimer in
|
|
|
|
guard let strongSelf = self else {
|
|
|
|
guard let strongSelf = self else {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -58,7 +69,7 @@ class OWS106EnsureProfileComplete: OWSDatabaseMigration {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Logger.info("\(strongSelf.TAG) complete. Canceling timer and saving.")
|
|
|
|
Logger.info("\(strongSelf.TAG) complete. Canceling timer and saving.")
|
|
|
|
isCompleted = true
|
|
|
|
isCompleted = true
|
|
|
|
timer.invalidate()
|
|
|
|
aTimer.invalidate()
|
|
|
|
strongSelf.completionHandler()
|
|
|
|
strongSelf.completionHandler()
|
|
|
|
}.catch { error in
|
|
|
|
}.catch { error in
|
|
|
|
Logger.error("\(strongSelf.TAG) failed with \(error). We'll try again in \(CompleteRegistrationFixerJob.kRetryInterval) seconds.")
|
|
|
|
Logger.error("\(strongSelf.TAG) failed with \(error). We'll try again in \(CompleteRegistrationFixerJob.kRetryInterval) seconds.")
|
|
|
|