From 3a1addbfe505936df4c40fa100a3fdcb97e6931b Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:23:13 -0800 Subject: [PATCH] Improve check in storage service comparator --- ts/services/storageRecordOps.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index 5db935168..81c1e30b3 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -748,20 +748,28 @@ function doRecordsConflict( continue; } + const isRemoteNullish = + !remoteValue || (Long.isLong(remoteValue) && remoteValue.isZero()); + const isLocalNullish = + !localValue || (Long.isLong(localValue) && localValue.isZero()); + // Sometimes we get `null` values from Protobuf and they should default to // false, empty string, or 0 for these records we do not count them as // conflicting. - if ( - (!remoteValue || (Long.isLong(remoteValue) && remoteValue.isZero())) && - (!localValue || (Long.isLong(localValue) && localValue.isZero())) - ) { + if (isRemoteNullish && isLocalNullish) { continue; } const areEqual = isEqual(localValue, remoteValue); if (!areEqual) { - details.push(`key=${key}: different values`); + if (isRemoteNullish) { + details.push(`key=${key}: removed`); + } else if (isLocalNullish) { + details.push(`key=${key}: added`); + } else { + details.push(`key=${key}: different values`); + } } }