TF-2464 Set default notification message when email changed

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 98937eca3b44e70100bbfb55d32bb713e8f6e8b2)
This commit is contained in:
dab246
2024-01-17 12:42:18 +07:00
committed by Dat PHAM HOANG
parent defe71843f
commit 642121dea3
5 changed files with 14 additions and 5 deletions
+2 -1
View File
@@ -1 +1,2 @@
"newMessageInTwakeMail" = "You have new emails";
"newMessageInTwakeMail" = "You have new emails";
"newNotificationInTwakeMail" = "You have a new notification";
+2 -1
View File
@@ -1 +1,2 @@
"newMessageInTwakeMail" = "Vous avez de nouveaux e-mails";
"newMessageInTwakeMail" = "Vous avez de nouveaux e-mails";
"newNotificationInTwakeMail" = "Vous avez une nouvelle notification";
+2 -1
View File
@@ -1 +1,2 @@
"newMessageInTwakeMail" = "У вас есть новые электронные письма";
"newMessageInTwakeMail" = "У вас есть новые электронные письма";
"newNotificationInTwakeMail" = "У вас новое объявление";
+2 -1
View File
@@ -1 +1,2 @@
"newMessageInTwakeMail" = "Bạn có email mới";
"newMessageInTwakeMail" = "Bạn có email mới";
"newNotificationInTwakeMail" = "Bạn có thông báo mới";
+6 -1
View File
@@ -4,6 +4,7 @@ import SwiftUI
class NotificationService: UNNotificationServiceExtension {
private let newEmailDefaultMessageKey: String = "newMessageInTwakeMail"
private let newNotificationDefaultMessageKey: String = "newNotificationInTwakeMail"
private var handler: ((UNNotificationContent) -> Void)?
private var modifiedContent: UNMutableNotificationContent?
@@ -16,11 +17,11 @@ class NotificationService: UNNotificationServiceExtension {
modifiedContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
self.modifiedContent?.title = InfoPlistReader(bundle: .app).bundleDisplayName
self.modifiedContent?.body = NSLocalizedString(newEmailDefaultMessageKey, comment: "Localizable")
self.modifiedContent?.badge = NSNumber(value: 1)
guard let payloadData = request.content.userInfo as? [String: Any],
!keychainController.retrieveSharingSessions().isEmpty else {
self.modifiedContent?.body = NSLocalizedString(newEmailDefaultMessageKey, comment: "Localizable")
return self.notify()
}
@@ -29,6 +30,7 @@ class NotificationService: UNNotificationServiceExtension {
await handleGetNewEmails(payloadData: payloadData)
}
} else {
self.modifiedContent?.body = NSLocalizedString(newEmailDefaultMessageKey, comment: "Localizable")
return self.notify()
}
}
@@ -44,6 +46,7 @@ class NotificationService: UNNotificationServiceExtension {
let mapStateChanges: [String: [TypeName: String]] = PayloadParser.shared.parsingPayloadNotification(payloadData: payloadData)
if (mapStateChanges.isEmpty) {
self.modifiedContent?.body = NSLocalizedString(newEmailDefaultMessageKey, comment: "Localizable")
return self.notify()
} else {
guard let currentAccountId = mapStateChanges.keys.first,
@@ -53,6 +56,7 @@ class NotificationService: UNNotificationServiceExtension {
let oldEmailState = keychainSharingSession.emailState,
newEmailState != oldEmailState,
keychainSharingSession.tokenOIDC != nil || keychainSharingSession.basicAuth != nil else {
self.modifiedContent?.body = NSLocalizedString(newNotificationDefaultMessageKey, comment: "Localizable")
return self.notify()
}
@@ -67,6 +71,7 @@ class NotificationService: UNNotificationServiceExtension {
oidcScopes: keychainSharingSession.oidcScopes,
onComplete: { (emails, errors) in
if emails.isEmpty {
self.modifiedContent?.body = NSLocalizedString(self.newNotificationDefaultMessageKey, comment: "Localizable")
return self.notify()
} else {
self.keychainController.updateEmailStateToKeychain(accountId: keychainSharingSession.accountId, newState: newEmailState)