Full document, spreadsheet, slideshow, and diagram tooling
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: PDS sync not working on document pages + bulk push existing docs (#17)

scott 05eebcc0 a475b740

+60 -5
+7 -3
src/landing.ts
··· 345 345 .then(() => syncKeys()) 346 346 .then(async () => { 347 347 const { ensurePdsIdentity } = await import('./lib/pds-setup.js'); 348 - await ensurePdsIdentity(); 349 - const { pullRemoteDocuments } = await import('./lib/pds-pull-sync.js'); 350 - await pullRemoteDocuments(); 348 + const ready = await ensurePdsIdentity(); 349 + if (ready) { 350 + const { pushLocalDocuments } = await import('./lib/pds-push-sync.js'); 351 + await pushLocalDocuments(); 352 + const { pullRemoteDocuments } = await import('./lib/pds-pull-sync.js'); 353 + await pullRemoteDocuments(); 354 + } 351 355 }) 352 356 .then(() => loadDocuments()); 353 357
+41
src/lib/pds-push-sync.ts
··· 1 + /** 2 + * PDS push sync — uploads local documents missing from PDS. 3 + * Handles the case where documents existed before sync was enabled. 4 + * Called once during boot after identity is ready. 5 + */ 6 + 7 + import { listPdsDocuments, saveDocumentToPds } from './pds-documents.js'; 8 + import { listDocuments } from './local-store.js'; 9 + import { isPdsReady } from './pds-setup.js'; 10 + import { getSession } from './auth.js'; 11 + 12 + const PUSH_SYNC_KEY = 'atmos-pds-push-sync-done'; 13 + 14 + export async function pushLocalDocuments(): Promise<number> { 15 + if (!isPdsReady()) return 0; 16 + if (localStorage.getItem(PUSH_SYNC_KEY)) return 0; 17 + 18 + const session = getSession(); 19 + if (!session) return 0; 20 + 21 + const localDocs = await listDocuments(); 22 + if (localDocs.length === 0) return 0; 23 + 24 + const remoteDocs = await listPdsDocuments(session.agent, session.did); 25 + const remoteIds = new Set(remoteDocs.map(d => d.rkey)); 26 + 27 + let pushed = 0; 28 + for (const doc of localDocs) { 29 + if (remoteIds.has(doc.id)) continue; 30 + 31 + try { 32 + await saveDocumentToPds(session.agent, session.did, doc.id); 33 + pushed++; 34 + } catch (err) { 35 + console.warn(`Failed to push document ${doc.id} to PDS:`, err); 36 + } 37 + } 38 + 39 + localStorage.setItem(PUSH_SYNC_KEY, Date.now().toString()); 40 + return pushed; 41 + }
+12 -2
src/lib/provider.ts
··· 11 11 import { Awareness, removeAwarenessStates } from 'y-protocols/awareness'; 12 12 import { encrypt, decrypt } from './crypto.js'; 13 13 import { getDocument, updateDocument } from './local-store.js'; 14 - import { isPdsReady } from './pds-setup.js'; 14 + import { isPdsReady, ensurePdsIdentity } from './pds-setup.js'; 15 15 import { getSession } from './auth.js'; 16 16 import { saveDocumentToPds } from './pds-documents.js'; 17 17 ··· 233 233 } 234 234 235 235 private _syncToPds(): void { 236 - if (!isPdsReady()) return; 236 + if (!isPdsReady()) { 237 + ensurePdsIdentity().then(ready => { 238 + if (!ready) return; 239 + const session = getSession(); 240 + if (!session) return; 241 + saveDocumentToPds(session.agent, session.did, this.roomId).catch(err => { 242 + console.warn('PDS sync failed (will retry on next save):', err); 243 + }); 244 + }); 245 + return; 246 + } 237 247 const session = getSession(); 238 248 if (!session) return; 239 249