This commit is contained in:
mmrbnjd
2025-07-31 02:35:14 +03:30
parent 01922b0922
commit 38031b2e81
2 changed files with 25 additions and 20 deletions

View File

@@ -236,27 +236,16 @@
LastOpenChat = await ChatService.GetLastOpenChatInCompany(CompanyID);
if (LastOpenChat != null)
{
// Check if there are unread messages
var hasUnreadMessages = LastOpenChat.Responses?.Any(m => !m.IsRead && m.Type != Common.Enums.ConversationType.UE) ?? false;
if (hasUnreadMessages)
{
_shouldObserveVisibility = true;
StateHasChanged();
// Scroll to target (new message separator) after render
await Task.Delay(100);
await JS.InvokeVoidAsync("scrollToTarget");
}
else
{
// If no unread messages, scroll to bottom
await Task.Delay(100);
await JS.InvokeVoidAsync("scrollToBottom", "B1");
}
// Always set up visibility observation for chat bubbles
_shouldObserveVisibility = true;
StateHasChanged();
// Wait for render to complete
await Task.Delay(200);
// Scroll to target if exists, otherwise scroll to bottom
await JS.InvokeVoidAsync("scrollToTargetOrBottom");
}
}
}
@@ -776,7 +765,10 @@
window.scrollToBottom = (elementId) => {
const el = document.getElementById(elementId);
if (el) {
el.scrollTop = el.scrollHeight;
el.scrollTo({
top: el.scrollHeight,
behavior: 'smooth'
});
}
};
@@ -798,6 +790,9 @@
behavior: 'smooth'
});
}
} else {
// If no target element exists, scroll to bottom smoothly
window.scrollToBottom('B1');
}
};
@@ -826,4 +821,14 @@
}, 100); // Small delay to ensure DOM is updated
};
// Check if target exists and scroll accordingly
window.scrollToTargetOrBottom = () => {
const targetElement = document.getElementById('target');
if (targetElement && targetElement.style.display !== 'none') {
window.scrollToTarget();
} else {
window.scrollToBottom('B1');
}
};
</script>