Skip to content

Commit a2fa027

Browse files
Eitotbarijaona
authored andcommitted
Group file download notifications in Notification Centre
1 parent 02ad83b commit a2fa027

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

Vienna/Sources/Download window/DownloadManager.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#import "Preferences.h"
3030
#import "Vienna-Swift.h"
3131

32+
static NSString * const VNAUserNotificationFileDownloadThreadIdentifier = @"FileDownloadThreadIdentifier";
33+
3234
@interface DownloadManager ()
3335

3436
// Private properties
@@ -311,6 +313,9 @@ - (void)deliverNotificationForDownloadItem:(DownloadItem *)item {
311313
VNAUserNotificationRequest *request =
312314
[[VNAUserNotificationRequest alloc] initWithIdentifier:item.fileURL.absoluteString
313315
title:title];
316+
// Use a thread identifier to group all file download notifications
317+
// (this can be disabled by the user in System Settings).
318+
request.threadIdentifier = VNAUserNotificationFileDownloadThreadIdentifier;
314319
request.body = body;
315320
request.playSound = settings.isSoundEnabled;
316321
request.userInfo = userInfo;

Vienna/Sources/UserNotifications/UserNotificationCenter.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class UserNotificationCenter: NSObject {
154154
if let userInfo = request.userInfo {
155155
content.userInfo = userInfo
156156
}
157+
if let threadIdentifier = request.threadIdentifier {
158+
content.threadIdentifier = threadIdentifier
159+
}
157160
content.sound = request.playSound ? .default : nil
158161
let notificationRequest = UNNotificationRequest(
159162
identifier: request.identifier,
@@ -178,6 +181,7 @@ class UserNotificationCenter: NSObject {
178181
let request = notification.request
179182
return UserNotificationResponse(
180183
identifier: request.identifier,
184+
threadIdentifier: request.content.threadIdentifier,
181185
userInfo: request.content.userInfo
182186
)
183187
}
@@ -229,9 +233,11 @@ extension UserNotificationCenter: UNUserNotificationCenterDelegate {
229233
}
230234
let request = response.notification.request
231235
let identifier = request.identifier
236+
let threadIdentifier = request.content.threadIdentifier
232237
let userInfo = request.content.userInfo as? [String: AnyHashable]
233238
let response = UserNotificationResponse(
234239
identifier: identifier,
240+
threadIdentifier: threadIdentifier,
235241
userInfo: userInfo
236242
)
237243
delegate.userNotificationCenter(self, didReceive: response)

Vienna/Sources/UserNotifications/UserNotificationRequest.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class UserNotificationRequest: NSObject {
2525
/// The identifier of the notification.
2626
@objc let identifier: String
2727

28+
/// The identifier of the thread to which the notification belongs.
29+
@objc var threadIdentifier: String?
30+
2831
/// Additional user info that is attached to the notification.
2932
@objc var userInfo: [AnyHashable: Any]?
3033

Vienna/Sources/UserNotifications/UserNotificationResponse.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ class UserNotificationResponse: NSObject {
2525
/// The identifier of the notification.
2626
@objc let identifier: String
2727

28+
/// The identifier of the thread to which the notification belongs.
29+
@objc let threadIdentifier: String?
30+
2831
/// Additional user info that is attached to the notification.
2932
@objc let userInfo: [AnyHashable: Any]?
3033

3134
init(
3235
identifier: String,
36+
threadIdentifier: String? = nil,
3337
userInfo: [AnyHashable: Any]? = nil
3438
) {
3539
self.identifier = identifier
40+
self.threadIdentifier = threadIdentifier
3641
self.userInfo = userInfo
3742
}
3843

0 commit comments

Comments
 (0)