fix(contacts): relay DM content frames and expose relayToPeer

Accept MESSAGE_*/REACTION/TYPING/PIN on the contacts mesh as a reliability
path when the dedicated DM topic is empty, and export relayToPeer for
platform dual-path gossip.
This commit is contained in:
Raven Scott
2026-07-13 01:44:34 -04:00
parent 698f2c98bb
commit 19e0ff3492
+25
View File
@@ -468,6 +468,21 @@ class PearcordContacts extends EventEmitter {
this.emit('dm-channel', payload)
return
}
// DM content can ride the contacts mesh when the dedicated DM topic is empty
// on one side (asymmetric peer counts / late join). Platform dedupes by message id.
if (
method === RPC.MESSAGE_CREATE ||
method === RPC.MESSAGE_UPDATE ||
method === RPC.MESSAGE_DELETE ||
method === RPC.REACTION_TOGGLE ||
method === RPC.MESSAGE_PIN ||
method === RPC.TYPING_START ||
method === RPC.CHANNEL_READ
) {
if (payload?.guildId && payload.guildId !== 'dm' && payload.guildId != null) return
this.emit('dm-relay', { method, payload })
return
}
if (method === RPC.CONTACT_REQUEST) {
this.ingestRequest(payload).catch(() => {})
} else if (method === RPC.CONTACT_ACCEPT) {
@@ -483,6 +498,16 @@ class PearcordContacts extends EventEmitter {
}
}
/**
* Deliver a gossip frame to a specific peer's contacts topic (friend or ephemeral).
* Used as a reliability path for 1:1 / group DM when the dedicated DM swarm is empty.
*/
async relayToPeer (peerUserId, method, payload) {
if (!peerUserId || method == null) return false
await this._gossipToPeer(peerUserId, method, payload)
return true
}
async simulateGossip (method, payload) {
if (method === RPC.DM_CHANNEL_UPSERT) {
this.emit('dm-channel', payload)