From 793c8f83e0e6754cebf9d000ce163c4ccc160ea6 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Tue, 25 Apr 2023 10:46:40 -0400 Subject: [PATCH] Update clocks if new device added --- Sources/ParseCareKit/Models/RemoteSynchronizing.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/ParseCareKit/Models/RemoteSynchronizing.swift b/Sources/ParseCareKit/Models/RemoteSynchronizing.swift index 7bf7d6e71..8b98da60e 100644 --- a/Sources/ParseCareKit/Models/RemoteSynchronizing.swift +++ b/Sources/ParseCareKit/Models/RemoteSynchronizing.swift @@ -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 } }