|
@@ -278,26 +278,29 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
|
|
|
private func startTimer() {
|
|
|
- // check if the timer is not yet started
|
|
|
- if !(timer?.isValid ?? false) {
|
|
|
- timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) { [weak self] _ in
|
|
|
- //reload table
|
|
|
- DispatchQueue.main.async {
|
|
|
- guard let self = self, let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
|
|
|
- if appDelegate.appIsInForeground() {
|
|
|
- self.messageIds = self.getMessageIds()
|
|
|
- self.reloadData()
|
|
|
- }
|
|
|
+ stopTimer()
|
|
|
+ timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) { [weak self] _ in
|
|
|
+ // reload table
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
+ guard let self = self,
|
|
|
+ let appDelegate = UIApplication.shared.delegate as? AppDelegate
|
|
|
+ else { return }
|
|
|
+
|
|
|
+ if appDelegate.appIsInForeground() {
|
|
|
+ self.messageIds = self.getMessageIds()
|
|
|
+ self.reloadData()
|
|
|
+ } else {
|
|
|
+ logger.warning("startTimer() must not be executed in background")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private func stopTimer() {
|
|
|
- // check if the timer is not already stopped
|
|
|
- if timer?.isValid ?? false {
|
|
|
- timer?.invalidate()
|
|
|
+ if let timer = timer {
|
|
|
+ timer.invalidate()
|
|
|
}
|
|
|
+ timer = nil
|
|
|
}
|
|
|
|
|
|
private func configureEmptyStateView() {
|