Skip to content

Commit 786b5a7

Browse files
committed
saveNotificationPersistence 保存扩展中的修改 同步至主项目
1 parent 2009340 commit 786b5a7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Sources/NotificationSession.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Sources/Synchronization/Strategies/PushNotificationStrategy.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ extension PushNotificationStrategy {
146146
conversation = ZMConversation.init(noRowCacheWithRemoteID: conversationID, createIfNeeded: false, in: moc)
147147
exLog.info("convertToLocalNotifications conversationID: \(conversationID) after fetch conversation from coredata")
148148
}
149-
//可能是系统通知 sendid 为00000000-0000-0000-0000-000000000002
150-
151-
// guard event.senderUUID() != self.accountIdentifier else {return nil}
152149
return ZMLocalNotification(noticationEvent: event, conversation: conversation, managedObjectContext: moc)
153150
}
154151
}

0 commit comments

Comments
 (0)