OverviewFilesCommitsIssuesDocsReleasesPeers

p2pbuilders commits / 0dc9680

web: orphan-proof the outbox — re-merge every past outbox so posts survive an identity-key change across sessions
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0dc9680436a0a13137041bd8b7e300319c7fe8a6
by bigdestiny2 <defidon@protonmail.com> · 2026-06-23T18:43:32.000Z

Changed files (1) +18 -0

web/js/gossip.js +18 -0
……@@ -255,6 +255,16 @@ class BridgeGossipSync {
255255 // users can never collide onto the same sync group.
256256 _myAppId () { return this.getMe() }
257257
258 // Every outbox this user has ever written, persisted locally. Re-merging ALL
259 // of them on boot makes posts survive even if PearBrowser hands back a
260 // different per-app identity key on reopen (which would otherwise orphan the
261 // prior outbox and make posts "vanish" though they're still on disk).
262 _knownOutboxes () { try { return JSON.parse(localStorage.getItem('p2pb:my-outboxes') || '[]') } catch { return [] } }
263 _rememberOutbox (appId, inviteKey) {
264 const list = this._knownOutboxes()
265 if (!list.find(o => o.appId === appId)) { list.push({ appId, inviteKey }); try { localStorage.setItem('p2pb:my-outboxes', JSON.stringify(list)) } catch {} }
266 }
267
258268 async ready () {
259269 await cryptoReady()
260270 let key = null
……@@ -267,6 +277,14 @@ class BridgeGossipSync {
267277 const r = await this.pear.sync.create(this._myAppId()); this._myInvite = r.inviteKey
268278 }
269279 this._peers.set(this.getMe(), { appId: this._myAppId(), inviteKey: this._myInvite, self: true })
280 this._rememberOutbox(this._myAppId(), this._myInvite)
281 // Re-join + merge EVERY outbox we've ever owned, so a changed identity key
282 // can't strand earlier posts.
283 for (const o of this._knownOutboxes()) {
284 if (this._peers.has(o.appId)) continue
285 try { await this.pear.sync.join(o.appId, o.inviteKey); this._peers.set(o.appId, { appId: o.appId, inviteKey: o.inviteKey, self: true }) } catch {}
286 }
287 try { console.log('[p2pb persist] me=' + (this.getMe() || '').slice(0, 12) + ' outbox=' + (this._myInvite || '').slice(0, 12) + ' knownOutboxes=' + this._knownOutboxes().length) } catch {}
270288 try {
271289 this._channel = await this.pear.swarm.v1.join(TOPIC, { server: true, client: true, appName: 'p2pbuilders', reason: 'Discover other p2pbuilders peers' })
272290 this._channel.on('peer', () => this._announce())