TF-2871 Block notification on folders Sent, Outbox, Drafts, Spam and Trash
This commit is contained in:
+1
-1
@@ -323,7 +323,7 @@ SPEC CHECKSUMS:
|
||||
FirebaseInstallations: 558b1da7d65afeb996fd5c814332f013234ece4e
|
||||
FirebaseMessaging: e345b219fd15d325f0cf2fef28cb8ce00d851b3f
|
||||
fk_user_agent: 1f47ec39291e8372b1d692b50084b0d54103c545
|
||||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
||||
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
||||
flutter_appauth: 1ce438877bc111c5d8f42da47729909290624886
|
||||
flutter_downloader: b7301ae057deadd4b1650dc7c05375f10ff12c39
|
||||
flutter_image_compress_common: ec1d45c362c9d30a3f6a0426c297f47c52007e3e
|
||||
|
||||
@@ -68,6 +68,11 @@ class JmapClient {
|
||||
accountId: String,
|
||||
onComplete: @escaping ([Email], [Error]) -> Void) {
|
||||
guard hasMoreChanges, let sinceState = currentSinceState else {
|
||||
if !self.totalListEmails.isEmpty {
|
||||
let sortedListEmails = self.sortListEmails(currentListEmails: self.totalListEmails)
|
||||
self.totalListEmails = sortedListEmails
|
||||
}
|
||||
|
||||
return onComplete(self.totalListEmails, self.listErrors)
|
||||
}
|
||||
|
||||
@@ -85,8 +90,7 @@ class JmapClient {
|
||||
if let response = data.parsing(methodName: JmapConstants.EMAIL_GET_METHOD_NAME, methodCallId: "c1") {
|
||||
if let listEmail = response.list,
|
||||
!listEmail.isEmpty {
|
||||
let sortedListEmails = self.sortListEmails(currentListEmails: listEmail)
|
||||
self.totalListEmails.append(contentsOf: sortedListEmails)
|
||||
self.totalListEmails.append(contentsOf: listEmail)
|
||||
}
|
||||
self.hasMoreChanges = response.hasMoreChanges ?? false
|
||||
self.currentSinceState = response.newState
|
||||
@@ -97,6 +101,11 @@ class JmapClient {
|
||||
self.hasMoreChanges = false
|
||||
self.currentSinceState = nil
|
||||
|
||||
if !self.totalListEmails.isEmpty {
|
||||
let sortedListEmails = self.sortListEmails(currentListEmails: self.totalListEmails)
|
||||
self.totalListEmails = sortedListEmails
|
||||
}
|
||||
|
||||
onComplete(self.totalListEmails, self.listErrors)
|
||||
}
|
||||
},
|
||||
@@ -105,6 +114,11 @@ class JmapClient {
|
||||
self.hasMoreChanges = false
|
||||
self.currentSinceState = nil
|
||||
|
||||
if !self.totalListEmails.isEmpty {
|
||||
let sortedListEmails = self.sortListEmails(currentListEmails: self.totalListEmails)
|
||||
self.totalListEmails = sortedListEmails
|
||||
}
|
||||
|
||||
onComplete(self.totalListEmails, self.listErrors)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ struct Email: Codable {
|
||||
let preview: String?
|
||||
let from: [EmailAddress]?
|
||||
let receivedAt: String?
|
||||
let mailboxIds: [String: Bool]?
|
||||
|
||||
func getSenderName() -> String? {
|
||||
if (from == nil || from?.isEmpty == true) {
|
||||
|
||||
@@ -14,7 +14,8 @@ class JmapConstants {
|
||||
"subject",
|
||||
"preview",
|
||||
"from",
|
||||
"receivedAt"
|
||||
"receivedAt",
|
||||
"mailboxIds"
|
||||
]
|
||||
|
||||
static let EMAIL_ID = "email_id"
|
||||
|
||||
@@ -11,6 +11,7 @@ struct KeychainSharingSession: Codable {
|
||||
let basicAuth: String?
|
||||
let tokenEndpoint: String?
|
||||
let oidcScopes: [String]?
|
||||
let mailboxIdsBlockNotification: [String]?
|
||||
}
|
||||
|
||||
extension KeychainSharingSession {
|
||||
@@ -25,7 +26,8 @@ extension KeychainSharingSession {
|
||||
tokenOIDC: self.tokenOIDC,
|
||||
basicAuth: self.basicAuth,
|
||||
tokenEndpoint: self.tokenEndpoint,
|
||||
oidcScopes: self.oidcScopes
|
||||
oidcScopes: self.oidcScopes,
|
||||
mailboxIdsBlockNotification: self.mailboxIdsBlockNotification
|
||||
)
|
||||
}
|
||||
|
||||
@@ -45,7 +47,8 @@ extension KeychainSharingSession {
|
||||
),
|
||||
basicAuth: self.basicAuth,
|
||||
tokenEndpoint: self.tokenEndpoint,
|
||||
oidcScopes: self.oidcScopes
|
||||
oidcScopes: self.oidcScopes,
|
||||
mailboxIdsBlockNotification: self.mailboxIdsBlockNotification
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -85,31 +85,15 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
newEmailDeliveryState: newEmailDeliveryState
|
||||
)
|
||||
|
||||
if (emails.count > 1) {
|
||||
for email in emails {
|
||||
if (email.id == emails.last?.id) {
|
||||
self.showModifiedNotification(title: email.getSenderName(),
|
||||
subtitle: email.subject,
|
||||
body: email.preview,
|
||||
badgeCount: emails.count,
|
||||
userInfo: [JmapConstants.EMAIL_ID : email.id])
|
||||
return self.notify()
|
||||
} else {
|
||||
self.showNewNotification(title: email.getSenderName(),
|
||||
subtitle: email.subject,
|
||||
body: email.preview,
|
||||
badgeCount: emails.count,
|
||||
notificationId: email.id,
|
||||
userInfo: [JmapConstants.EMAIL_ID : email.id])
|
||||
}
|
||||
}
|
||||
let mailboxIdsBlockNotification = keychainSharingSession.mailboxIdsBlockNotification ?? []
|
||||
|
||||
if (mailboxIdsBlockNotification.isEmpty) {
|
||||
return self.showListNotification(emails: emails)
|
||||
} else {
|
||||
self.showModifiedNotification(title: emails.first!.getSenderName(),
|
||||
subtitle: emails.first!.subject,
|
||||
body: emails.first!.preview,
|
||||
badgeCount: 1,
|
||||
userInfo: [JmapConstants.EMAIL_ID : emails.first!.id])
|
||||
return self.notify()
|
||||
let emailFiltered = self.filterEmailsToPushNotification(
|
||||
emails: emails,
|
||||
mailboxIdsBlockNotification: mailboxIdsBlockNotification)
|
||||
return self.showListNotification(emails: emailFiltered)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@@ -121,7 +105,39 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func filterEmailsToPushNotification(emails: [Email], mailboxIdsBlockNotification: [String]) -> [Email] {
|
||||
return emails.filter { email in
|
||||
guard let mailboxIds = email.mailboxIds else { return true }
|
||||
for id in mailboxIds.keys {
|
||||
if mailboxIdsBlockNotification.contains(id) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private func showListNotification(emails: [Email]) {
|
||||
for email in emails {
|
||||
if (email.id == emails.last?.id) {
|
||||
self.showModifiedNotification(title: email.getSenderName(),
|
||||
subtitle: email.subject,
|
||||
body: email.preview,
|
||||
badgeCount: emails.count,
|
||||
userInfo: [JmapConstants.EMAIL_ID : email.id])
|
||||
return self.notify()
|
||||
} else {
|
||||
self.showNewNotification(title: email.getSenderName(),
|
||||
subtitle: email.subject,
|
||||
body: email.preview,
|
||||
badgeCount: emails.count,
|
||||
notificationId: email.id,
|
||||
userInfo: [JmapConstants.EMAIL_ID : email.id])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func showDefaultNotification(message: String) {
|
||||
self.modifiedContent?.title = InfoPlistReader(bundle: .app).bundleDisplayName
|
||||
self.modifiedContent?.body = message
|
||||
|
||||
Reference in New Issue
Block a user