17 lines
636 B
JavaScript
17 lines
636 B
JavaScript
![]() |
window.observeVisibility = (dotNetRef) => {
|
|||
|
const elements = document.querySelectorAll(".chat-bubble[data-id]");
|
|||
|
const observer = new IntersectionObserver(entries => {
|
|||
|
entries.forEach(entry => {
|
|||
|
if (entry.isIntersecting) {
|
|||
|
const id = entry.target.getAttribute("data-id");
|
|||
|
dotNetRef.invokeMethodAsync("MarkAsRead", parseInt(id));
|
|||
|
observer.unobserve(entry.target); // دیگه دوباره نخونه
|
|||
|
}
|
|||
|
});
|
|||
|
}, {
|
|||
|
threshold: 0.6 // 60٪ از پیام دیده بشه
|
|||
|
});
|
|||
|
|
|||
|
elements.forEach(el => observer.observe(el));
|
|||
|
};
|