diff --git a/Signal/src/ViewControllers/HomeView/HVRenderState.swift b/Signal/src/ViewControllers/HomeView/HVRenderState.swift index 66e63ccc19..a223eadd14 100644 --- a/Signal/src/ViewControllers/HomeView/HVRenderState.swift +++ b/Signal/src/ViewControllers/HomeView/HVRenderState.swift @@ -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 } } diff --git a/Signal/src/ViewControllers/HomeView/HVTableDataSource.swift b/Signal/src/ViewControllers/HomeView/HVTableDataSource.swift index 8f4b048e89..d377dd058f 100644 --- a/Signal/src/ViewControllers/HomeView/HVTableDataSource.swift +++ b/Signal/src/ViewControllers/HomeView/HVTableDataSource.swift @@ -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()