Skip to content

Commit cc78211

Browse files
committed
[trello.com/c/aZtAfZ44] remove + 1 from budge if message readed
1 parent e82a209 commit cc78211

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

NotificationServiceExtension/NotificationService.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class NotificationService: UNNotificationServiceExtension {
8787
if let lastReadIds,
8888
lastReadIds.contains(String(transaction.id)) {
8989
shouldIgnoreNotification = true
90-
return
9190
}
9291

9392
// MARK: 3. Working on transaction
@@ -333,22 +332,24 @@ class NotificationService: UNNotificationServiceExtension {
333332
if let data = try? JSONEncoder().encode(transaction), let transactionRaw = String(data: data, encoding: .utf8) {
334333
bestAttemptContent.userInfo[AdamantNotificationUserInfoKeys.transaction] = transactionRaw
335334
}
336-
bestAttemptContent.userInfo[AdamantNotificationUserInfoKeys.decodedMessage] = decodedMessage
337335

338-
// MARK: 8 Set current budge
339-
let storedBadgeString: String? = SecureStore.get(StoreKey.notificationsService.customBadgeNumber)
340-
let currentBadge = (Int(storedBadgeString ?? "0") ?? 0) + 1
341-
bestAttemptContent.badge = NSNumber(value: currentBadge)
342-
SecureStore.set(String(currentBadge), for: StoreKey.notificationsService.customBadgeNumber)
336+
// MARK: 8 Set current budge and Message
337+
var badgeValue = (Int(SecureStore.get(StoreKey.notificationsService.customBadgeNumber) ?? "0") ?? 0)
338+
if !shouldIgnoreNotification {
339+
badgeValue += 1
340+
bestAttemptContent.userInfo[AdamantNotificationUserInfoKeys.decodedMessage] = decodedMessage
341+
}
342+
343+
bestAttemptContent.badge = NSNumber(value: badgeValue)
344+
SecureStore.set(String(badgeValue), for: StoreKey.notificationsService.customBadgeNumber)
343345

344346
contentHandler(bestAttemptContent)
345347
}
346348

347349
override func serviceExtensionTimeWillExpire() {
348350
// Called just before the extension will be terminated by the system.
349351
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
350-
if !shouldIgnoreNotification,
351-
let contentHandler = contentHandler,
352+
if let contentHandler = contentHandler,
352353
let bestAttemptContent = bestAttemptContent {
353354
contentHandler(bestAttemptContent)
354355
}

0 commit comments

Comments
 (0)