Browse Source

add a option to disable notifications

B. Petersen 5 years ago
parent
commit
ed1960126c
2 changed files with 21 additions and 12 deletions
  1. 7 0
      deltachat-ios/Controller/SettingsController.swift
  2. 14 12
      deltachat-ios/DC/events.swift

+ 7 - 0
deltachat-ios/Controller/SettingsController.swift

@@ -188,6 +188,13 @@ internal final class SettingsViewController: QuickTableViewController {
                     NavigationRow(text: String.localized("pref_blocked_contacts"),
                               detailText: .none,
                               action: { [weak self] in self?.showBlockedContacts($0) }),
+                    SwitchRow(text: String.localized("pref_notifications"),
+                              switchValue: !UserDefaults.standard.bool(forKey: "notifications_disabled"),
+                              action: { row in
+                                if let row = row as? SwitchRow {
+                                    UserDefaults.standard.set(!row.switchValue, forKey: "notifications_disabled")
+                                }
+                    }),
                     SwitchRow(text: String.localized("pref_read_receipts"),
                               switchValue: DcConfig.mdnsEnabled,
                               action: { row in

+ 14 - 12
deltachat-ios/DC/events.swift

@@ -101,18 +101,20 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
                     object: nil,
                     userInfo: userInfo)
 
-            let content = UNMutableNotificationContent()
-            let msg = DcMsg(id: Int(data2))
-            content.title = msg.fromContact.displayName
-            content.body = msg.summary(chars: 40) ?? ""
-            content.userInfo = userInfo
-            content.sound = .default
-
-            let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
-
-            let request = UNNotificationRequest(identifier: Constants.notificationIdentifier, content: content, trigger: trigger)
-            UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
-            logger.info("notifications: added \(content)")
+            if !UserDefaults.standard.bool(forKey: "notifications_disabled") {
+                let content = UNMutableNotificationContent()
+                let msg = DcMsg(id: Int(data2))
+                content.title = msg.fromContact.displayName
+                content.body = msg.summary(chars: 40) ?? ""
+                content.userInfo = userInfo
+                content.sound = .default
+
+                let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
+
+                let request = UNNotificationRequest(identifier: Constants.notificationIdentifier, content: content, trigger: trigger)
+                UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
+                logger.info("notifications: added \(content)")
+            }
 
             let array = DcArray(arrayPointer: dc_get_fresh_msgs(mailboxPointer))
             UIApplication.shared.applicationIconBadgeNumber = array.count