fix home screen not reloading when coming into foreground

pull/541/head
Ryan Zhao 4 years ago
parent cc1b1e8c51
commit a8fd6d9d18

@ -229,7 +229,7 @@
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "App Store Release" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableUBSanitizer = "YES" enableUBSanitizer = "YES"

@ -17,6 +17,8 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
return result return result
}() }()
private var isReloading = false
// MARK: UI Components // MARK: UI Components
private lazy var seedReminderView: SeedReminderView = { private lazy var seedReminderView: SeedReminderView = {
let result = SeedReminderView(hasContinueButton: true) let result = SeedReminderView(hasContinueButton: true)
@ -131,6 +133,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
notificationCenter.addObserver(self, selector: #selector(handleLocalProfileDidChangeNotification(_:)), name: Notification.Name(kNSNotificationName_LocalProfileDidChange), object: nil) notificationCenter.addObserver(self, selector: #selector(handleLocalProfileDidChangeNotification(_:)), name: Notification.Name(kNSNotificationName_LocalProfileDidChange), object: nil)
notificationCenter.addObserver(self, selector: #selector(handleSeedViewedNotification(_:)), name: .seedViewed, object: nil) notificationCenter.addObserver(self, selector: #selector(handleSeedViewedNotification(_:)), name: .seedViewed, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleBlockedContactsUpdatedNotification(_:)), name: .blockedContactsUpdated, object: nil) notificationCenter.addObserver(self, selector: #selector(handleBlockedContactsUpdatedNotification(_:)), name: .blockedContactsUpdated, object: nil)
notificationCenter.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: .OWSApplicationDidBecomeActive, object: nil)
// Threads (part 2) // Threads (part 2)
threads = YapDatabaseViewMappings(groups: [ TSInboxGroup ], view: TSThreadDatabaseViewExtensionName) // The extension should be registered at this point threads = YapDatabaseViewMappings(groups: [ TSInboxGroup ], view: TSThreadDatabaseViewExtensionName) // The extension should be registered at this point
threads.setIsReversed(true, forGroup: TSInboxGroup) threads.setIsReversed(true, forGroup: TSInboxGroup)
@ -163,6 +166,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
reload() reload()
} }
@objc private func applicationDidBecomeActive(_ notification: Notification) {
reload()
}
deinit { deinit {
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
@ -181,6 +188,8 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
// MARK: Updating // MARK: Updating
private func reload() { private func reload() {
AssertIsOnMainThread() AssertIsOnMainThread()
guard !isReloading else { return }
isReloading = true
dbConnection.beginLongLivedReadTransaction() // Jump to the latest commit dbConnection.beginLongLivedReadTransaction() // Jump to the latest commit
dbConnection.read { transaction in dbConnection.read { transaction in
self.threads.update(with: transaction) self.threads.update(with: transaction)
@ -188,6 +197,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
threadViewModelCache.removeAll() threadViewModelCache.removeAll()
tableView.reloadData() tableView.reloadData()
emptyStateView.isHidden = (threadCount != 0) emptyStateView.isHidden = (threadCount != 0)
isReloading = false
} }
@objc private func handleYapDatabaseModifiedNotification(_ yapDatabase: YapDatabase) { @objc private func handleYapDatabaseModifiedNotification(_ yapDatabase: YapDatabase) {

Loading…
Cancel
Save