Skip to content

Commit d3e9d5c

Browse files
author
tung-ideapad
committed
.
1 parent 5c238d1 commit d3e9d5c

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

src/helpers.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ async function synchronize({notes, deletedNoteIds, isSilent, credentials, nostrP
441441
const { finalIdArray: effectiveDeletedNoteIds, hasChanged: deletedListChanged } = await syncDeletedNoteIds({deletedNoteIds, credentials, gitCredentials, gdriveStore});
442442

443443
// --- Step 1: Get remote state FIRST ---
444-
const { mergedNotes: remoteNoteMetadata, s3Ids, gitIds, nostrIds, gdriveIds, gdriveMap } = await listNotes({credentials, nostrPrivateKey, nostrRelays, lastSync, gitCredentials, gdriveStore});
444+
const { mergedNotes: remoteNoteMetadata, s3Ids, gitIds, nostrIds, gdriveIds, gdriveMap, listingSucceeded } = await listNotes({credentials, nostrPrivateKey, nostrRelays, lastSync, gitCredentials, gdriveStore});
445445
const remoteMetaMap = new Map(remoteNoteMetadata.map(m => [m.id, m]));
446446

447447
// --- Step 2: Determine which notes to upload ---
@@ -554,17 +554,19 @@ async function synchronize({notes, deletedNoteIds, isSilent, credentials, nostrP
554554
const localNoteIds = new Set(allLocalNotesMap.keys());
555555

556556
// Identify notes that should be deleted locally:
557-
// - Exist locally
558-
// - Don't exist remotely
559-
// - Weren't already marked for local deletion
560-
// - Weren't just uploaded (which would mean they now exist remotely)
561-
const remotelyDeletedNoteIds = [...localNoteIds].filter(noteId =>
562-
!remoteNoteIds.has(noteId) &&
563-
!locallyDeletedNoteIds.has(noteId) &&
564-
!uploadedNoteIds.has(noteId)
565-
);
566-
567-
notesToDeleteLocally.push(...remotelyDeletedNoteIds);
557+
const idsToDeleteLocally = [...localNoteIds].filter(noteId => {
558+
// 1. If it's in our known deleted list (synced via deleted-notes.json), it must go.
559+
if (locallyDeletedNoteIds.has(noteId)) return true;
560+
561+
// 2. If it's gone from ALL remotes AND we successfully listed all remotes AND it's not a new local note.
562+
if (listingSucceeded && !remoteNoteIds.has(noteId) && !uploadedNoteIds.has(noteId)) {
563+
return true;
564+
}
565+
566+
return false;
567+
});
568+
569+
notesToDeleteLocally.push(...idsToDeleteLocally);
568570
}
569571

570572
const downloadPromises = notesToDownload.map(remoteMeta => {
@@ -820,13 +822,16 @@ async function listNotes({credentials, nostrPrivateKey, nostrRelays, lastSync, g
820822
}
821823
});
822824

825+
const listingSucceeded = [s3Res, nostrRes, gitRes, gdriveRes].every(r => r.status === 'fulfilled');
826+
823827
return {
824828
mergedNotes: Array.from(mergedNotes.values()),
825829
s3Ids: new Set(s3Notes.map(n => n.id)),
826830
gitIds: new Set(gitNotes.map(n => n.id)),
827831
nostrIds: new Set(nostrNotes.map(n => n.id)),
828832
gdriveIds: new Set(gdriveNotes.map(n => n.id)),
829-
gdriveMap: new Map(gdriveNotes.map(n => [n.id, n]))
833+
gdriveMap: new Map(gdriveNotes.map(n => [n.id, n])),
834+
listingSucceeded
830835
};
831836
}
832837

0 commit comments

Comments
 (0)