fix(im): scope interaction message lookup by chat in ImOutputRegistry

This commit is contained in:
MicroBlock committed 2026-11-17 20:45:14 +08:00
1 parent 3d3a73eb85
commit 324ca9b137
2 files changed
+17 -1

No files matched your search

+2 -1
View File
@@ -213,9 +213,10 @@ export class ImOutputRegistry implements ImOutputs {
// next inbound frame is re-admitted against the current rules, so the controls have to be as well.
if (!admitsChat(source, interaction.bot.id, interaction.chat)) return
if (!allows(source.users, interaction.user.id)) return
const message = interaction.message === undefined
const candidate = interaction.message === undefined
? undefined
: this.deps.im.history.get(ImMessageKey(interaction.bot.id, interaction.message.id))
const message = candidate?.chat.key === chat.key ? candidate : undefined
const owner = message === undefined ? undefined : this.deps.sender.sessionOf(message.key)
return { chat, ...message === undefined ? {} : { message }, ...owner === undefined ? {} : { session: owner } }
}
@@ -380,6 +380,21 @@ describe('ImOutputRegistry buttons', () => {
expect(harness.buttons).toHaveLength(1)
})
it('ignores a stored message belonging to another chat when attributing an interaction', async () => {
const harness = booted()
harness.host({ output: 'probe' })
const foreign = harness.host({ key: 'foreign', output: 'probe', bindings: [{ chat: ImChatKey('fake:bot', 'elsewhere'), writable: true, home: true }] })
const foreignMsg = { ...inbound(), key: ImMessageKey('fake:bot', 'm-foreign'), chat: chatOf('elsewhere') }
// Simulate an alias collision where history.get(aliasKey) returns a message from another chat.
harness.messages.set(ImMessageKey('fake:bot', 'REFIDX_shared'), foreignMsg)
harness.sender.owners.set(foreignMsg.key, foreign.sessionId)
await harness.registry.button(click('dsh:plain', { message: 'REFIDX_shared' }))
expect(harness.buttons).toHaveLength(1)
expect(harness.buttons[0]?.message).toBeUndefined()
expect(harness.buttons[0]?.session).toBeUndefined()
})
it('routes the stop button of a bound session to sessions.stop', async () => {
const harness = booted()
const hosted = harness.host({ output: 'probe' })