Merge pull request #3873 from signalapp/martin/IOS-2048b
avoiding duplicate timers and crashes in "debug" environment
This commit is contained in:
commit
681c22e2ca
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@ -42,27 +42,35 @@ public class HVRenderState: NSObject {
|
||||
}
|
||||
|
||||
@objc
|
||||
func thread(forIndexPath indexPath: IndexPath) -> TSThread? {
|
||||
func thread(forIndexPath indexPath: IndexPath, expectsSuccess: Bool = true) -> TSThread? {
|
||||
guard let section = HomeViewSection(rawValue: indexPath.section) else {
|
||||
owsFailDebug("Invalid section: \(indexPath.section).")
|
||||
if expectsSuccess {
|
||||
owsFailDebug("Invalid section: \(indexPath.section).")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
switch section {
|
||||
case .pinned:
|
||||
guard let thread = pinnedThreads[safe: indexPath.row]?.value else {
|
||||
owsFailDebug("No thread for index path: \(indexPath)")
|
||||
if expectsSuccess {
|
||||
owsFailDebug("No thread for index path: \(indexPath)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return thread
|
||||
case .unpinned:
|
||||
guard let thread = unpinnedThreads[safe: indexPath.row] else {
|
||||
owsFailDebug("No thread for index path: \(indexPath)")
|
||||
if expectsSuccess {
|
||||
owsFailDebug("No thread for index path: \(indexPath)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return thread
|
||||
default:
|
||||
owsFailDebug("Invalid index path: \(indexPath).")
|
||||
if expectsSuccess {
|
||||
owsFailDebug("Invalid index path: \(indexPath).")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@ -33,6 +33,8 @@ public class HVTableDataSource: NSObject {
|
||||
return
|
||||
}
|
||||
|
||||
updateTimer?.invalidate()
|
||||
updateTimer = nil
|
||||
if let interval = nextUpdateAt?.timeIntervalSinceNow {
|
||||
updateTimer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { [weak self] (_) in
|
||||
if let self = self {
|
||||
@ -44,9 +46,6 @@ public class HVTableDataSource: NSObject {
|
||||
}
|
||||
self?.updateAndSetRefreshTimer()
|
||||
}
|
||||
} else if updateTimer != nil {
|
||||
updateTimer?.invalidate()
|
||||
updateTimer = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,15 +85,15 @@ extension HVTableDataSource {
|
||||
}
|
||||
|
||||
@objc
|
||||
func threadViewModel(forIndexPath indexPath: IndexPath) -> ThreadViewModel? {
|
||||
guard let thread = self.thread(forIndexPath: indexPath) else {
|
||||
func threadViewModel(forIndexPath indexPath: IndexPath, expectsSuccess: Bool = true) -> ThreadViewModel? {
|
||||
guard let thread = self.thread(forIndexPath: indexPath, expectsSuccess: expectsSuccess) else {
|
||||
return nil
|
||||
}
|
||||
return self.threadViewModel(forThread: thread)
|
||||
}
|
||||
|
||||
func thread(forIndexPath indexPath: IndexPath) -> TSThread? {
|
||||
renderState.thread(forIndexPath: indexPath)
|
||||
func thread(forIndexPath indexPath: IndexPath, expectsSuccess: Bool = true) -> TSThread? {
|
||||
renderState.thread(forIndexPath: indexPath, expectsSuccess: expectsSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
@ -770,7 +769,7 @@ extension HVTableDataSource {
|
||||
public func updateVisibleCellContent(at indexPath: IndexPath, for tableView: UITableView) -> Bool {
|
||||
AssertIsOnMainThread()
|
||||
|
||||
if let primKey = threadViewModel(forIndexPath: indexPath)?.threadRecord.uniqueId, (tableView.indexPathsForVisibleRows ?? []).contains(indexPath) {
|
||||
if let primKey = threadViewModel(forIndexPath: indexPath, expectsSuccess: false)?.threadRecord.uniqueId, (tableView.indexPathsForVisibleRows ?? []).contains(indexPath) {
|
||||
for cell in tableView.visibleCells {
|
||||
if let homeCell = cell as? HomeViewCell, let myKey = homeCell.thread?.uniqueId, myKey == primKey, let token = buildCellConfigurationAndContentTokenSync(forIndexPath: indexPath)?.contentToken {
|
||||
homeCell.reset()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user