Skip to content

Commit

Permalink
Migrate ephemeral timer notification
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Jul 16, 2024
1 parent c4e34e4 commit 7b8e7af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 3 additions & 2 deletions DcCore/DcCore/DC/events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
])
}
Expand Down
11 changes: 7 additions & 4 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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)
}
}

Expand Down
17 changes: 11 additions & 6 deletions deltachat-ios/Controller/GroupChatDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 7b8e7af

Please sign in to comment.