add a process to clean up any expired messages before loading initial screen after app launch

pull/955/head
Ryan ZHAO 2 months ago
parent 041038476a
commit 2e4c11f4b9

@ -320,6 +320,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
Configuration.performMainSetup()
JobRunner.setExecutor(SyncPushTokensJob.self, for: .syncPushTokens)
/// We need to do a clean up for disappear after send messages that are received by push notifications before
/// the app set up the main screen and load initial data to prevent a case when the PagedDatabaseObserver
/// hasn't been setup yet then the conversation screen can show stale (ie. deleted) interactions incorrectly
DisappearingMessagesJob.cleanExpiredMessagesOnLaunch()
// Setup the UI if needed, then trigger any post-UI setup actions
self.ensureRootViewController(calledFrom: lifecycleMethod) { [weak self] success in
// If we didn't successfully ensure the rootViewController then don't continue as

@ -46,6 +46,24 @@ public enum DisappearingMessagesJob: JobExecutor {
}
}
// MARK: - Clean expired messages on app launch
public extension DisappearingMessagesJob {
static func cleanExpiredMessagesOnLaunch() {
let timestampNowMs: TimeInterval = TimeInterval(SnodeAPI.currentOffsetTimestampMs())
var numDeleted: Int = -1
Storage.shared.write { db in
numDeleted = try Interaction
.filter(Interaction.Columns.expiresStartedAtMs != nil)
.filter((Interaction.Columns.expiresStartedAtMs + (Interaction.Columns.expiresInSeconds * 1000)) <= timestampNowMs)
.deleteAll(db)
}
SNLog("[DisappearingMessagesJob] Deleted \(numDeleted) expired messages on app launch.")
}
}
// MARK: - Convenience
public extension DisappearingMessagesJob {

Loading…
Cancel
Save