fix(mesh): contacts profile ingest, presence burst, and accept-side names
Ingest profiles on contact accept and contacts user gossip; rebroadcast presence with profile fields after mesh join. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -662,7 +662,19 @@ class PearcordPlatform extends EventEmitter {
|
||||
storagePath: this.storagePath
|
||||
})
|
||||
await this.contacts.ready()
|
||||
this.contacts.on('contact', () => this.emit('contact'))
|
||||
this.contacts.on('contact', (row) => {
|
||||
if (row?.status === 'accepted' && row.peerUserId) {
|
||||
void this._ingestUserProfile({
|
||||
id: row.peerUserId,
|
||||
username: row.peerUsername || null,
|
||||
displayName: row.peerDisplayName || null
|
||||
}).catch(() => {})
|
||||
}
|
||||
this.emit('contact')
|
||||
})
|
||||
this.contacts.on('user', (u) => {
|
||||
void this._ingestUserProfile(u).catch(() => {})
|
||||
})
|
||||
this.contacts.on('contact-request', (row) => {
|
||||
void this._ingestContactRequestProfile(row).catch(() => {})
|
||||
this.emit('contact-request')
|
||||
@@ -678,6 +690,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
this._contactsSwarm = this._newHyperswarm(this.identity.keyPair)
|
||||
}
|
||||
await this.contacts.joinMesh(this._contactsSwarm)
|
||||
this._scheduleContactsPresenceBurst()
|
||||
}
|
||||
|
||||
async _joinSettingsMesh () {
|
||||
@@ -3974,14 +3987,43 @@ class PearcordPlatform extends EventEmitter {
|
||||
for (const ms of delays) {
|
||||
setTimeout(() => {
|
||||
if (gen !== this._profileGossipBurstGen) return
|
||||
if (this.mode !== 'guild' || !this.guild?.guild) return
|
||||
if ((this.guild.peers?.size || 0) < 1) return
|
||||
this._gossipSelfUserProfile()
|
||||
this._gossipGuildPresenceSnapshot()
|
||||
if (this.mode === 'guild' && this.guild?.guild) {
|
||||
if ((this.guild.peers?.size || 0) < 1) return
|
||||
this._gossipSelfUserProfile()
|
||||
this._gossipGuildPresenceSnapshot()
|
||||
}
|
||||
if (this.contacts?._meshJoined) this._gossipContactsPresenceSnapshot()
|
||||
}, ms)
|
||||
}
|
||||
}
|
||||
|
||||
_scheduleContactsPresenceBurst () {
|
||||
const gen = (this._contactsPresenceBurstGen = (this._contactsPresenceBurstGen || 0) + 1)
|
||||
const delays = [0, 600, 1500, 4000]
|
||||
for (const ms of delays) {
|
||||
setTimeout(() => {
|
||||
if (gen !== this._contactsPresenceBurstGen) return
|
||||
if (!this.contacts?._meshJoined) return
|
||||
this._gossipContactsPresenceSnapshot()
|
||||
}, ms)
|
||||
}
|
||||
}
|
||||
|
||||
_gossipContactsPresenceSnapshot () {
|
||||
const snap = this.presence?.snapshot?.()
|
||||
if (!snap?.self?.userId || !this.contacts?._meshJoined) return
|
||||
void this.contacts
|
||||
.broadcastPresence({
|
||||
userId: snap.self.userId,
|
||||
status: snap.self.status,
|
||||
customStatus: snap.self.customStatus,
|
||||
activity: snap.self.activity,
|
||||
at: Date.now(),
|
||||
...this._profileFieldsForGossip()
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
_gossipGuildPresenceSnapshot () {
|
||||
const snap = this.presence?.snapshot?.()
|
||||
if (!snap?.self?.userId || !this.guild) return
|
||||
|
||||
Reference in New Issue
Block a user