Files
Joffrey JAFFEUXandGitHub 8ca0bdd2f7 FIX: correctly updates last read on scroll arrow click (#25838)
Prior to this fix the scroll was ignored when clicking the arrow bottom which would prevent the call to update last read. This fix manually calls update last read in this case and adds a test for it.
2024-02-23 14:23:17 +01:00

56 lines
1.2 KiB
JavaScript

import { next, schedule } from "@ember/runloop";
import { stackingContextFix } from "discourse/plugins/chat/discourse/lib/chat-ios-hacks";
export async function scrollListToBottom(list) {
await new Promise((resolve) => {
stackingContextFix(list, () => {
list.scrollTo({ top: 0, behavior: "auto" });
next(resolve);
});
});
}
export async function scrollListToTop(list) {
await new Promise((resolve) => {
stackingContextFix(list, () => {
list.scrollTo({ top: -list.scrollHeight, behavior: "auto" });
next(resolve);
});
});
}
export function scrollListToMessage(
list,
message,
opts = { highlight: false, position: "start", autoExpand: false }
) {
if (!message) {
return;
}
if (message?.deletedAt && opts.autoExpand) {
message.expanded = true;
}
schedule("afterRender", () => {
const messageEl = list.querySelector(
`.chat-message-container[data-id='${message.id}']`
);
if (!messageEl) {
return;
}
if (opts.highlight) {
message.highlight();
}
stackingContextFix(list, () => {
messageEl.scrollIntoView({
behavior: "auto",
block: opts.position || "center",
});
});
});
}