| … | … | @@ -255,6 +255,16 @@ class BridgeGossipSync { |
| 255 | 255 | // users can never collide onto the same sync group. |
| 256 | 256 | _myAppId () { return this.getMe() } |
| 257 | 257 | |
| 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 | |
| 258 | 268 | async ready () { |
| 259 | 269 | await cryptoReady() |
| 260 | 270 | let key = null |
| … | … | @@ -267,6 +277,14 @@ class BridgeGossipSync { |
| 267 | 277 | const r = await this.pear.sync.create(this._myAppId()); this._myInvite = r.inviteKey |
| 268 | 278 | } |
| 269 | 279 | 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 {} |
| 270 | 288 | try { |
| 271 | 289 | this._channel = await this.pear.swarm.v1.join(TOPIC, { server: true, client: true, appName: 'p2pbuilders', reason: 'Discover other p2pbuilders peers' }) |
| 272 | 290 | this._channel.on('peer', () => this._announce()) |