Files
discourse/plugins/chat/assets/javascripts/discourse/lib/check-message-visibility.ts
T
David Taylor de793bc6ed DEV: add typescript support for core, themes and plugins (#41478)
We've been using basic type-checking via JSDoc for some time. This
commit allows us to author proper `.ts`/`.gts` files, and use the full
typescript syntax. Initially, only d-button and a single chat file are
migrated, as proof of functionality.

In future, we may migrate more files, and consider making our tsconfig
more strict.
2026-07-08 12:57:18 +01:00

23 lines
639 B
TypeScript

const BOTTOM_VISIBILITY_SLACK = 10;
export function checkMessageBottomVisibility(
list: Element,
message: Element
): boolean {
const distanceToTop = window.pageYOffset + list.getBoundingClientRect().top;
const bounding = message.getBoundingClientRect();
return (
bounding.bottom - distanceToTop <=
list.clientHeight + BOTTOM_VISIBILITY_SLACK
);
}
export function checkMessageTopVisibility(
list: Element,
message: Element
): boolean {
const distanceToTop = window.pageYOffset + list.getBoundingClientRect().top;
const bounding = message.getBoundingClientRect();
return bounding.top - distanceToTop >= -1;
}