Phase 884: gossip RPC pull opts, payload builders, search responders extract (v0.8.851)
Non-breaking refactor: buildGuildGossipRpcPullOpts() for config+override assembly; extend payload builders for host sync, member page, and message search pulls; registry lookup helpers; extract message search RPC responders; unify all pull mixins on shared opts builder. Default gossip v1 unchanged; fleet v2 cutover still deferred.
This commit is contained in:
@@ -6,7 +6,7 @@ const {
|
||||
matchesGuildRpcTargetMember,
|
||||
markRpcResponse,
|
||||
fetchGuildGossipRpcPullHit,
|
||||
gossipRpcPullConfig,
|
||||
buildGuildGossipRpcPullOpts,
|
||||
buildTargetedGuildGossipRpcFetchPayload
|
||||
} = require('../../../gossip-rpc-pull')
|
||||
|
||||
@@ -37,19 +37,21 @@ const platformAuditArchiveRpcMixin = {
|
||||
},
|
||||
|
||||
async _tryFetchAuditExportArchiveFromMeshRpc (archiveId, opts = {}) {
|
||||
return fetchGuildGossipRpcPullHit(this, {
|
||||
...gossipRpcPullConfig('auditExportArchive'),
|
||||
targetMemberId: opts.targetMemberId || null,
|
||||
rpcMethod: sharedScope.RPC.AUDIT_EXPORT_ARCHIVE_REQUEST,
|
||||
buildPayload: async ({ guildId }) =>
|
||||
buildTargetedGuildGossipRpcFetchPayload({
|
||||
guildId,
|
||||
resourceIdField: { archiveId },
|
||||
requestId: id(),
|
||||
requestedBy: this.identity.user?.id || null,
|
||||
opts
|
||||
})
|
||||
})
|
||||
return fetchGuildGossipRpcPullHit(
|
||||
this,
|
||||
buildGuildGossipRpcPullOpts('auditExportArchive', {
|
||||
targetMemberId: opts.targetMemberId || null,
|
||||
rpcMethod: sharedScope.RPC.AUDIT_EXPORT_ARCHIVE_REQUEST,
|
||||
buildPayload: async ({ guildId }) =>
|
||||
buildTargetedGuildGossipRpcFetchPayload({
|
||||
guildId,
|
||||
resourceIdField: { archiveId },
|
||||
requestId: id(),
|
||||
requestedBy: this.identity.user?.id || null,
|
||||
opts
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ const {
|
||||
matchesGuildRpcTargetMember,
|
||||
markRpcResponse,
|
||||
fetchGuildGossipRpcPullHit,
|
||||
gossipRpcPullConfig,
|
||||
buildGuildGossipRpcPullOpts,
|
||||
buildTargetedGuildGossipRpcFetchPayload
|
||||
} = require('../../../gossip-rpc-pull')
|
||||
|
||||
@@ -39,19 +39,21 @@ const platformAutomationDigestSnapshotRpcMixin = {
|
||||
},
|
||||
|
||||
async _tryFetchAutomationDigestSnapshotFromMeshRpc (snapshotId, opts = {}) {
|
||||
return fetchGuildGossipRpcPullHit(this, {
|
||||
...gossipRpcPullConfig('automationDigestSnapshot'),
|
||||
targetMemberId: opts.targetMemberId || null,
|
||||
rpcMethod: sharedScope.RPC.AUTOMATION_DIGEST_EXPORT_SNAPSHOT_REQUEST,
|
||||
buildPayload: async ({ guildId }) =>
|
||||
buildTargetedGuildGossipRpcFetchPayload({
|
||||
guildId,
|
||||
resourceIdField: { snapshotId },
|
||||
requestId: id(),
|
||||
requestedBy: this.identity.user?.id || null,
|
||||
opts
|
||||
})
|
||||
})
|
||||
return fetchGuildGossipRpcPullHit(
|
||||
this,
|
||||
buildGuildGossipRpcPullOpts('automationDigestSnapshot', {
|
||||
targetMemberId: opts.targetMemberId || null,
|
||||
rpcMethod: sharedScope.RPC.AUTOMATION_DIGEST_EXPORT_SNAPSHOT_REQUEST,
|
||||
buildPayload: async ({ guildId }) =>
|
||||
buildTargetedGuildGossipRpcFetchPayload({
|
||||
guildId,
|
||||
resourceIdField: { snapshotId },
|
||||
requestId: id(),
|
||||
requestedBy: this.identity.user?.id || null,
|
||||
opts
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ const {
|
||||
fetchGuildGossipRpcFromHostHit,
|
||||
resolveGuildGossipRpcHostPeerId,
|
||||
markRpcResponse,
|
||||
gossipRpcPullConfig
|
||||
buildGuildGossipRpcPullOpts,
|
||||
buildGuildSyncHostRpcFetchPayload,
|
||||
buildMemberPageHostRpcFetchPayload
|
||||
} = require('../../../gossip-rpc-pull')
|
||||
|
||||
/** Guild sync + member page protomux-rpc pull helpers (Phase 882 extract). */
|
||||
@@ -15,15 +17,18 @@ const platformMeshRpcPullMixin = {
|
||||
const userId = this.identity?.user?.id
|
||||
if (!guildId || !userId) return null
|
||||
const off = Math.max(0, Number(offset) || 0)
|
||||
const page = await fetchGuildGossipRpcFromHostHit(this, {
|
||||
...gossipRpcPullConfig('memberPageHost'),
|
||||
rpcMethod: sharedScope.RPC.MEMBER_PAGE_REQUEST,
|
||||
buildPayload: async ({ guildId: gid }) => ({
|
||||
guildId: gid,
|
||||
requesterId: userId,
|
||||
offset: off
|
||||
const page = await fetchGuildGossipRpcFromHostHit(
|
||||
this,
|
||||
buildGuildGossipRpcPullOpts('memberPageHost', {
|
||||
rpcMethod: sharedScope.RPC.MEMBER_PAGE_REQUEST,
|
||||
buildPayload: async ({ guildId: gid }) =>
|
||||
buildMemberPageHostRpcFetchPayload({
|
||||
guildId: gid,
|
||||
requesterId: userId,
|
||||
offset: off
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
if (!page) return null
|
||||
const added = await this._ingestMemberPage(page)
|
||||
return markRpcResponse({
|
||||
@@ -41,20 +46,23 @@ const platformMeshRpcPullMixin = {
|
||||
const wm = this._getGuildSyncWatermark(guildId)
|
||||
const ch = channelId || this.activeChannelId || null
|
||||
const hostPublicKey = await this._lookupGuildHostPublicKey(this.guild.guild)
|
||||
const bundle = await fetchGuildGossipRpcFromHostHit(this, {
|
||||
...gossipRpcPullConfig('guildSyncHost'),
|
||||
hostPublicKey,
|
||||
rpcMethod: sharedScope.RPC.GUILD_SYNC_REQUEST,
|
||||
beforeRequest: async (platform) =>
|
||||
platform.guild.guild.ownerId === platform.identity?.user?.id,
|
||||
buildPayload: async ({ guildId: gid }) => ({
|
||||
guildId: gid,
|
||||
userId,
|
||||
channelId: ch,
|
||||
sinceTimestamp: wm.sinceTimestamp || 0,
|
||||
sinceMessageId: wm.sinceMessageId || null
|
||||
const bundle = await fetchGuildGossipRpcFromHostHit(
|
||||
this,
|
||||
buildGuildGossipRpcPullOpts('guildSyncHost', {
|
||||
hostPublicKey,
|
||||
rpcMethod: sharedScope.RPC.GUILD_SYNC_REQUEST,
|
||||
beforeRequest: async (platform) =>
|
||||
platform.guild.guild.ownerId === platform.identity?.user?.id,
|
||||
buildPayload: async ({ guildId: gid }) =>
|
||||
buildGuildSyncHostRpcFetchPayload({
|
||||
guildId: gid,
|
||||
userId,
|
||||
channelId: ch,
|
||||
sinceTimestamp: wm.sinceTimestamp || 0,
|
||||
sinceMessageId: wm.sinceMessageId || null
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
if (!bundle) return null
|
||||
await this._ingestGuildSync(bundle)
|
||||
const hostPk = resolveGuildGossipRpcHostPeerId(this.guild, hostPublicKey)
|
||||
|
||||
@@ -4,27 +4,32 @@ const searchScope = require('pearcord-search')
|
||||
const sharedScope = require('../../../platform-pearcord-shared-imports')
|
||||
const { id } = require('../../../platform-class-imports')
|
||||
const {
|
||||
markRpcResponse,
|
||||
fetchGuildGossipRpcPullMerged,
|
||||
gossipRpcPullConfig
|
||||
buildGuildGossipRpcPullOpts,
|
||||
buildMessageSearchGuildGossipRpcFetchPayload
|
||||
} = require('../../../gossip-rpc-pull')
|
||||
const { platformSearchRpcRespondersMixin } = require('./platform-search-rpc-responders-mixin')
|
||||
|
||||
const platformSearchMeshGossipMixin = {
|
||||
...platformSearchRpcRespondersMixin,
|
||||
|
||||
async _fetchGuildSearchFromMeshRpc (guildId, query, opts = {}) {
|
||||
if (!this.guild?.guild || this.guild.guild.id !== guildId) return null
|
||||
const requestId = id()
|
||||
return fetchGuildGossipRpcPullMerged(this, {
|
||||
...gossipRpcPullConfig('messageSearchMerge'),
|
||||
rpcMethod: sharedScope.RPC.MESSAGE_SEARCH_REQUEST,
|
||||
buildPayload: async ({ guildId: gid }) => ({
|
||||
guildId: gid,
|
||||
requestId,
|
||||
query: String(query || '').trim(),
|
||||
limit: opts.limit || 50,
|
||||
requestedBy: this.identity.user?.id || null,
|
||||
at: Date.now()
|
||||
return fetchGuildGossipRpcPullMerged(
|
||||
this,
|
||||
buildGuildGossipRpcPullOpts('messageSearchMerge', {
|
||||
rpcMethod: sharedScope.RPC.MESSAGE_SEARCH_REQUEST,
|
||||
buildPayload: async ({ guildId: gid }) =>
|
||||
buildMessageSearchGuildGossipRpcFetchPayload({
|
||||
guildId: gid,
|
||||
requestId,
|
||||
query,
|
||||
opts,
|
||||
requestedBy: this.identity.user?.id || null
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
async _fetchGuildSearchFromMeshOnce (guildId, query, opts = {}) {
|
||||
@@ -46,14 +51,15 @@ const platformSearchMeshGossipMixin = {
|
||||
})
|
||||
})
|
||||
if (this.guild.gossipMessageSearchRequest) {
|
||||
this.guild.gossipMessageSearchRequest({
|
||||
guildId,
|
||||
requestId,
|
||||
query: String(query || '').trim(),
|
||||
limit: opts.limit || 50,
|
||||
requestedBy: this.identity.user?.id || null,
|
||||
at: Date.now()
|
||||
})
|
||||
this.guild.gossipMessageSearchRequest(
|
||||
buildMessageSearchGuildGossipRpcFetchPayload({
|
||||
guildId,
|
||||
requestId,
|
||||
query,
|
||||
opts,
|
||||
requestedBy: this.identity.user?.id || null
|
||||
})
|
||||
)
|
||||
}
|
||||
return waitPromise
|
||||
},
|
||||
@@ -65,27 +71,6 @@ const platformSearchMeshGossipMixin = {
|
||||
fn(hits)
|
||||
},
|
||||
|
||||
async _buildMessageSearchResponsePayload (payload) {
|
||||
if (!payload?.guildId || !payload?.requestId || !payload?.query) return null
|
||||
if (this.guild?.guild?.id !== payload.guildId) return null
|
||||
const local = await this.searchGuildMessages(payload.guildId, payload.query, {
|
||||
limit: Math.min(30, Number(payload.limit) || 30)
|
||||
})
|
||||
const compact = local.map((m) => searchScope.compactMeshSearchHit(m))
|
||||
return {
|
||||
guildId: payload.guildId,
|
||||
requestId: payload.requestId,
|
||||
query: payload.query,
|
||||
hits: compact,
|
||||
respondedBy: this.identity.user?.id || null,
|
||||
at: Date.now()
|
||||
}
|
||||
},
|
||||
|
||||
async _handleMessageSearchRequestRpc (payload) {
|
||||
return markRpcResponse(await this._buildMessageSearchResponsePayload(payload))
|
||||
},
|
||||
|
||||
async _onMessageSearchRequestGossip (payload) {
|
||||
const res = await this._buildMessageSearchResponsePayload(payload)
|
||||
if (!res) return null
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const searchScope = require('pearcord-search')
|
||||
|
||||
/** Message search protomux-rpc responders (Phase 884 extract). */
|
||||
const platformSearchRpcRespondersMixin = {
|
||||
async _buildMessageSearchResponsePayload (payload) {
|
||||
if (!payload?.guildId || !payload?.requestId || !payload?.query) return null
|
||||
if (this.guild?.guild?.id !== payload.guildId) return null
|
||||
const local = await this.searchGuildMessages(payload.guildId, payload.query, {
|
||||
limit: Math.min(30, Number(payload.limit) || 30)
|
||||
})
|
||||
const compact = local.map((m) => searchScope.compactMeshSearchHit(m))
|
||||
return {
|
||||
guildId: payload.guildId,
|
||||
requestId: payload.requestId,
|
||||
query: payload.query,
|
||||
hits: compact,
|
||||
respondedBy: this.identity.user?.id || null,
|
||||
at: Date.now()
|
||||
}
|
||||
},
|
||||
|
||||
async _handleMessageSearchRequestRpc (payload) {
|
||||
const { markRpcResponse } = require('../../../gossip-rpc-pull')
|
||||
return markRpcResponse(await this._buildMessageSearchResponsePayload(payload))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformSearchRpcRespondersMixin }
|
||||
Reference in New Issue
Block a user