forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationService.swift
52 lines (44 loc) · 1.85 KB
/
NotificationService.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Foundation
import UserNotifications
import SwiftSignalKit
private let queue = Queue()
@available(iOSApplicationExtension 10.0, *)
@objc(NotificationService)
final class NotificationService: UNNotificationServiceExtension {
private let impl: QueueLocalObject<NotificationServiceImpl>
override init() {
self.impl = QueueLocalObject(queue: queue, generate: {
var completion: ((Int32) -> Void)?
let impl = NotificationServiceImpl(serialDispatch: { f in
queue.async {
f()
}
}, countIncomingMessage: { rootPath, accountId, encryptionParameters, peerId, messageId in
SyncProviderImpl.addIncomingMessage(queue: queue, withRootPath: rootPath, accountId: accountId, encryptionParameters: encryptionParameters, peerId: peerId, messageId: messageId, completion: { count in
completion?(count)
})
}, isLocked: { rootPath in
return SyncProviderImpl.isLocked(withRootPath: rootPath)
}, lockedMessageText: { rootPath in
return SyncProviderImpl.lockedMessageText(withRootPath: rootPath)
})
completion = { [weak impl] count in
queue.async {
impl?.updateUnreadCount(count)
}
}
return impl
})
super.init()
}
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.impl.with { impl in
impl.didReceive(request, withContentHandler: contentHandler)
}
}
override func serviceExtensionTimeWillExpire() {
self.impl.with { impl in
impl.serviceExtensionTimeWillExpire()
}
}
}