@@ -49,6 +49,8 @@ public class NotificationSession {
4949 public var lastEventId : UUID ?
5050
5151 private let operationLoop : RequestGeneratingOperationLoop
52+
53+ private var saveNotificationPersistence : ContextDidSaveNotificationPersistence
5254
5355 /// Initializes a new `SessionDirectory` to be used in an extension environment
5456 /// - parameter databaseDirectory: The `NSURL` of the shared group container
@@ -132,6 +134,7 @@ public class NotificationSession {
132134 transportSession: transportSession,
133135 operationLoop: operationLoop,
134136 sharedContainerURL: sharedContainerURL,
137+ accountContainer: accountContainer,
135138 accountIdentifier: accountIdentifier,
136139 isHuge: isHuge
137140 )
@@ -142,15 +145,22 @@ public class NotificationSession {
142145 transportSession: ZMTransportSession ,
143146 operationLoop: RequestGeneratingOperationLoop ,
144147 sharedContainerURL: URL ,
148+ accountContainer: URL ,
145149 accountIdentifier: UUID ,
146150 isHuge: Bool = false
147151 ) throws {
148152 self . syncMoc = moc
149153 self . transportSession = transportSession
150154 self . operationLoop = operationLoop
155+ self . saveNotificationPersistence = ContextDidSaveNotificationPersistence ( accountContainer: accountContainer)
151156 moc. performAndWait { [ unowned self] in
152157 self . lastEventId = isHuge ? moc. zm_lastHugeNotificationID : moc. zm_lastNotificationID
153158 }
159+ NotificationCenter . default. addObserver (
160+ self ,
161+ selector: #selector( SaveNotificationSession . contextDidSave ( _: ) ) ,
162+ name: . NSManagedObjectContextDidSave,
163+ object: moc)
154164 }
155165
156166 deinit {
@@ -159,3 +169,9 @@ public class NotificationSession {
159169 transportSession. tearDown ( )
160170 }
161171}
172+
173+ extension NotificationSession {
174+ @objc func contextDidSave( _ note: Notification ) {
175+ self . saveNotificationPersistence. add ( note)
176+ }
177+ }
0 commit comments