This commit is contained in:
mmrbnjd
2025-07-29 17:07:37 +03:30
parent cb8e8146b5
commit af37d0b85d
5 changed files with 158 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
@page "/Chant"
@page "/Chat"
@using Common.Dtos.Conversation
@using Common.Dtos.Group
@using Common.Enums
@@ -158,7 +158,44 @@
<!-- B1: Chat area -->
<div class="flex-fill border p-2 overflow-auto" id="B1" style="height: 300px; overflow-y: auto;">
@if (ChatCurrent != null && ChatCurrent.Responses != null)
{ @B1Content }
{
<div class="chat-container p-3">
@{
bool target = false;
}
@foreach (var msg in ChatCurrent?.Responses)
{
@if (!target && ((!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE) || ChatCurrent.Responses.Last() == msg))
{
target = true;
<div id="target" style="text-align: center;">
@if (!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE)
{
<p>ـــــــــــــــــــــــــ</p>
}
</div>
}
<div class="d-flex mb-2 @(msg.Type==Common.Enums.ConversationType.UE ? "justify-content-end" : "justify-content-start")">
<div class="chat-bubble @(msg.Type==Common.Enums.ConversationType.UE ? "chat-mine": "chat-other")" data-id="@msg.ID"> @msg.text </div>
@if (msg.Type == Common.Enums.ConversationType.EU)
{
if (msg.IsRead)
{
<Icon Style="align-self: self-end;" Name="IconName.CheckAll" Size="IconSize.x5" Color="IconColor.Success" />
}
else
{
<Icon Style="align-self: self-end;" Name="IconName.CheckLg" Size="IconSize.x5" />
}
}
</div>
}
@{
target = false;
}
</div>
}
else
{
<div class="d-flex justify-content-center align-items-center flex-column" style="height: 80%;">
@@ -195,7 +232,6 @@
@code {
public RenderFragment B1Content { get; set; }
public Common.Dtos.CurrentUserInfo CurrentUser { get; set; }
List<Read_GroupDto> _Group = new List<Read_GroupDto>();
//-------------------------------------
@@ -210,6 +246,8 @@
public string MsgInput { get; set; }
bool chatloading = false;
string SelectedChatUserName = "مهدی ربیع نژاد";
private bool _shouldObserveVisibility = false;
}
@functions {
@@ -220,8 +258,19 @@
Inbox1Items = await chatService.ChatAwaitingOurResponse();
Inbox2Items = await chatService.MyChatsIsInProgress();
Inbox3Items = await chatService.MyChatsIsFinished();
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (_shouldObserveVisibility)
{
_shouldObserveVisibility = false;
await JS.InvokeVoidAsync("observeVisibility", DotNetObjectReference.Create(this));
await JS.InvokeVoidAsync("scrollToTarget");
}
}
async Task OnclickInbox(int ID)
{
switch (ID)
@@ -262,37 +311,29 @@
}
async Task onClickSelectedChat(int InboxID, ChatItemDto chatItem)
{
chatloading = true;
SelectedChatUserName = "در حال گفتگو با " + chatItem.UserFullName;
ChatCurrent = chatItem;
_shouldObserveVisibility = true; // فعال کن تا در OnAfterRenderAsync صدا زده بشه
bool target = false;
B1Content =@<div class="chat-container p-3">
@foreach (var msg in ChatCurrent.Responses)
{
@if (!target && ((!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE) || ChatCurrent.Responses.Last() == msg))
{
target = true;
<div id="target" style="text-align: center;">
@if (!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE) { <p>ـــــــــــــــــــــــــ</p>}
</div>
}
<div class="d-flex mb-2 @(msg.Type==Common.Enums.ConversationType.UE ? "justify-content-end" : "justify-content-start")">
<div class="chat-bubble @(msg.Type==Common.Enums.ConversationType.UE ? "chat-mine": "chat-other")" data-id="@msg.ID"> @msg.text </div>
@if (msg.Type == Common.Enums.ConversationType.EU)
{
if (msg.IsRead) { <Icon Style="align-self: self-end;" Name="IconName.CheckAll" Size="IconSize.x5" Color="IconColor.Success" /> }
else { <Icon Style="align-self: self-end;" Name="IconName.CheckLg" Size="IconSize.x5" /> }
}
</div>
}
</div>;
await JS.InvokeVoidAsync("observeVisibility", DotNetObjectReference.Create(this));
await JS.InvokeVoidAsync("scrollToTarget");
StateHasChanged(); // مجبور کن Blazor رندر کنه
chatloading = false;
}
[JSInvokable]
public async Task MarkAsRead(int id)
{
var msg = ChatCurrent.Responses.FirstOrDefault(m => m.ID == id);
if (msg != null && !msg.IsRead && msg.Type == Common.Enums.ConversationType.UE)
{
msg.IsRead = true;
await chatService.MarkAsReadChatItemAsync(id);
}
StateHasChanged();
await Task.CompletedTask;
}
}
<style>
@@ -321,6 +362,7 @@
color: #353;
border-top-right-radius: 0;
}
.input-group-text-chat {
display: flex;
align-items: center;

View File

@@ -9,6 +9,11 @@ namespace HushianWebApp.Service
private readonly BaseController _baseController;
const string BaseRoute = "v1/Chat/";
public ChatService(BaseController baseController)
{
_baseController = baseController;
}
//Inbox1
public async Task<List<ChatItemDto>> ChatAwaitingOurResponse()
{
@@ -62,6 +67,12 @@ namespace HushianWebApp.Service
var response = await _baseController.Put($"{BaseRoute}ChatIsFinish/{ChatID}");
return response.IsSuccessStatusCode;
}
public async Task<bool> MarkAsReadChatItemAsync(int ID)
{
var response = await _baseController.Put($"{BaseRoute}MarkAsReadChatItem/{ID}");
return response.IsSuccessStatusCode;
}
}
}