Skip to content

Commit

Permalink
Update clocks if new device added
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Apr 25, 2023
1 parent f124e1a commit 793c8f8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/ParseCareKit/Models/RemoteSynchronizing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ actor RemoteSynchronizing {
}

func hasNewerClock(_ vector: OCKRevisionRecord.KnowledgeVector, for uuid: UUID) -> Bool {
guard let currentClock = knowledgeVector?.clock(for: uuid) else {
guard let currentVector = knowledgeVector else {
return true
}
return vector.clock(for: uuid) > currentClock
var testVector = currentVector
testVector.merge(with: vector)
let currentClock = currentVector.clock(for: uuid)
return vector.clock(for: uuid) > currentClock || testVector.uuids.count > currentVector.uuids.count
}

func hasNewerVector(_ vector: OCKRevisionRecord.KnowledgeVector) -> Bool {
guard let currentVector = knowledgeVector else {
return true
}
return vector > currentVector
var testVector = currentVector
testVector.merge(with: vector)
return vector > currentVector || testVector.uuids.count > currentVector.uuids.count
}
}

0 comments on commit 793c8f8

Please sign in to comment.