This commit is contained in:
mmrbnjd
2025-08-02 13:35:49 +03:30
parent 44afa4dbb6
commit 8aa02020b9

View File

@@ -13,6 +13,7 @@
@inject GroupService groupService @inject GroupService groupService
@inject ChatService chatService @inject ChatService chatService
@inject IJSRuntime JS @inject IJSRuntime JS
@inject ToastService toastService
@layout UserPanelLayout @layout UserPanelLayout
<div class="container-fluid"> <div class="container-fluid">
<div class="row" style="height:85vh"> <div class="row" style="height:85vh">
@@ -138,7 +139,7 @@
@code { @code {
[Parameter] public int CompanyID { get; set; } [Parameter] public int CompanyID { get; set; }
private bool _shouldObserveVisibility = false; private bool _shouldObserveVisibility = false;
int? GroupID = null;
ReadANDUpdate_CompanyDto? CompanyInfo = new(); ReadANDUpdate_CompanyDto? CompanyInfo = new();
Common.Dtos.CurrentUserInfo CurrentUser = new(); Common.Dtos.CurrentUserInfo CurrentUser = new();
List<Read_GroupDto> CompanyGroups = new(); List<Read_GroupDto> CompanyGroups = new();
@@ -172,15 +173,26 @@
var model = await chatService.ADDChatResponse(LastOpenChat.ID, MsgInput, type); var model = await chatService.ADDChatResponse(LastOpenChat.ID, MsgInput, type);
LastOpenChat?.Responses.Add(model); LastOpenChat?.Responses.Add(model);
LastOpenChat.LastText = MsgInput; LastOpenChat.LastText = MsgInput;
await Task.Yield();
// Scroll to bottom for user's own messages
await JS.InvokeVoidAsync("scrollToBottom", "B1");
MsgInput = string.Empty;
} }
else else
{ {
//TODO New Chat //TODO New Chat
var model = await chatService.NewChatFromCurrentUser(new ADD_ConversationDto()
{
CompanyID = CompanyID,
GroupID = GroupID,
Question = MsgInput,
UserID = 0
});
if (model != null) LastOpenChat = model;
else toastService.Notify(new ToastMessage(ToastType.Danger, "خطا در گفتگو جدید"));
} }
await Task.Yield();
// Scroll to bottom for user's own messages
await JS.InvokeVoidAsync("scrollToBottom", "B1");
MsgInput = string.Empty;
} }
} }
@@ -245,14 +257,14 @@
LastOpenChat = null; LastOpenChat = null;
if (LastOpenChat != null) if (LastOpenChat != null)
{ {
// Always set up visibility observation for chat bubbles // Always set up visibility observation for chat bubbles
_shouldObserveVisibility = true; _shouldObserveVisibility = true;
StateHasChanged(); StateHasChanged();
// Wait for render to complete // Wait for render to complete
await Task.Delay(200); await Task.Delay(200);
// Scroll to target if exists, otherwise scroll to bottom // Scroll to target if exists, otherwise scroll to bottom
await JS.InvokeVoidAsync("scrollToTargetOrBottom"); await JS.InvokeVoidAsync("scrollToTargetOrBottom");
} }
@@ -266,7 +278,7 @@
{ {
msg.IsRead = true; msg.IsRead = true;
await chatService.MarkAsReadChatItemAsync(id); await chatService.MarkAsReadChatItemAsync(id);
// StateHasChanged(); // StateHasChanged();
} }
await Task.CompletedTask; await Task.CompletedTask;
} }
@@ -790,7 +802,7 @@
const targetRect = targetElement.getBoundingClientRect(); const targetRect = targetElement.getBoundingClientRect();
const containerRect = chatContainer.getBoundingClientRect(); const containerRect = chatContainer.getBoundingClientRect();
const relativeTop = targetRect.top - containerRect.top; const relativeTop = targetRect.top - containerRect.top;
// Scroll to show the target element with some padding // Scroll to show the target element with some padding
const scrollPosition = chatContainer.scrollTop + relativeTop - 100; // 100px padding const scrollPosition = chatContainer.scrollTop + relativeTop - 100; // 100px padding
chatContainer.scrollTo({ chatContainer.scrollTo({