Skip to content

Commit 140fe3c

Browse files
committed
Fix handleIdConflicts
We need to exclude new client IDs in the ID check
1 parent 02aedc2 commit 140fe3c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

common/src/commonMain/kotlin/com/darkrockstudios/apps/hammer/common/data/sync/projectsync/operations/IdConflictResolutionOperation.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,22 @@ class IdConflictResolutionOperation(
6060
return CResult.success(newState)
6161
}
6262

63+
private fun calculateLastClientIdWithoutNewIds(clientSyncData: ProjectSynchronizationData): Int {
64+
return if (clientSyncData.newIds.isNotEmpty()) {
65+
clientSyncData.newIds.min() - 1
66+
} else {
67+
clientSyncData.lastId
68+
}
69+
}
70+
6371
private suspend fun handleIdConflicts(
6472
clientSyncData: ProjectSynchronizationData,
6573
serverSyncData: ProjectSynchronizationBegan,
6674
onLog: OnSyncLog
6775
): ProjectSynchronizationData {
6876

69-
return if (serverSyncData.lastId >= clientSyncData.lastId) {
77+
val lastClientIdWithoutNew = calculateLastClientIdWithoutNewIds(clientSyncData)
78+
return if (serverSyncData.lastId > lastClientIdWithoutNew) {
7079
if (clientSyncData.newIds.isNotEmpty()) {
7180
var serverLastId = serverSyncData.lastId
7281
val updatedNewIds = clientSyncData.newIds.toMutableList()

0 commit comments

Comments
 (0)