...
This commit is contained in:
@@ -272,11 +272,44 @@ namespace Hushian.Application.Services
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<bool> FinishChat(int ChatID)
|
||||
public async Task<bool> FinishChat(int ChatID, int CompanyID)
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w => w.ID == ChatID);
|
||||
.FirstOrDefaultAsync(w => w.ID == ChatID && w.CompanyID==CompanyID);
|
||||
|
||||
if (convModel != null && convModel.Status != ConversationStatus.Finished)
|
||||
{
|
||||
convModel.Status = ConversationStatus.Finished;
|
||||
convModel.FinishedDateTime = DateTime.Now;
|
||||
return await _ConversationRepository.UPDATEBool(convModel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> OpenChat(int ChatID, int CompanyID,int? ExperID)
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w =>
|
||||
w.ID == ChatID
|
||||
&& w.CompanyID == CompanyID
|
||||
&& ExperID.HasValue ? w.ConversationResponses.Any(a=>a.ExperID==ExperID.GetValueOrDefault()) :true);
|
||||
|
||||
if (convModel != null && convModel.Status == ConversationStatus.Finished)
|
||||
{
|
||||
convModel.Status = ConversationStatus.InProgress;
|
||||
convModel.FinishedDateTime = null;
|
||||
return await _ConversationRepository.UPDATEBool(convModel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> FinishChatFromUser(int ChatID, int userID)
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w => w.ID == ChatID && w.UserID == userID);
|
||||
|
||||
if (convModel != null && convModel.Status != ConversationStatus.Finished)
|
||||
{
|
||||
|
@@ -122,11 +122,60 @@ namespace Hushian.WebApi.Controllers.v1
|
||||
return Response.Success ? Ok(Response.Value)
|
||||
: BadRequest(Response.Errors);
|
||||
}
|
||||
[HttpGet("ChatIsFinish/{ChatID}")]
|
||||
[HttpPut("ChatIsFinish/{ChatID}")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> ChatIsFinish(int ChatID)
|
||||
{
|
||||
return await _chatService.FinishChat(ChatID) ? NoContent()
|
||||
|
||||
int CompanyID = 0;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
|
||||
CompanyID = await _experService.GetCompanyIDExper(ExperID);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
}
|
||||
|
||||
return await _chatService.FinishChat(ChatID, CompanyID) ? NoContent()
|
||||
: BadRequest(new List<string> { "خطا در بروزرسانی وضعیت" });
|
||||
}
|
||||
[HttpPut("OpenChat/{ChatID}")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> OpenChat(int ChatID)
|
||||
{
|
||||
|
||||
int CompanyID = 0;
|
||||
int? ExperID =null;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
ExperID = Convert.ToInt32(strExperID);
|
||||
|
||||
CompanyID = await _experService.GetCompanyIDExper(ExperID.GetValueOrDefault());
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
}
|
||||
|
||||
return await _chatService.OpenChat(ChatID, CompanyID, ExperID) ? NoContent()
|
||||
: BadRequest(new List<string> { "خطا در بروزرسانی وضعیت" });
|
||||
}
|
||||
[HttpPut("ChatIsFinishFromUser/{ChatID}")]
|
||||
[Authorize(Roles = "User")]
|
||||
public async Task<ActionResult> ChatIsFinishFromUser(int ChatID)
|
||||
{
|
||||
string strUserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int UserID = Convert.ToInt32(strUserID);
|
||||
|
||||
|
||||
return await _chatService.FinishChatFromUser(ChatID, UserID) ? NoContent()
|
||||
: BadRequest(new List<string> { "خطا در بروزرسانی وضعیت" });
|
||||
}
|
||||
[HttpPut("MarkAsReadChatItem/{ConversationItemID}")]
|
||||
|
@@ -27,7 +27,7 @@
|
||||
"Key": "84322CFB66934ECC86D547C5CF4F2EFC",
|
||||
"Audience": "MMRbnjd",
|
||||
"Issuer": "MMRbnjd",
|
||||
"DurationInMinutes": 60
|
||||
"DurationInMinutes": 6000
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
@@ -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">
|
||||
@@ -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 {
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
@@ -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>
|
||||
|
@@ -62,11 +62,21 @@ namespace HushianWebApp.Service
|
||||
return null;
|
||||
|
||||
}
|
||||
public async Task<bool> OpenChat(int ChatID)
|
||||
{
|
||||
var response = await _baseController.Put($"{BaseRoute}OpenChat/{ChatID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<bool> ChatIsFinish(int ChatID)
|
||||
{
|
||||
var response = await _baseController.Put($"{BaseRoute}ChatIsFinish/{ChatID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<bool> ChatIsFinishFromUser(int ChatID)
|
||||
{
|
||||
var response = await _baseController.Put($"{BaseRoute}ChatIsFinishFromUser/{ChatID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<bool> MarkAsReadChatItemAsync(int ID)
|
||||
{
|
||||
var response = await _baseController.Put($"{BaseRoute}MarkAsReadChatItem/{ID}");
|
||||
|
Reference in New Issue
Block a user