Phase 791: GUILD_SYNC guildStickers slice and guild-sync-ready stickers count.
Export/ingest custom sticker bundles; sticker gossip emits structural sync-ready. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -530,6 +530,58 @@ async _ingestGuildEmojisSyncBundle (rows = []) {
|
||||
return changed
|
||||
},
|
||||
|
||||
async _exportGuildStickersForSyncBundle (guildId) {
|
||||
if (!guildId) return []
|
||||
await this._initStickerRegistry(guildId)
|
||||
if (!this.stickerRegistry) return []
|
||||
const rows = await this.stickerRegistry.list().catch(() => [])
|
||||
return rows.slice(0, 128).map((s) => ({
|
||||
guildId: s.guildId || guildId,
|
||||
name: s.name,
|
||||
description: s.description || '',
|
||||
packName: s.packName || null,
|
||||
attachmentId: s.attachmentId || null,
|
||||
mimeType: s.mimeType || null,
|
||||
filename: s.filename || null,
|
||||
animated: !!s.animated,
|
||||
format: s.format || 'raster',
|
||||
updatedAt: hyperdbScope.coerceSyncUint(s.updatedAt, 0),
|
||||
tombstone: false
|
||||
}))
|
||||
},
|
||||
|
||||
async _ingestGuildStickersSyncBundle (rows = []) {
|
||||
const span = this.log.time('guild.sync.stickers', {
|
||||
spanKind: 'guild.sync.stickers',
|
||||
guildId: this.guild?.guild?.id,
|
||||
count: rows?.length || 0
|
||||
})
|
||||
let changed = 0
|
||||
const guildId = this.guild?.guild?.id
|
||||
if (!guildId) {
|
||||
span.end({ changed: 0, rows: 0 })
|
||||
return 0
|
||||
}
|
||||
await this._initStickerRegistry(guildId)
|
||||
if (!this.stickerRegistry) {
|
||||
span.end({ changed: 0, rows: 0 })
|
||||
return 0
|
||||
}
|
||||
for (const r of rows) {
|
||||
if (!r?.name) continue
|
||||
if (r.tombstone || r.removed) {
|
||||
const removed = await this.stickerRegistry.remove(r.name).catch(() => null)
|
||||
if (removed) changed += 1
|
||||
continue
|
||||
}
|
||||
const out = await this.stickerRegistry.ingestGossip(r)
|
||||
if (out) changed += 1
|
||||
}
|
||||
span.end({ changed, rows: rows?.length || 0 })
|
||||
if (changed > 0) this.emit('guild-sticker', { batch: true })
|
||||
return changed
|
||||
},
|
||||
|
||||
async _ingestPresenceVectorBundle (guildId, rows = []) {
|
||||
const span = this.log.time('guild.sync.presence', {
|
||||
spanKind: 'guild.sync.presence',
|
||||
@@ -899,6 +951,7 @@ async _buildGuildSyncBundle (limitPerChannel, opts = {}) {
|
||||
{ syncDelta, visibleOnly: true }
|
||||
)
|
||||
const guildEmojis = await this._exportGuildEmojisForSyncBundle(guild.id)
|
||||
const guildStickers = await this._exportGuildStickersForSyncBundle(guild.id)
|
||||
const pins = await this._exportPinsForSyncBundle(
|
||||
guild.id,
|
||||
syncChannels.map((c) => c.id),
|
||||
@@ -1012,6 +1065,7 @@ async _buildGuildSyncBundle (limitPerChannel, opts = {}) {
|
||||
channelCoreKeys,
|
||||
reactions,
|
||||
guildEmojis,
|
||||
guildStickers,
|
||||
presenceVector: this._exportPresenceVectorForSync(guild.id),
|
||||
forumIndex,
|
||||
voiceOccupancy,
|
||||
|
||||
@@ -597,6 +597,7 @@ async _ingestGuildSync (payload) {
|
||||
}
|
||||
const reactionChanges = await this._ingestReactionsSyncBundle(payload.reactions || [])
|
||||
const emojiChanges = await this._ingestGuildEmojisSyncBundle(payload.guildEmojis || [])
|
||||
const stickerChanges = await this._ingestGuildStickersSyncBundle(payload.guildStickers || [])
|
||||
let sparse = { mode: 'gossip', added: 0 }
|
||||
if (payload.channelCoreKeys?.length) {
|
||||
this._lastGuildSyncChannelCoreKeys = payload.channelCoreKeys.slice(0, 96)
|
||||
@@ -629,6 +630,7 @@ async _ingestGuildSync (payload) {
|
||||
roles: rolesApplied,
|
||||
reactions: reactionChanges,
|
||||
emojis: emojiChanges,
|
||||
stickers: stickerChanges,
|
||||
sparse,
|
||||
attachPull,
|
||||
ingestMs
|
||||
|
||||
@@ -24,6 +24,12 @@ const platformGuildSyncWireSparseMixin = {
|
||||
updatedAt: hyperdbScope.coerceSyncUint(e.updatedAt, 0)
|
||||
}))
|
||||
}
|
||||
if (Array.isArray(next.guildStickers)) {
|
||||
next.guildStickers = next.guildStickers.map((s) => ({
|
||||
...s,
|
||||
updatedAt: hyperdbScope.coerceSyncUint(s.updatedAt, 0)
|
||||
}))
|
||||
}
|
||||
return next
|
||||
},
|
||||
|
||||
|
||||
@@ -260,6 +260,7 @@ _wireGuild (guildInstance) {
|
||||
(payload?.memberRoleLinks?.length || 0)
|
||||
const payloadReactions = payload?.reactions?.length || 0
|
||||
const payloadEmojis = payload?.guildEmojis?.length || 0
|
||||
const payloadStickers = payload?.guildStickers?.length || 0
|
||||
const hasSlice =
|
||||
payloadMsgs > 0 ||
|
||||
payloadMems > 0 ||
|
||||
@@ -268,7 +269,8 @@ _wireGuild (guildInstance) {
|
||||
payloadVoice > 0 ||
|
||||
payloadRoles > 0 ||
|
||||
payloadReactions > 0 ||
|
||||
payloadEmojis > 0
|
||||
payloadEmojis > 0 ||
|
||||
payloadStickers > 0
|
||||
if (!result && !hasSlice) return
|
||||
this._lastGuildSyncIngestAt = Date.now()
|
||||
const msgCount =
|
||||
@@ -303,6 +305,10 @@ _wireGuild (guildInstance) {
|
||||
typeof result === 'object'
|
||||
? Math.max(result.emojis || 0, payloadEmojis)
|
||||
: payloadEmojis
|
||||
const stickersCount =
|
||||
typeof result === 'object'
|
||||
? Math.max(result.stickers || 0, payloadStickers)
|
||||
: payloadStickers
|
||||
if (
|
||||
msgCount > 0 ||
|
||||
memCount > 0 ||
|
||||
@@ -312,6 +318,7 @@ _wireGuild (guildInstance) {
|
||||
rolesCount > 0 ||
|
||||
reactionsCount > 0 ||
|
||||
emojisCount > 0 ||
|
||||
stickersCount > 0 ||
|
||||
hasSlice
|
||||
) {
|
||||
this.emit('guild-sync-ready', {
|
||||
@@ -323,7 +330,8 @@ _wireGuild (guildInstance) {
|
||||
voice: voiceCount,
|
||||
roles: rolesCount,
|
||||
reactions: reactionsCount,
|
||||
emojis: emojisCount
|
||||
emojis: emojisCount,
|
||||
stickers: stickersCount
|
||||
})
|
||||
if (payload?.guildId === this.guild?.guild?.id) {
|
||||
this._touchAllGuildMeshPeersSeen(payload.guildId, 'guild-sync')
|
||||
@@ -570,10 +578,14 @@ _wireGuild (guildInstance) {
|
||||
})
|
||||
}
|
||||
this.emit('guild-sticker', row)
|
||||
const gid = this.guild?.guild?.id
|
||||
if (gid) this.emit('guild-sync-ready', { guildId: gid, stickers: 1 })
|
||||
})
|
||||
guildInstance.on('guild-sticker-delete', (payload) => {
|
||||
this.stickerRegistry?.ingestDeleteGossip(payload).catch(() => {})
|
||||
this.emit('guild-sticker-delete', payload)
|
||||
const gid = this.guild?.guild?.id
|
||||
if (gid) this.emit('guild-sync-ready', { guildId: gid, stickers: 1 })
|
||||
})
|
||||
guildInstance.on('guild-sticker-pack', (row) => {
|
||||
this.stickerRegistry?.ingestPackGossip(row).catch(() => {})
|
||||
|
||||
Reference in New Issue
Block a user