fix(snjs): keep apply payload timestamp when using keep base conflict strategy (#2031)

This commit is contained in:
Mo
2022-11-17 21:51:06 -06:00
committed by GitHub
parent bc12663c7f
commit 87f86693a6
3 changed files with 57 additions and 7 deletions

View File

@@ -99,4 +99,22 @@ describe('conflict delta', () => {
expect(delta.getConflictStrategy()).toBe(ConflictStrategy.KeepApply)
})
it('if keep base strategy, always use the apply payloads updated_at_timestamp', () => {
const basePayload = createDecryptedItemsKey('123', 'secret', 2)
const baseCollection = createBaseCollection(basePayload)
const applyPayload = createDecryptedItemsKey('123', 'other secret', 1)
const delta = new ConflictDelta(baseCollection, basePayload, applyPayload, historyMap)
expect(delta.getConflictStrategy()).toBe(ConflictStrategy.KeepBaseDuplicateApply)
const result = delta.result()
expect(result.emits).toHaveLength(1)
expect(result.emits[0].updated_at_timestamp).toEqual(applyPayload.updated_at_timestamp)
})
})

View File

@@ -1,4 +1,4 @@
import { greaterOfTwoDates, uniqCombineObjArrays } from '@standardnotes/utils'
import { uniqCombineObjArrays } from '@standardnotes/utils'
import { ImmutablePayloadCollection } from '../Collection/Payload/ImmutablePayloadCollection'
import { CreateDecryptedItemFromPayload, CreateItemFromPayload } from '../../Utilities/Item/ItemGenerator'
import { HistoryMap, historyMapFunctions } from '../History/HistoryMap'
@@ -114,9 +114,9 @@ export class ConflictDelta {
}
private handleKeepBaseStrategy(): SyncResolvedPayload[] {
const updatedAt = greaterOfTwoDates(this.basePayload.serverUpdatedAt, this.applyPayload.serverUpdatedAt)
const updatedAt = this.applyPayload.serverUpdatedAt
const updatedAtTimestamp = Math.max(this.basePayload.updated_at_timestamp, this.applyPayload.updated_at_timestamp)
const updatedAtTimestamp = this.applyPayload.updated_at_timestamp
const leftPayload = this.basePayload.copyAsSyncResolved(
{
@@ -146,9 +146,9 @@ export class ConflictDelta {
}
private handleKeepBaseDuplicateApplyStrategy(): SyncResolvedPayload[] {
const updatedAt = greaterOfTwoDates(this.basePayload.serverUpdatedAt, this.applyPayload.serverUpdatedAt)
const updatedAt = this.applyPayload.serverUpdatedAt
const updatedAtTimestamp = Math.max(this.basePayload.updated_at_timestamp, this.applyPayload.updated_at_timestamp)
const updatedAtTimestamp = this.applyPayload.updated_at_timestamp
const leftPayload = this.basePayload.copyAsSyncResolved(
{
@@ -201,9 +201,9 @@ export class ConflictDelta {
'content_type',
])
const updatedAt = greaterOfTwoDates(this.basePayload.serverUpdatedAt, this.applyPayload.serverUpdatedAt)
const updatedAt = this.applyPayload.serverUpdatedAt
const updatedAtTimestamp = Math.max(this.basePayload.updated_at_timestamp, this.applyPayload.updated_at_timestamp)
const updatedAtTimestamp = this.applyPayload.updated_at_timestamp
const payload = this.basePayload.copyAsSyncResolved(
{