This commit is contained in:
mmrbnjd
2025-08-03 17:22:49 +03:30
parent 381c877bc3
commit dace739e46
6 changed files with 192 additions and 23 deletions

View File

@@ -8,6 +8,8 @@
@inject GroupService groupService
@inject UserService userService
@inject IJSRuntime JS
@inject ToastService toastService
<ConfirmDialog @ref="dialog" />
<PageTitle>گفتمان</PageTitle>
<div class="container-fluid">
<div class="row" style="height:85vh">
@@ -64,11 +66,11 @@
<Badge Color="BadgeColor.Info" VisuallyHiddenText="Visually hidden text for Info">@item.GroupName</Badge>
</div>
}
<div class="item-time">
<small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small>
</div>
</div>
<div class="item-message">@item.LastText</div>
@@ -152,11 +154,7 @@
@if (ChatCurrent.status == Common.Enums.ConversationStatus.InProgress)
{
<Button Color="ButtonColor.Danger" Size=ButtonSize.ExtraSmall Outline="true" Class="finish-conversation-btn"
@onclick="async()=>
{
if(await chatService.ChatIsFinish(ChatCurrent.ID))
ChatCurrent.status=Common.Enums.ConversationStatus.Finished;
}">
@onclick="CloseChat">
<Icon Name="IconName.Escape" /> اتمام گفتگو
</Button>
@@ -167,7 +165,8 @@
else if (ChatCurrent.status == Common.Enums.ConversationStatus.Finished
&& (CurrentUser.Role == "Company" || ChatCurrent.ExperID == CurrentUser.ExperID))
{
<Button Color="ButtonColor.Success" Size=ButtonSize.ExtraSmall Outline="true" Class="finish-conversation-btn">
<Button Color="ButtonColor.Success" Size=ButtonSize.ExtraSmall Outline="true" Class="finish-conversation-btn"
@onclick="OpenChat">
<Icon Name="IconName.Escape" /> باز کردن گفتگو
</Button>
@@ -283,7 +282,7 @@
bool chatloading = false;
string SelectedChatUserName = "مهدی ربیع نژاد";
private bool _shouldObserveVisibility = false;
private ConfirmDialog dialog = default!;
}
@functions {
@@ -351,7 +350,7 @@
chatloading = true;
SelectedChatUserName = "در حال گفتگو با " + chatItem.UserFullName;
ChatCurrent = chatItem;
_shouldObserveVisibility = true; // فعال کن تا در OnAfterRenderAsync صدا زده بشه
StateHasChanged(); // مجبور کن Blazor رندر کنه
@@ -367,8 +366,50 @@
msg.IsRead = true;
await chatService.MarkAsReadChatItemAsync(id);
}
// StateHasChanged();
// StateHasChanged();
await Task.CompletedTask;
}
async Task OpenChat()
{
if (CurrentUser.Role == "Company" || CurrentUser.Role == "Exper" && ChatCurrent.ExperID==CurrentUser.ExperID)
{
if (ChatCurrent.status != Common.Enums.ConversationStatus.Finished) return;
if (await chatService.OpenChat(ChatCurrent.ID))
{
ChatCurrent.status = Common.Enums.ConversationStatus.InProgress;
StateHasChanged();
}
}
else toastService.Notify(new ToastMessage(ToastType.Danger, "دسترسی به این گفتگو ندارید"));
}
async Task CloseChat()
{
if (ChatCurrent.status == Common.Enums.ConversationStatus.Finished) return;
var options = new ConfirmDialogOptions
{
YesButtonText = "بله",
YesButtonColor = ButtonColor.Success,
NoButtonText = "انصراف",
NoButtonColor = ButtonColor.Danger
};
var confirmation = await dialog.ShowAsync(
title: "پایان دادن به گفتگو",
message1: "اطمینان دارید ؟",
confirmDialogOptions: options);
if (confirmation)
{
if (await chatService.ChatIsFinish(ChatCurrent.ID))
{
ChatCurrent.status = Common.Enums.ConversationStatus.Finished;
StateHasChanged();
}
}
}
}

View File

@@ -16,6 +16,8 @@
@inject IJSRuntime JS
@inject ToastService toastService
@layout UserPanelLayout
<ConfirmDialog @ref="dialog" />
<div class="container-fluid">
<div class="row" style="height:85vh">
@if (IsEndFirstProcess)
@@ -33,11 +35,11 @@
{
@if (LastOpenChat.status == Common.Enums.ConversationStatus.InProgress)
{
<Button Color="ButtonColor.Danger" Size=ButtonSize.ExtraSmall Outline="true" Class="finish-conversation-btn">
<Button Color="ButtonColor.Danger" Size=ButtonSize.ExtraSmall Outline="true" @onclick="CloseChat" Class="finish-conversation-btn">
<Icon Name="IconName.Escape" Class="me-1" /> اتمام گفتگو
</Button>
}
<Button Color="ButtonColor.Success" Size=ButtonSize.ExtraSmall Outline="true" Class="finish-conversation-btn">
<Button Color="ButtonColor.Success" Size=ButtonSize.ExtraSmall Outline="true" @onclick="NewChat" Class="finish-conversation-btn">
<Icon Name="IconName.ChatDots" Class="me-1" /> گفتگو جدید
</Button>
}
@@ -105,7 +107,7 @@
@foreach (var group in CompanyGroups)
{
<div class="group-card @(GroupID == group.ID ? "selected" : "")"
@onclick="() => SelectGroup(group.ID)">
@onclick="() => SelectGroup(group.ID)">
<div class="group-card-content">
@if (group.img == null || group.img.Length == 0)
{
@@ -133,7 +135,7 @@
<!-- B2: Message input -->
<div class="message-input-container" id="B2">
<div class="input-wrapper">
<input type="text" @bind-value="MsgInput" class="message-input" placeholder="پیام خود را بنویسید..." />
<input type="text" @bind-value="MsgInput" class="message-input" placeholder="پیام خود را بنویسید..." @onkeydown="HandleKeyDown" />
<Button Color="ButtonColor.Primary" Size=ButtonSize.Small @onclick="OnClickSendMsg" Class="send-btn">
<Icon Name="IconName.Send" />
</Button>
@@ -170,6 +172,7 @@
@code {
[Parameter] public int CompanyID { get; set; }
[Parameter] public int? ChatID { get; set; }
private ConfirmDialog dialog = default!;
private bool _shouldObserveVisibility = false;
int? GroupID = null;
@@ -297,7 +300,7 @@
{
if (ChatID.HasValue) LastOpenChat = await ChatService.Getchat(ChatID.GetValueOrDefault());
else LastOpenChat = LastOpenChat = await ChatService.GetLastOpenChatInCompany(CompanyID);
if (LastOpenChat != null)
{
@@ -337,6 +340,37 @@
await JS.InvokeVoidAsync("autoScrollToNewMessage");
}
}
}
async Task NewChat()
{
LastOpenChat = null;
}
async Task CloseChat()
{
var options = new ConfirmDialogOptions
{
YesButtonText = "بله",
YesButtonColor = ButtonColor.Success,
NoButtonText = "انصراف",
NoButtonColor = ButtonColor.Danger
};
var confirmation = await dialog.ShowAsync(
title: "پایان دادن به گفتگو",
message1: "اطمینان دارید ؟",
confirmDialogOptions: options);
if (confirmation)
{
if (await chatService.ChatIsFinishFromUser(LastOpenChat.ID))
{
LastOpenChat.status = Common.Enums.ConversationStatus.Finished;
StateHasChanged();
}
}
}
async Task Logout()
{
@@ -345,7 +379,6 @@
IsLogin = false;
StateHasChanged();
}
async Task SelectGroup(int groupId)
{
GroupID = groupId;
@@ -353,7 +386,10 @@
}
private string GetImageSource(byte[] bytes)
=> $"data:image/jpeg;base64,{Convert.ToBase64String(bytes)}";
private async Task HandleKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") await OnClickSendMsg();
}
}
<style>