fix(discord): do not treat embed generation or removal as message edits
Link unfurls and "Remove Embeds" (SUPPRESS_EMBEDS) both fire MessageUpdate. Only a real author edit sets a new edited_timestamp, so skip updates whose editedAt is null or unchanged. The same-text check alone missed Remove Embeds when the cached old text was stale; drop the `?? new Date()` fallback that let timestamp-less updates through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1389,6 +1389,51 @@ describe('message edit handling', () => {
|
||||
expect(opts.onMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ignores an embed being generated for a link (edit time unchanged)', async () => {
|
||||
const opts = createTestOpts();
|
||||
const channel = new DiscordChannel('test-token', opts);
|
||||
await channel.connect();
|
||||
|
||||
// Unfurl: Discord adds the embed but leaves edited_timestamp null.
|
||||
const oldMessage = {
|
||||
...createMessage({ content: '이거 봐 https://example.com' }),
|
||||
editedAt: null,
|
||||
embeds: [],
|
||||
};
|
||||
const newMessage = {
|
||||
...createMessage({ content: '이거 봐 https://example.com' }),
|
||||
editedAt: null,
|
||||
embeds: [{ url: 'https://example.com', title: 'Example' }],
|
||||
};
|
||||
await triggerMessageUpdate(oldMessage, newMessage);
|
||||
|
||||
expect(opts.onMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ignores "Remove Embeds" even on a message that was edited before', async () => {
|
||||
const opts = createTestOpts();
|
||||
const channel = new DiscordChannel('test-token', opts);
|
||||
await channel.connect();
|
||||
|
||||
// SUPPRESS_EMBEDS keeps the earlier edited_timestamp. The cached old text
|
||||
// is deliberately different so only the edit-time check can reject it.
|
||||
const editedAt = new Date('2024-01-01T00:05:00.000Z');
|
||||
const oldMessage = {
|
||||
...createMessage({ content: '수정 전 https://example.com' }),
|
||||
editedAt: new Date(editedAt),
|
||||
embeds: [{ url: 'https://example.com' }],
|
||||
};
|
||||
const newMessage = {
|
||||
...createMessage({ content: '수정 후 https://example.com' }),
|
||||
editedAt: new Date(editedAt),
|
||||
embeds: [],
|
||||
flags: { has: (flag: number) => flag === 1 << 2 },
|
||||
};
|
||||
await triggerMessageUpdate(oldMessage, newMessage);
|
||||
|
||||
expect(opts.onMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ignores edits by bots, including its own messages', async () => {
|
||||
const opts = createTestOpts();
|
||||
const channel = new DiscordChannel('test-token', opts);
|
||||
|
||||
@@ -415,9 +415,16 @@ export class DiscordChannel implements Channel {
|
||||
// Human edits only: own/other bot edits (streaming progress, reviewer bot)
|
||||
// are not user input.
|
||||
if (newMessage.author.bot) return;
|
||||
// Discord sets a new edited_timestamp only when the author edits the
|
||||
// message. Embed/link-preview generation and "Remove Embeds" (the
|
||||
// SUPPRESS_EMBEDS flag) also fire MessageUpdate but leave it unchanged.
|
||||
const editedAt = newMessage.editedAt;
|
||||
if (!editedAt || editedAt.getTime() === oldMessage.editedAt?.getTime()) {
|
||||
return;
|
||||
}
|
||||
const before = oldMessage.content;
|
||||
const after = newMessage.content;
|
||||
// Same text = embed/link-preview update, not a user edit.
|
||||
// Same text = not a text edit.
|
||||
if (before === after) return;
|
||||
|
||||
const chatJid = `dc:${newMessage.channelId}`;
|
||||
@@ -430,7 +437,6 @@ export class DiscordChannel implements Channel {
|
||||
return;
|
||||
}
|
||||
|
||||
const editedAt = newMessage.editedAt ?? new Date();
|
||||
const senderName =
|
||||
newMessage.member?.displayName ||
|
||||
newMessage.author.displayName ||
|
||||
|
||||
Reference in New Issue
Block a user