Skip to content

Commit

Permalink
Fix handleIdConflicts
Browse files Browse the repository at this point in the history
We need to exclude new client IDs in the ID check
  • Loading branch information
Wavesonics committed Nov 2, 2024
1 parent 02aedc2 commit 140fe3c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,22 @@ class IdConflictResolutionOperation(
return CResult.success(newState)
}

private fun calculateLastClientIdWithoutNewIds(clientSyncData: ProjectSynchronizationData): Int {
return if (clientSyncData.newIds.isNotEmpty()) {
clientSyncData.newIds.min() - 1
} else {
clientSyncData.lastId
}
}

private suspend fun handleIdConflicts(
clientSyncData: ProjectSynchronizationData,
serverSyncData: ProjectSynchronizationBegan,
onLog: OnSyncLog
): ProjectSynchronizationData {

return if (serverSyncData.lastId >= clientSyncData.lastId) {
val lastClientIdWithoutNew = calculateLastClientIdWithoutNewIds(clientSyncData)
return if (serverSyncData.lastId > lastClientIdWithoutNew) {
if (clientSyncData.newIds.isNotEmpty()) {
var serverLastId = serverSyncData.lastId
val updatedNewIds = clientSyncData.newIds.toMutableList()
Expand Down

0 comments on commit 140fe3c

Please sign in to comment.