feat(roles): Phase 682 member-roles mixin and effective perm view (v0.8.657)

Add member-roles-mixin for link gossip dedupe and partition heal, extend
permission.eval spans with effectivePermissionCount, deep link openAssignMemberRoles.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-06-02 23:57:12 -04:00
co-authored by Cursor
parent 49b3e46e60
commit ec2698b4db
3 changed files with 122 additions and 4 deletions
+2
View File
@@ -2,6 +2,8 @@
Application facade: one `PearcordPlatform` class that wires identity, database, guild mesh, DMs, invites, voice, discovery, bots, and dozens of feature modules for the Pearcord desktop sidecar and companion.
**Phase 682 (v0.8.657):** Effective permissions & member roles — `member-roles-mixin.js`, member role gossip dedupe, `_healMemberRoleLinksOnPartition`, view `effectivePermissionCount`, deep link `?roles=1`. Bundle: `npm run test:ci-phase682`.
**Phase 681 (v0.8.656):** Channel permissions editor — `permissions-mixin.js`, overwrite gossip dedupe, `_healChannelOverwritesOnPartition` + `_healGuildRolesOnPartition`, `permissionOverwriteCount` span metadata, deep link `?permissions=1`. Bundle: `npm run test:ci-phase681`.
**Phase 680 (v0.8.655):** Announcement follow & cross-post — `announcements-mixin.js`, cross-post dedupe/heal/rate limit, `announcement.follow` spans, `retryAnnouncementCrosspost`, announcement search scope. Bundle: `npm run test:ci-phase680`.
+19 -4
View File
@@ -1577,6 +1577,12 @@ class PearcordPlatform extends EventEmitter {
const guildRolesHeal = await this._healGuildRolesOnPartition(gid).catch(() => ({
relisted: 0
}))
const memberRoleLinksHeal = await this._healMemberRoleLinksOnPartition(gid).catch(() => ({
relisted: 0
}))
const effectivePermCacheHeal = await this._healEffectivePermissionCacheOnPartition(gid).catch(() => ({
relisted: 0
}))
return {
voiceApplied,
emojiSlots,
@@ -1605,7 +1611,9 @@ class PearcordPlatform extends EventEmitter {
announcementCrosspostHeal,
announcementFollowHeal,
permissionOverwriteHeal,
guildRolesHeal
guildRolesHeal,
memberRoleLinksHeal,
effectivePermCacheHeal
}
}
@@ -14358,7 +14366,9 @@ class PearcordPlatform extends EventEmitter {
await this._audit('member.role.remove', { guildId: this.guild.guild.id, targetId: userId, roleId: rid })
}
}
this.guild.gossipMemberCustomRoles(link)
if (this._shouldGossipMemberRoles(link)) {
this.guild.gossipMemberCustomRoles(link)
}
this.emit('guild-member-roles', link)
await this._fanoutAppEvent(APP_EVENTS.MEMBER_ROLE_UPDATE, { memberRoles: link })
this.emit('member', await this.db.get(COLLECTIONS.MEMBERS, {
@@ -14637,7 +14647,8 @@ class PearcordPlatform extends EventEmitter {
perm: 'sendMessages',
spanKind: 'permission.eval',
activeChannelId: this.activeChannelId || null,
guildCount: (this.guilds || []).length
guildCount: (this.guilds || []).length,
effectivePermissionCount: (PERMISSION_META || []).length
})
} catch (evalErr) {
this.log.error('permission.eval error', {
@@ -17026,7 +17037,8 @@ class PearcordPlatform extends EventEmitter {
openCreateThread: !!parsed.createThreadMessageId,
messageId: parsed.createThreadMessageId || null,
openFollowAnnouncement: !!parsed.followAnnouncement,
openChannelPermissions: !!parsed.editChannelPermissions
openChannelPermissions: !!parsed.editChannelPermissions,
openAssignMemberRoles: !!parsed.assignMemberRoles
}
}
@@ -25613,6 +25625,7 @@ class PearcordPlatform extends EventEmitter {
voicePermsByChannel,
channelPermsByChannel,
channelOverwriteCount,
effectivePermissionCount: (PERMISSION_META || []).length,
pins,
mentionNames: [...mentionNames],
channelSettings,
@@ -26258,6 +26271,7 @@ const { invitesDiscoveryMixin } = require('./invites-discovery')
const { threadsForumMixin } = require('./threads-forum')
const { announcementsMixin } = require('./announcements-mixin')
const { permissionsMixin } = require('./permissions-mixin')
const { memberRolesMixin } = require('./member-roles-mixin')
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
Object.assign(PearcordPlatform.prototype, userSettingsMixin)
@@ -26266,3 +26280,4 @@ Object.assign(PearcordPlatform.prototype, invitesDiscoveryMixin)
Object.assign(PearcordPlatform.prototype, threadsForumMixin)
Object.assign(PearcordPlatform.prototype, announcementsMixin)
Object.assign(PearcordPlatform.prototype, permissionsMixin)
Object.assign(PearcordPlatform.prototype, memberRolesMixin)
+101
View File
@@ -0,0 +1,101 @@
'use strict'
const { PERMISSION_META } = require('pearcord-guild-roles/permissions')
const memberRolesMixin = {
_memberRoleGossipKeys: null,
_memberRoleHealWatermark: null,
_effectivePermHealWatermark: null,
_initMemberRolesMixinState () {
if (!this._memberRoleGossipKeys) {
this._memberRoleGossipKeys = new Set()
}
},
_shouldGossipMemberRoles (link) {
this._initMemberRolesMixinState()
if (!link?.guildId || !link?.userId) return true
const ids = (link.roleIds || []).join(',')
const hash = `${link.guildId}:${link.userId}:${ids}:${link.updatedAt || 0}`
if (this._memberRoleGossipKeys.has(hash)) return false
this._memberRoleGossipKeys.add(hash)
if (this._memberRoleGossipKeys.size > 8192) {
const first = this._memberRoleGossipKeys.values().next().value
if (first) this._memberRoleGossipKeys.delete(first)
}
return true
},
async _healMemberRoleLinksOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('role.heal', {
spanKind: 'role.heal',
guildId: gid,
slice: 'member-links'
})
try {
if (!gid || !this.guildRoles?.listMemberLinks) {
span.end({ relisted: 0, skipped: true })
return { relisted: 0, skipped: true }
}
const links = await this.guildRoles.listMemberLinks(gid).catch(() => [])
let relisted = 0
for (const link of links) {
if (link.guildId && link.guildId !== gid) continue
if (this._shouldGossipMemberRoles(link) && this.guild?.gossipMemberCustomRoles) {
this.guild.gossipMemberCustomRoles(link)
relisted++
}
}
const watermark = Date.now()
this._memberRoleHealWatermark = watermark
span.end({ relisted, watermark, linkCount: links.length })
return { relisted, watermark, linkCount: links.length }
} catch (err) {
this.log.error('role.heal error', {
guildId: gid,
slice: 'member-links',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
},
async _healEffectivePermissionCacheOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('permission.eval', {
spanKind: 'permission.eval',
guildId: gid,
context: 'heal.cache'
})
try {
if (!gid) {
span.end({ relisted: 0, skipped: true, effectivePermissionCount: 0 })
return { relisted: 0, skipped: true }
}
const flagCount = (PERMISSION_META || []).length
const watermark = Date.now()
this._effectivePermHealWatermark = watermark
span.end({
relisted: 0,
watermark,
effectivePermissionCount: flagCount,
guildCount: (this.guilds || []).length,
activeChannelId: this.activeChannelId || null
})
return { relisted: 0, watermark, effectivePermissionCount: flagCount }
} catch (err) {
this.log.error('permission.eval error', {
guildId: gid,
context: 'heal.cache',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
module.exports = { memberRolesMixin }