From cb8e8146b5ced8231f0bc0b1cc7e6cd599102d8d Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Tue, 29 Jul 2025 00:00:16 +0330 Subject: [PATCH] ... --- .../ApplicationServicesRegistration.cs | 1 + Hushian.Application/Services/ChatService.cs | 21 +- .../Controllers/v1/ChatController.cs | 7 + Presentation/HushianWebApp/Pages/Chat.razor | 254 +++++++++++++++++- Presentation/HushianWebApp/Program.cs | 1 + .../HushianWebApp/Service/ChatService.cs | 5 + 6 files changed, 281 insertions(+), 8 deletions(-) diff --git a/Hushian.Application/ApplicationServicesRegistration.cs b/Hushian.Application/ApplicationServicesRegistration.cs index 8e04b88..927bcd0 100644 --- a/Hushian.Application/ApplicationServicesRegistration.cs +++ b/Hushian.Application/ApplicationServicesRegistration.cs @@ -63,6 +63,7 @@ namespace Hushian.Application services.AddScoped(typeof(AuthService)); services.AddScoped(typeof(CompanyService)); services.AddScoped(typeof(ConversationService)); + services.AddScoped(typeof(ChatService)); services.AddScoped(typeof(ExperService)); services.AddScoped(typeof(GroupService)); services.AddScoped(typeof(UserService)); diff --git a/Hushian.Application/Services/ChatService.cs b/Hushian.Application/Services/ChatService.cs index 39385ee..1ce2d9e 100644 --- a/Hushian.Application/Services/ChatService.cs +++ b/Hushian.Application/Services/ChatService.cs @@ -54,7 +54,7 @@ namespace Hushian.Application.Services IsRead = ss.IsRead, text = ss.Text, Type = ss.Type - }) + }).ToList() }).ToListAsync(); public async Task> GetChatsByCompanyID(int CompanyID, ConversationStatus status) @@ -88,7 +88,7 @@ namespace Hushian.Application.Services IsRead = ss.IsRead, text = ss.Text, Type = ss.Type - }) + }).ToList() }).ToListAsync(); public async Task> ChatsAwaitingOurResponse(int CompanyID) @@ -122,7 +122,7 @@ namespace Hushian.Application.Services IsRead = ss.IsRead, text = ss.Text, Type = ss.Type - }) + }).ToList() }).ToListAsync(); //------------------------ @@ -242,5 +242,20 @@ namespace Hushian.Application.Services return Response; } + public async Task FinishChat(int ChatID) + { + var convModel = await _ConversationRepository.Get() + .Include(inc => inc.ConversationResponses) + .FirstOrDefaultAsync(w => w.ID == ChatID); + + if (convModel != null && convModel.Status != ConversationStatus.Finished) + { + convModel.Status = ConversationStatus.Finished; + convModel.FinishedDateTime = DateTime.Now; + return await _ConversationRepository.UPDATEBool(convModel); + } + + return true; + } } } diff --git a/Presentation/Hushian.WebApi/Controllers/v1/ChatController.cs b/Presentation/Hushian.WebApi/Controllers/v1/ChatController.cs index 038180b..9756e44 100644 --- a/Presentation/Hushian.WebApi/Controllers/v1/ChatController.cs +++ b/Presentation/Hushian.WebApi/Controllers/v1/ChatController.cs @@ -93,5 +93,12 @@ namespace Hushian.WebApi.Controllers.v1 return Response.Success ? Ok(Response.Value) : BadRequest(Response.Errors); } + [HttpGet("ChatIsFinish/{ChatID}")] + [Authorize(Roles = "Company,Exper")] + public async Task ChatIsFinish(int ChatID) + { + return await _chatService.FinishChat(ChatID) ? NoContent() + : BadRequest(new List { "خطا در بروزرسانی وضعیت" }); + } } } diff --git a/Presentation/HushianWebApp/Pages/Chat.razor b/Presentation/HushianWebApp/Pages/Chat.razor index 6fbb2ad..24c762e 100644 --- a/Presentation/HushianWebApp/Pages/Chat.razor +++ b/Presentation/HushianWebApp/Pages/Chat.razor @@ -1,12 +1,201 @@ @page "/Chant" @using Common.Dtos.Conversation @using Common.Dtos.Group +@using Common.Enums @using HushianWebApp.Service @inject ChatService chatService @inject GroupService groupService @inject UserService userService @inject IJSRuntime JS + +
+
+ +
+ +
+ گفتگو های اخیر +
+ + + +
+ + + + + + + + + + + + + + +
+ + +
+ + @if (isSelectedInbox1) + { + @foreach (var item in Inbox1Items) + { +
+ +
+
+ @item.UserFullName + @item.LastMsgdate + @item.LastMsgtime +
+
@item.LastText
+
+ + @item.Responses.Count() +
+ + + + } + } + + @if (isSelectedInbox2) + { + @foreach (var item in Inbox2Items) + { +
+ +
+
+ @item.UserFullName + @item.LastMsgdate + @item.LastMsgtime +
+
@item.LastText
+
+ @if (item.Responses.Count(c => !c.IsRead && c.Type == ConversationType.UE) > 0) + { + @item.Responses.Count(c => !c.IsRead && c.Type == ConversationType.UE) + } + + +
+ + } + } + + @if (isSelectedInbox3) + { + @foreach (var item in Inbox3Items) + { +
+ +
+
+ @item.UserFullName + @item.LastMsgdate + @item.LastMsgtime +
+
@item.LastText
+
+ +
+ + } + } + +
+
+ + + +
+
+ @if (ChatCurrent != null) + { +

@SelectedChatUserName

+ + @if (ChatCurrent.status == Common.Enums.ConversationStatus.InProgress) + { + + + + } + else if (ChatCurrent.status == Common.Enums.ConversationStatus.Finished + && (CurrentUser.Role == "Company" || ChatCurrent.ExperID == CurrentUser.ExperID)) + { + + } + + } + +
+ +
+ @if (ChatCurrent != null && ChatCurrent.Responses != null) + { @B1Content } + else + { +
+ + +

+ هوشیان +

+
+ + + } + +
+ + @if (ChatCurrent != null && ChatCurrent.status != Common.Enums.ConversationStatus.Finished && ChatCurrent.Responses != null) + { + +
+ + + + + +
+ } + + +
+ + +
+
+ + @code { + public RenderFragment B1Content { get; set; } public Common.Dtos.CurrentUserInfo CurrentUser { get; set; } List _Group = new List(); //------------------------------------- @@ -19,11 +208,14 @@ ///////////// public ChatItemDto? ChatCurrent { get; set; } = null; public string MsgInput { get; set; } + bool chatloading = false; + string SelectedChatUserName = "مهدی ربیع نژاد"; + } @functions { protected override async Task OnInitializedAsync() { - CurrentUser =await userService.GetCurrentUserInfo(); + CurrentUser = await userService.GetCurrentUserInfo(); _Group = await groupService.GetGroups(); Inbox1Items = await chatService.ChatAwaitingOurResponse(); Inbox2Items = await chatService.MyChatsIsInProgress(); @@ -37,7 +229,7 @@ case 1: isSelectedInbox1 = true; isSelectedInbox2 = false; - isSelectedInbox3 = false; + isSelectedInbox3 = false; break; case 2: @@ -55,7 +247,7 @@ ChatCurrent = null; } - async Task SendMsg() + async Task OnClickSendMsg() { if (!string.IsNullOrEmpty(MsgInput) && ChatCurrent != null) { @@ -68,15 +260,67 @@ MsgInput = string.Empty; } } - async Task onClickSelectedCon(int InboxID, Read_ConversationDto conversationDto) + async Task onClickSelectedChat(int InboxID, ChatItemDto chatItem) { - + chatloading = true; + SelectedChatUserName = "در حال گفتگو با " + chatItem.UserFullName; + ChatCurrent = chatItem; + + bool target = false; + B1Content =@
+ @foreach (var msg in ChatCurrent.Responses) + { + @if (!target && ((!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE) || ChatCurrent.Responses.Last() == msg)) + { + target = true; +
+ @if (!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE) {

ـــــــــــــــــــــــــ

} +
+ } + +
+
@msg.text
+ @if (msg.Type == Common.Enums.ConversationType.EU) + { + if (msg.IsRead) { } + else { } + } +
+ } +
; + await JS.InvokeVoidAsync("observeVisibility", DotNetObjectReference.Create(this)); + await JS.InvokeVoidAsync("scrollToTarget"); + chatloading = false; } }