Phase 787: guild-sync-ready roles slice on role gossip (v0.8.754)

Emit guild-sync-ready with roles on guild-role, guild-role-delete, and
guild-member-roles; count guildRoles/memberRoleLinks in GUILD_SYNC ingest.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-06-03 21:40:24 -04:00
co-authored by Cursor
parent 7e4942f709
commit b17e7bdc74
3 changed files with 23 additions and 2 deletions
@@ -617,12 +617,15 @@ async _ingestGuildSync (payload) {
syncReplayResume: replayCtx.resume,
syncReplay: localScope.guildSyncReplay.snapshotForDiagnostics(payload.guildId)
})
const rolesApplied =
(payload.guildRoles?.length || 0) + (payload.memberRoleLinks?.length || 0)
return {
messages: added,
members: membersAdded,
presence: presenceApplied,
channels: channelRows.length,
voice: voiceApplied,
roles: rolesApplied,
reactions: reactionChanges,
sparse,
attachPull,
@@ -247,12 +247,16 @@ _wireGuild (guildInstance) {
const payloadPres = payload?.presenceVector?.length || 0
const payloadChans = payload?.channels?.length || 0
const payloadVoice = payload?.voiceOccupancy?.length || 0
const payloadRoles =
(payload?.guildRoles?.length || 0) +
(payload?.memberRoleLinks?.length || 0)
const hasSlice =
payloadMsgs > 0 ||
payloadMems > 0 ||
payloadPres > 0 ||
payloadChans > 0 ||
payloadVoice > 0
payloadVoice > 0 ||
payloadRoles > 0
if (!result && !hasSlice) return
this._lastGuildSyncIngestAt = Date.now()
const msgCount =
@@ -275,12 +279,17 @@ _wireGuild (guildInstance) {
typeof result === 'object'
? Math.max(result.voice || 0, payloadVoice)
: payloadVoice
const rolesCount =
typeof result === 'object'
? Math.max(result.roles || 0, payloadRoles)
: payloadRoles
if (
msgCount > 0 ||
memCount > 0 ||
presCount > 0 ||
chanCount > 0 ||
voiceCount > 0 ||
rolesCount > 0 ||
hasSlice
) {
this.emit('guild-sync-ready', {
@@ -289,7 +298,8 @@ _wireGuild (guildInstance) {
members: memCount,
presence: presCount,
channels: chanCount,
voice: voiceCount
voice: voiceCount,
roles: rolesCount
})
if (payload?.guildId === this.guild?.guild?.id) {
this._touchAllGuildMeshPeersSeen(payload.guildId, 'guild-sync')
@@ -545,14 +555,20 @@ _wireGuild (guildInstance) {
guildInstance.on('guild-role', (row) => {
this.guildRoles?.ingestRoleGossip(row).catch(() => {})
this.emit('guild-role', row)
const gid = this.guild?.guild?.id
if (gid) this.emit('guild-sync-ready', { guildId: gid, roles: 1 })
})
guildInstance.on('guild-role-delete', (payload) => {
this.guildRoles?.ingestRoleDelete(payload).catch(() => {})
this.emit('guild-role-delete', payload)
const gid = this.guild?.guild?.id
if (gid) this.emit('guild-sync-ready', { guildId: gid, roles: 1 })
})
guildInstance.on('guild-member-roles', (payload) => {
this.guildRoles?.ingestMemberRolesGossip(payload).catch(() => {})
this.emit('guild-member-roles', payload)
const gid = this.guild?.guild?.id
if (gid) this.emit('guild-sync-ready', { guildId: gid, roles: 1 })
this._fanoutAppEvent(appEventsScope.APP_EVENTS.MEMBER_ROLE_UPDATE, { memberRoles: payload }).catch(
() => {}
)