@@ -481,94 +481,6 @@ async function synchronize({notes, deletedNoteIds, isSilent, credentials, nostrP
481481 }
482482}
483483
484- // --- Step 5: Determine which notes to download or delete locally ---
485- const notesToDownload = [ ] ;
486- const notesToDeleteLocally = [ ] ;
487- const allLocalNotesMap = new Map ( localNotes . map ( n => [ n . id , n ] ) ) ;
488-
489- // Find notes updated remotely
490- for ( const remoteMeta of remoteNoteMetadata ) {
491- const localNote = allLocalNotesMap . get ( remoteMeta . id ) ;
492- if ( ! localNote ) {
493- // Note exists on remote but not local, and isn't in the local delete list. Download it.
494- if ( ! deletedNoteIds . includes ( remoteMeta . id ) ) {
495- notesToDownload . push ( remoteMeta ) ;
496- }
497- } else {
498- // Note exists on both. Download if remote is newer.
499- const remoteDate = new Date ( remoteMeta . updatedAt ) ;
500- const localDate = new Date ( localNote . updatedAt ) ;
501- if ( remoteDate > localDate ) {
502- notesToDownload . push ( remoteMeta ) ;
503- }
504- }
505- }
506-
507- // Find notes deleted remotely
508- const remoteNoteIds = new Set ( remoteNoteMetadata . map ( m => m . id ) ) ;
509- const locallyDeletedNoteIds = new Set ( deletedNoteIds ) ;
510- const uploadedNoteIds = new Set ( notesToUpload . map ( n => n . id ) ) ;
511-
512- // Create a set of all local note IDs for easier checking
513- const localNoteIds = new Set ( allLocalNotesMap . keys ( ) ) ;
514-
515- // Identify notes that should be deleted locally:
516- // - Exist locally
517- // - Don't exist remotely
518- // - Weren't already marked for local deletion
519- // - Weren't just uploaded (which would mean they now exist remotely)
520- const remotelyDeletedNoteIds = [ ...localNoteIds ] . filter ( noteId =>
521- ! remoteNoteIds . has ( noteId ) &&
522- ! locallyDeletedNoteIds . has ( noteId ) &&
523- ! uploadedNoteIds . has ( noteId )
524- ) ;
525-
526- notesToDeleteLocally . push ( ...remotelyDeletedNoteIds ) ;
527-
528- const downloadPromises = notesToDownload . map ( remoteMeta => {
529- if ( remoteMeta . source === 'git' ) {
530- // We already have the content from listNotesInGit?
531- // listNotesInGit returns full note objects with content!
532- // So we don't need to download again. We just return it.
533- return Promise . resolve ( remoteMeta ) ;
534- } else if ( remoteMeta . source === 'nostr' ) {
535- return Promise . resolve ( remoteMeta ) ; // Nostr also returns full event/note
536- } else {
537- return downloadNoteFromS3 ( remoteMeta . id , credentials ) ;
538- }
539- } ) ;
540- const downloadResults = await Promise . allSettled ( downloadPromises ) ;
541-
542- const updatedNotes = [ ] ;
543- downloadResults . forEach ( ( result , idx ) => {
544- if ( result . status === 'fulfilled' && result . value ) {
545- updatedNotes . push ( result . value ) ;
546- } else if ( result . status === 'rejected' ) {
547- console . log ( 'Sync download error:' , notesToDownload [ idx ] . id , result . reason . message ) ;
548- // If a note was listed in metadata but fails to download with NoSuchKey,
549- // it means it was deleted between the list and get operations.
550- // We should treat it as a remote deletion.
551- if ( result . reason && result . reason . code === 'NoSuchKey' ) {
552- notesToDeleteLocally . push ( notesToDownload [ idx ] . id ) ;
553- }
554- }
555- } ) ;
556-
557- return {
558- success : true ,
559- uploadedCount : successfulUploadedCount ,
560- deletedCount : successfulDeletedCount ,
561- successfulDeletedIds, // downloaded notes
562- updatedNotes, // downloaded notes
563- notesToDeleteLocally,
564- finalRemoteIds : Array . from ( remoteNoteIds )
565- } ;
566- } catch ( error ) {
567- console . error ( 'synchronize error:' , error ) ;
568- return { success : false , error : error . message } ;
569- }
570- }
571-
572484async function synchronizeImages ( { encryptedSettings, userId, nostrPrivateKey, nostrRelays} ) {
573485 try {
574486 const credentials = await decryptSettings ( encryptedSettings , userId ) ;
0 commit comments