fix(frontend): a link to a message opens the chat right at it without loading the latest page first

This commit is contained in:
hh committed 2026-10-19 03:00:23 +00:00
1 parent c247dd0217
commit fffbb08d36
2 files changed
+10 -6

No files matched your search

@@ -179,7 +179,7 @@
return messages.find((m) => holds(m, messageId))?.message_id ?? null; return messages.find((m) => holds(m, messageId))?.message_id ?? null;
} }
function jumpToMessage(messageId: number) { function jumpToMessage(messageId: number, smooth = true) {
const owner = ownerOf(messageId) ?? messageId; const owner = ownerOf(messageId) ?? messageId;
const target = container?.querySelector<HTMLElement>( const target = container?.querySelector<HTMLElement>(
`[data-message-id="${owner}"]` `[data-message-id="${owner}"]`
@@ -188,7 +188,10 @@
toasts.error(t("thread.notFound")); toasts.error(t("thread.notFound"));
return; return;
} }
target.scrollIntoView({ behavior: "smooth", block: "center" }); target.scrollIntoView({
behavior: smooth ? "smooth" : "auto",
block: "center",
});
highlightId = owner; highlightId = owner;
if (highlightTimer) { if (highlightTimer) {
clearTimeout(highlightTimer); clearTimeout(highlightTimer);
@@ -229,7 +232,7 @@
ui.clearJump(); ui.clearJump();
await loadAround(pending.messageId); await loadAround(pending.messageId);
await tick(); await tick();
jumpToMessage(pending.messageId); jumpToMessage(pending.messageId, false);
return; return;
} }
const page = await listMessages(chatId, { const page = await listMessages(chatId, {
@@ -514,11 +517,12 @@
async function goTo(messageId: number) { async function goTo(messageId: number) {
try { try {
if (ownerOf(messageId) === null) { const loaded = ownerOf(messageId) !== null;
if (!loaded) {
await loadAround(messageId); await loadAround(messageId);
} }
await tick(); await tick();
jumpToMessage(messageId); jumpToMessage(messageId, loaded);
} catch { } catch {
toasts.error(t("thread.loadFailed")); toasts.error(t("thread.loadFailed"));
} }
@@ -20,7 +20,7 @@
chats.enrich(chatId); chats.enrich(chatId);
}); });
$effect(() => { $effect.pre(() => {
if (linkedMessage === null) { if (linkedMessage === null) {
return; return;
} }