fix: address code review issues for embeds implementation

- Fix ?? to || in metadataFetcher.ts to handle empty strings from Cheerio
- Fix stale embeds on message edit: delete old embeds synchronously before
  broadcast, then resolve new ones async (all 4 edit paths: REST+WS, msg+DM)
- Revert unrelated MessageList.tsx scroll threshold change (5000 not 150)
- Remove duplicate embed indexes from migrateAddIndexes (kept standalone ones)
This commit is contained in:
Jannis Braun
2026-03-20 23:58:06 +01:00
parent dcdf10c5de
commit ff2decded5
6 changed files with 30 additions and 23 deletions
+10 -4
View File
@@ -313,6 +313,9 @@ function handleMessageEdit(event: Record<string, unknown>, userId: string): void
const spaceId = getChannelSpaceId(message.channelId);
if (!spaceId) return;
// Delete old embeds synchronously so the broadcast reflects the edit
db.delete(schema.embeds).where(eq(schema.embeds.messageId, messageId)).run();
const updatedMessage = getMessageWithUser(messageId);
if (updatedMessage) {
connectionManager.sendToChannel(spaceId, message.channelId, {
@@ -320,9 +323,9 @@ function handleMessageEdit(event: Record<string, unknown>, userId: string): void
message: updatedMessage,
});
// Re-resolve embeds asynchronously
// Resolve new embeds asynchronously (old ones already deleted above)
setImmediate(() => {
reResolveEmbeds(messageId, content.trim(), message.channelId, false, spaceId).catch(() => {});
resolveEmbeds(messageId, content.trim(), message.channelId, false, spaceId).catch(() => {});
});
}
}
@@ -862,6 +865,9 @@ function handleDmMessageEdit(event: Record<string, unknown>, userId: string): vo
.where(eq(schema.dmMessages.id, messageId))
.run();
// Delete old embeds synchronously so the broadcast reflects the edit
db.delete(schema.embeds).where(eq(schema.embeds.dmMessageId, messageId)).run();
const updated = getDmMessageWithUser(messageId);
if (!updated) return;
@@ -877,9 +883,9 @@ function handleDmMessageEdit(event: Record<string, unknown>, userId: string): vo
});
}
// Re-resolve embeds asynchronously
// Resolve new embeds asynchronously (old ones already deleted above)
setImmediate(() => {
reResolveEmbeds(messageId, content.trim(), msg.dmChannelId, true, null).catch(() => {});
resolveEmbeds(messageId, content.trim(), msg.dmChannelId, true, null).catch(() => {});
});
}