diff --git a/DcCore/DcCore/DC/events.swift b/DcCore/DcCore/DC/events.swift index 0b8961de2..fc22e089b 100644 --- a/DcCore/DcCore/DC/events.swift +++ b/DcCore/DcCore/DC/events.swift @@ -24,9 +24,10 @@ extension Notification.Name { // Webxdc public static let webxdcStatusUpdate = Notification.Name(rawValue: "eventWebxdcStatusUpdate") public static let webxdcRealtimeDataReceived = Notification.Name(rawValue: "eventWebxdcRealtimeData") + + public static let ephemeralTimerModified = Notification.Name(rawValue: "eventEphemeralTimerModified") } -public let eventEphemeralTimerModified = Notification.Name(rawValue: "eventEphemeralTimerModified") public class DcEventHandler { let dcAccounts: DcAccounts @@ -128,7 +129,7 @@ public class DcEventHandler { } logger.info("📡[\(accountId)] ephemeral timer modified: \(data1)") DispatchQueue.main.async { - NotificationCenter.default.post(name: eventEphemeralTimerModified, object: nil, userInfo: [ + NotificationCenter.default.post(name: .ephemeralTimerModified, object: nil, userInfo: [ "chat_id": Int(data1), ]) } diff --git a/deltachat-ios/Chat/ChatViewController.swift b/deltachat-ios/Chat/ChatViewController.swift index b4ac2aaae..262e439b5 100644 --- a/deltachat-ios/Chat/ChatViewController.swift +++ b/deltachat-ios/Chat/ChatViewController.swift @@ -418,6 +418,10 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate { // MARK: - Notifications + @objc private func handleEphemeralTimerModified(_ notification: Notification) { + updateTitle() + } + @objc private func handleChatModified(_ notification: Notification) { guard let ui = notification.userInfo, chatId == ui["chat_id"] as? Int else { return } @@ -545,11 +549,10 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate { if ephemeralTimerModifiedObserver == nil { ephemeralTimerModifiedObserver = nc.addObserver( - forName: eventEphemeralTimerModified, + forName: .ephemeralTimerModified, object: nil, queue: OperationQueue.main - ) { [weak self] _ in - guard let self else { return } - self.updateTitle() + ) { [weak self] notification in + self?.handleEphemeralTimerModified(notification) } } diff --git a/deltachat-ios/Controller/GroupChatDetailViewController.swift b/deltachat-ios/Controller/GroupChatDetailViewController.swift index 36b4db35d..96cd69526 100644 --- a/deltachat-ios/Controller/GroupChatDetailViewController.swift +++ b/deltachat-ios/Controller/GroupChatDetailViewController.swift @@ -240,14 +240,11 @@ class GroupChatDetailViewController: UIViewController { self?.handleIncomingMessage(notification) } ephemeralTimerObserver = nc.addObserver( - forName: eventEphemeralTimerModified, + forName: .ephemeralTimerModified, object: nil, queue: OperationQueue.main) { [weak self] notification in - guard let self else { return } - if let ui = notification.userInfo, - self.chatId == ui["chat_id"] as? Int { - self.updateEphemeralTimerCellValue() - } + self?.handleEphemeralTimerModified(notification) + } chatModifiedObserver = nc.addObserver( forName: .chatModified, @@ -272,6 +269,14 @@ class GroupChatDetailViewController: UIViewController { // MARK: - Notifications + @objc private func handleEphemeralTimerModified(_ notification: Notification) { + guard let ui = notification.userInfo, + let chatId = ui["chat_id"] as? Int, + self.chatId == chatId else { return } + + self.updateEphemeralTimerCellValue() + } + @objc private func handleChatModified(_ notification: Notification) { guard let ui = notification.userInfo,