fix(frontend): a link to a message opens the chat right at it without loading the latest page first
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
function jumpToMessage(messageId: number) {
|
||||
function jumpToMessage(messageId: number, smooth = true) {
|
||||
const owner = ownerOf(messageId) ?? messageId;
|
||||
const target = container?.querySelector<HTMLElement>(
|
||||
`[data-message-id="${owner}"]`
|
||||
@@ -188,7 +188,10 @@
|
||||
toasts.error(t("thread.notFound"));
|
||||
return;
|
||||
}
|
||||
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
target.scrollIntoView({
|
||||
behavior: smooth ? "smooth" : "auto",
|
||||
block: "center",
|
||||
});
|
||||
highlightId = owner;
|
||||
if (highlightTimer) {
|
||||
clearTimeout(highlightTimer);
|
||||
@@ -229,7 +232,7 @@
|
||||
ui.clearJump();
|
||||
await loadAround(pending.messageId);
|
||||
await tick();
|
||||
jumpToMessage(pending.messageId);
|
||||
jumpToMessage(pending.messageId, false);
|
||||
return;
|
||||
}
|
||||
const page = await listMessages(chatId, {
|
||||
@@ -514,11 +517,12 @@
|
||||
|
||||
async function goTo(messageId: number) {
|
||||
try {
|
||||
if (ownerOf(messageId) === null) {
|
||||
const loaded = ownerOf(messageId) !== null;
|
||||
if (!loaded) {
|
||||
await loadAround(messageId);
|
||||
}
|
||||
await tick();
|
||||
jumpToMessage(messageId);
|
||||
jumpToMessage(messageId, loaded);
|
||||
} catch {
|
||||
toasts.error(t("thread.loadFailed"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user