From bea54af85b8969654d5f47c4a1d8f77acb327147 Mon Sep 17 00:00:00 2001 From: Moe Jangda Date: Tue, 6 Jun 2023 11:25:04 -0700 Subject: [PATCH] (sync) handle pulling tombstones --- packages/web5-user-agent/src/sync-api.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/web5-user-agent/src/sync-api.ts b/packages/web5-user-agent/src/sync-api.ts index fe0c70ed4..257e138d4 100644 --- a/packages/web5-user-agent/src/sync-api.ts +++ b/packages/web5-user-agent/src/sync-api.ts @@ -314,9 +314,18 @@ export class SyncApi implements SyncManager { message : recordsRead }) as RecordsReadReply; - if (reply.status.code >= 400) { - // TODO: handle reply + if (recordsReadReply.status.code >= 400) { const pruneReply = await this.#dwn.synchronizePrunedInitialRecordsWrite(did, message); + + if (pruneReply.status.code === 202 || pruneReply.status.code === 409) { + await this.setWatermark(did, dwnUrl, 'pull', watermark); + await this.#addMessage(did, messageCid); + delOps.push({ type: 'del', key }); + + continue; + } else { + throw new Error(`Failed to sync tombstone. message cid: ${messageCid}`); + } } else { dataStream = webReadableToIsomorphicNodeReadable(recordsReadReply.record.data as any); }