feat(permissions): Phase 681 mixin, heal, gossip dedupe (v0.8.656)
Add permissions-mixin for overwrite dedupe and partition heal (overwrites + roles), extend permission.overwrite span metadata, deep link openChannelPermissions. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -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 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`.
|
||||
|
||||
**Phase 679 (v0.8.654):** Thread panel & forum parity — `threads-forum.js` mixin, `createThread` auto-archive, `_healThreadMetadataOnPartition` watermark + auto-archive heal, guild-scoped `buildThreadsPanel`, deep link `create-thread` query. Bundle: `npm run test:ci-phase679`.
|
||||
|
||||
@@ -1571,6 +1571,12 @@ class PearcordPlatform extends EventEmitter {
|
||||
const announcementFollowHeal = await this._healAnnouncementFollowsOnPartition(gid).catch(() => ({
|
||||
relisted: 0
|
||||
}))
|
||||
const permissionOverwriteHeal = await this._healChannelOverwritesOnPartition(gid).catch(() => ({
|
||||
relisted: 0
|
||||
}))
|
||||
const guildRolesHeal = await this._healGuildRolesOnPartition(gid).catch(() => ({
|
||||
relisted: 0
|
||||
}))
|
||||
return {
|
||||
voiceApplied,
|
||||
emojiSlots,
|
||||
@@ -1597,7 +1603,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
discoveryHeal,
|
||||
forumHeal,
|
||||
announcementCrosspostHeal,
|
||||
announcementFollowHeal
|
||||
announcementFollowHeal,
|
||||
permissionOverwriteHeal,
|
||||
guildRolesHeal
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14582,7 +14590,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
deny
|
||||
}
|
||||
)
|
||||
this.guild.gossipChannelOverwriteUpsert(row)
|
||||
if (this._shouldGossipChannelOverwrite(row)) {
|
||||
this.guild.gossipChannelOverwriteUpsert(row)
|
||||
}
|
||||
await this._audit('channel.overwrite', { guildId: this.guild.guild.id, targetId: chId })
|
||||
this.emit('channel-overwrite', row)
|
||||
await this._fanoutAppEvent(APP_EVENTS.CHANNEL_PERMISSION_UPDATE, { overwrite: row })
|
||||
@@ -14609,7 +14619,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
spanKind: 'permission.overwrite',
|
||||
activeChannelId: this.activeChannelId,
|
||||
channelOverwriteCount: overwrites.length,
|
||||
guildCount: (this.guilds || []).length
|
||||
permissionOverwriteCount: overwrites.length,
|
||||
guildCount: (this.guilds || []).length,
|
||||
partitionGuildId: guildId
|
||||
})
|
||||
const evalSpan = this.log.time('permission.eval', {
|
||||
channelId: chId,
|
||||
@@ -14696,7 +14708,8 @@ class PearcordPlatform extends EventEmitter {
|
||||
hadDeny: !!(Number(prev?.deny) || 0),
|
||||
spanKind: 'permission.overwrite.delete',
|
||||
activeChannelId: this.activeChannelId,
|
||||
remainingOverwriteCount: remaining.length
|
||||
remainingOverwriteCount: remaining.length,
|
||||
permissionOverwriteCount: remaining.length
|
||||
})
|
||||
return prev
|
||||
} catch (err) {
|
||||
@@ -17012,7 +17025,8 @@ class PearcordPlatform extends EventEmitter {
|
||||
channelId: parsed.channelId,
|
||||
openCreateThread: !!parsed.createThreadMessageId,
|
||||
messageId: parsed.createThreadMessageId || null,
|
||||
openFollowAnnouncement: !!parsed.followAnnouncement
|
||||
openFollowAnnouncement: !!parsed.followAnnouncement,
|
||||
openChannelPermissions: !!parsed.editChannelPermissions
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26243,6 +26257,7 @@ const { moderationMixin } = require('./moderation')
|
||||
const { invitesDiscoveryMixin } = require('./invites-discovery')
|
||||
const { threadsForumMixin } = require('./threads-forum')
|
||||
const { announcementsMixin } = require('./announcements-mixin')
|
||||
const { permissionsMixin } = require('./permissions-mixin')
|
||||
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
|
||||
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
|
||||
Object.assign(PearcordPlatform.prototype, userSettingsMixin)
|
||||
@@ -26250,3 +26265,4 @@ Object.assign(PearcordPlatform.prototype, moderationMixin)
|
||||
Object.assign(PearcordPlatform.prototype, invitesDiscoveryMixin)
|
||||
Object.assign(PearcordPlatform.prototype, threadsForumMixin)
|
||||
Object.assign(PearcordPlatform.prototype, announcementsMixin)
|
||||
Object.assign(PearcordPlatform.prototype, permissionsMixin)
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
'use strict'
|
||||
|
||||
const permissionsMixin = {
|
||||
_permissionOverwriteGossipKeys: null,
|
||||
_channelOverwriteHealWatermark: null,
|
||||
_guildRolesHealWatermark: null,
|
||||
|
||||
_initPermissionMixinState () {
|
||||
if (!this._permissionOverwriteGossipKeys) {
|
||||
this._permissionOverwriteGossipKeys = new Set()
|
||||
}
|
||||
},
|
||||
|
||||
_shouldGossipChannelOverwrite (row) {
|
||||
this._initPermissionMixinState()
|
||||
if (!row?.guildId || !row?.channelId) return true
|
||||
const hash = `${row.guildId}:${row.channelId}:${row.targetType}:${row.targetId}:${row.allow}:${row.deny}:${row.updatedAt || 0}`
|
||||
if (this._permissionOverwriteGossipKeys.has(hash)) return false
|
||||
this._permissionOverwriteGossipKeys.add(hash)
|
||||
if (this._permissionOverwriteGossipKeys.size > 8192) {
|
||||
const first = this._permissionOverwriteGossipKeys.values().next().value
|
||||
if (first) this._permissionOverwriteGossipKeys.delete(first)
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
async _healChannelOverwritesOnPartition (guildId) {
|
||||
const gid = guildId || this.guild?.guild?.id || null
|
||||
const span = this.log.time('permission.heal', {
|
||||
spanKind: 'permission.heal',
|
||||
guildId: gid,
|
||||
slice: 'overwrite'
|
||||
})
|
||||
try {
|
||||
if (!gid || !this.channelPermissions?.listForGuild) {
|
||||
span.end({ relisted: 0, skipped: true })
|
||||
return { relisted: 0, skipped: true }
|
||||
}
|
||||
const rows = await this.channelPermissions.listForGuild(gid).catch(() => [])
|
||||
let relisted = 0
|
||||
for (const row of rows) {
|
||||
if (row.guildId && row.guildId !== gid) continue
|
||||
if (this._shouldGossipChannelOverwrite(row) && this.guild?.gossipChannelOverwriteUpsert) {
|
||||
this.guild.gossipChannelOverwriteUpsert(row)
|
||||
relisted++
|
||||
}
|
||||
}
|
||||
const watermark = Date.now()
|
||||
this._channelOverwriteHealWatermark = watermark
|
||||
span.end({ relisted, watermark, overwriteCount: rows.length })
|
||||
return { relisted, watermark, overwriteCount: rows.length }
|
||||
} catch (err) {
|
||||
this.log.error('permission.heal error', {
|
||||
guildId: gid,
|
||||
slice: 'overwrite',
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
return { relisted: 0, error: err?.message || String(err) }
|
||||
}
|
||||
},
|
||||
|
||||
async _healGuildRolesOnPartition (guildId) {
|
||||
const gid = guildId || this.guild?.guild?.id || null
|
||||
const span = this.log.time('permission.heal', {
|
||||
spanKind: 'permission.heal',
|
||||
guildId: gid,
|
||||
slice: 'roles'
|
||||
})
|
||||
try {
|
||||
if (!gid || !this.guildRoles?.listRoles) {
|
||||
span.end({ relisted: 0, skipped: true })
|
||||
return { relisted: 0, skipped: true }
|
||||
}
|
||||
const roles = await this.guildRoles.listRoles(gid).catch(() => [])
|
||||
let relisted = 0
|
||||
for (const row of roles) {
|
||||
if (row.guildId && row.guildId !== gid) continue
|
||||
if (this.guild?.gossipRoleUpsert) {
|
||||
this.guild.gossipRoleUpsert(row)
|
||||
relisted++
|
||||
}
|
||||
}
|
||||
const watermark = Date.now()
|
||||
this._guildRolesHealWatermark = watermark
|
||||
span.end({ relisted, watermark, roleCount: roles.length })
|
||||
return { relisted, watermark, roleCount: roles.length }
|
||||
} catch (err) {
|
||||
this.log.error('permission.heal error', {
|
||||
guildId: gid,
|
||||
slice: 'roles',
|
||||
error: err?.message || String(err)
|
||||
})
|
||||
span.fail(err)
|
||||
return { relisted: 0, error: err?.message || String(err) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { permissionsMixin }
|
||||
Reference in New Issue
Block a user