@@ -41,10 +41,10 @@ public class ParseRemote: OCKRemoteSynchronizable {
41
41
public var pckStoreClassesToSynchronize : [ PCKStoreClass : any PCKVersionable ] !
42
42
43
43
private weak var parseDelegate : ParseRemoteDelegate ?
44
- private var revisionRecordSubscription : SubscriptionCallback < PCKRevisionRecord > ?
44
+ private var clockRecordSubscription : SubscriptionCallback < PCKClock > ?
45
45
private var subscribeToServerUpdates : Bool
46
46
private let remoteStatus = RemoteSynchronizing ( )
47
- private let revisionRecordQuery : Query < PCKRevisionRecord >
47
+ private let clockQuery : Query < PCKClock >
48
48
49
49
/**
50
50
Creates an instance of ParseRemote.
@@ -67,7 +67,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
67
67
self . pckStoreClassesToSynchronize = try PCKStoreClass . patient. getConcrete ( )
68
68
self . customClassesToSynchronize = nil
69
69
self . uuid = uuid
70
- self . revisionRecordQuery = PCKRevisionRecord . query ( RevisionRecordKey . clockUUID == uuid)
70
+ self . clockQuery = PCKClock . query ( ClockKey . uuid == uuid)
71
71
self . automaticallySynchronizes = auto
72
72
self . subscribeToServerUpdates = subscribeToServerUpdates
73
73
if let currentUser = try ? await PCKUser . current ( ) {
@@ -144,7 +144,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
144
144
deinit {
145
145
Task {
146
146
do {
147
- try await revisionRecordQuery . unsubscribe ( )
147
+ try await clockQuery . unsubscribe ( )
148
148
Logger . deinitializer. error ( " Unsubscribed from clock query " )
149
149
} catch {
150
150
Logger . deinitializer. error ( " Couldn't unsubscribe from clock query " )
@@ -189,36 +189,37 @@ public class ParseRemote: OCKRemoteSynchronizable {
189
189
do {
190
190
_ = try await PCKUser . current ( )
191
191
guard self . subscribeToServerUpdates,
192
- self . revisionRecordSubscription == nil else {
192
+ self . clockRecordSubscription == nil else {
193
193
return
194
194
}
195
195
196
196
do {
197
- self . revisionRecordSubscription = try await self . revisionRecordQuery . subscribeCallback ( )
198
- self . revisionRecordSubscription ? . handleEvent { ( _, event) in
197
+ self . clockRecordSubscription = try await self . clockQuery . subscribeCallback ( )
198
+ self . clockRecordSubscription ? . handleEvent { ( _, event) in
199
199
switch event {
200
- case . created( let updatedRevision) , . updated( let updatedRevision) , . entered( let updatedRevision) :
201
- guard let logicalClock = updatedRevision. logicalClock else {
202
- Logger
203
- . revisionRecordSubscription
204
- . error ( " RevisionRecord missing required \" logicalClock \" key: \( updatedRevision) " )
205
- return
206
- }
207
- Task {
208
- guard await self . remoteStatus. hasNewerRevision ( logicalClock, for: self . uuid) else {
209
- return
200
+ case . created( let updatedClock) , . updated( let updatedClock) , . entered( let updatedClock) :
201
+ do {
202
+ let updatedVector = try PCKClock . decodeVector ( updatedClock)
203
+ Task {
204
+ guard await self . remoteStatus. hasNewerRevision ( updatedVector, for: self . uuid) else {
205
+ return
206
+ }
207
+ self . parseDelegate? . didRequestSynchronization ( self )
208
+ Logger
209
+ . clockSubscription
210
+ . log ( " Parse subscription is notifying that there are updates on the server " )
210
211
}
211
- self . parseDelegate ? . didRequestSynchronization ( self )
212
+ } catch {
212
213
Logger
213
- . revisionRecordSubscription
214
- . log ( " Parse remote has updates available " )
214
+ . clockSubscription
215
+ . error ( " Could not decode server clock: \( error ) " )
215
216
}
216
217
default :
217
218
return
218
219
}
219
220
}
220
221
} catch {
221
- Logger . revisionRecordSubscription . error ( " Couldn't subscribe to RevisionRecord query " )
222
+ Logger . clockSubscription . error ( " Couldn't subscribe to RevisionRecord query " )
222
223
return
223
224
}
224
225
} catch {
@@ -330,8 +331,8 @@ public class ParseRemote: OCKRemoteSynchronizable {
330
331
completion ( ParseCareKitError . requiredValueCantBeUnwrapped)
331
332
return
332
333
}
333
- let logicalClock = parseVector . clock ( for : self . uuid )
334
- guard await !self . remoteStatus. hasNewerRevision ( logicalClock , for: self . uuid) else {
334
+
335
+ guard await !self . remoteStatus. hasNewerRevision ( parseVector , for: self . uuid) else {
335
336
let errorString = " New knowledge on server. Pull first then try again "
336
337
Logger . pushRevisions. error ( " \( errorString) " )
337
338
await self . remoteStatus. notSynchronzing ( )
@@ -351,7 +352,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
351
352
// 8. Push conflict resolutions + local changes to remote
352
353
self . notifyRevisionProgress ( 0 ,
353
354
total: deviceRevisions. count)
354
-
355
+ let logicalClock = parseVector . clock ( for : self . uuid )
355
356
for (index, deviceRevision) in deviceRevisions. enumerated ( ) {
356
357
do {
357
358
let remoteRevision = try PCKRevisionRecord ( record: deviceRevision,
0 commit comments