This commit is contained in:
mmrbnjd
2025-08-02 19:00:53 +03:30
parent 7fd53e5d5a
commit 4843890f9d
5 changed files with 158 additions and 35 deletions

View File

@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -166,22 +167,39 @@ namespace Hushian.Application.Services
ConversationResponses = new List<ConversationResponse>() { new() { Text = dto.Question, Type = type } } ConversationResponses = new List<ConversationResponse>() { new() { Text = dto.Question, Type = type } }
}; };
var mi = await _ConversationRepository.ADD(conversation); var mi = await _ConversationRepository.ADD(conversation);
Response.Value = new ChatItemDto() if(mi.ID > 0)
Response.Value = await _ConversationRepository.Get()
.Include(inc => inc.Group).Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.ID==mi.ID)
.Select(s => new ChatItemDto()
{ {
ID = mi.ID, ID = s.ID,
ExperID = mi.ConversationResponses.OrderBy(o => o.ID).Last().ExperID, ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
ExperFullName = /*mi.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName*/ "", ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
GroupID = mi.GroupID, GroupID = s.GroupID,
GroupName = /*mi.Group.Name*/ "", GroupName = s.Group.Name,
LastText = mi.ConversationResponses.OrderBy(o => o.ID).Last().Text, LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
LastMsgdate = mi.Cdatetime.GetDatePersian(), LastMsgdate = s.Cdatetime.GetDatePersian(),
LastMsgtime = mi.Cdatetime.GetTime(), LastMsgtime = s.Cdatetime.GetTime(),
LastMsgType = mi.ConversationResponses.OrderBy(o => o.ID).Last().Type, LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
status = mi.Status, status = s.Status,
UserID = mi.UserID, UserID = s.UserID,
UserFullName = /*string.IsNullOrEmpty(mi.User.FullName) ? mi.User.Mobile : mi.User.FullName*/ "" UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
{
ChatItemID = ss.ConversationID,
ExperID = ss.ExperID,
ExperName = ss.Exper.FullName,
FileContent = ss.FileContent,
FileName = ss.FileName,
FileType = ss.FileType,
ID = ss.ID,
IsRead = ss.IsRead,
text = ss.Text,
Type = ss.Type
}).ToList()
}; }).FirstOrDefaultAsync();
Response.Success = mi.ID > 0; Response.Success = mi.ID > 0;
} }
else Response.Errors.Add("شناسه گروه صحیح نمی باشد"); else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
@@ -305,7 +323,49 @@ namespace Hushian.Application.Services
Response.Value= await _ConversationRepository.Get() Response.Value= await _ConversationRepository.Get()
.Include(inc => inc.Group) .Include(inc => inc.Group)
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper) .Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.UserID== UserID && w.Status != ConversationStatus.Finished) .Where(w => w.UserID== UserID &&w.CompanyID==CompanyID && w.Status != ConversationStatus.Finished)
.OrderByDescending(o=>o.ID)
.Select(s => new ChatItemDto()
{
ID = s.ID,
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
GroupID = s.GroupID,
GroupName = s.Group.Name,
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
LastMsgdate = s.Cdatetime.GetDatePersian(),
LastMsgtime = s.Cdatetime.GetTime(),
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
status = s.Status,
UserID = s.UserID,
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
{
ChatItemID = ss.ConversationID,
ExperID = ss.ExperID,
ExperName = ss.Exper.FullName,
FileContent = ss.FileContent,
FileName = ss.FileName,
FileType = ss.FileType,
ID = ss.ID,
IsRead = ss.IsRead,
text = ss.Text,
Type = ss.Type
}).ToList()
}).FirstOrDefaultAsync();
if (Response.Value != null) Response.Success = true;
return Response;
}
public async Task<ResponseBase<ChatItemDto>> GetChat(int ChatID, int UserID)
{
ResponseBase<ChatItemDto> Response = new();
Response.Value = await _ConversationRepository.Get()
.Include(inc => inc.Group)
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.UserID == UserID && w.ID == ChatID )
.OrderByDescending(o => o.ID)
.Select(s => new ChatItemDto() .Select(s => new ChatItemDto()
{ {
ID = s.ID, ID = s.ID,

View File

@@ -52,6 +52,17 @@ namespace Hushian.WebApi.Controllers.v1
return response.Success ? Ok(response.Value) : Accepted() ; return response.Success ? Ok(response.Value) : Accepted() ;
}
[HttpGet("User/Chat/{ChatID}")]
[Authorize(Roles = "User")]
public async Task<ActionResult> Getchat(int ChatID)
{
string strUserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int UserID = Convert.ToInt32(strUserID);
var response = await _chatService.GetChat(ChatID, UserID);
return response.Success ? Ok(response.Value) : Accepted();
} }
[HttpGet("ChatsAwaitingOurResponse")] [HttpGet("ChatsAwaitingOurResponse")]
[Authorize(Roles = "Company,Exper")] [Authorize(Roles = "Company,Exper")]

View File

@@ -59,9 +59,16 @@
<div class="item-content"> <div class="item-content">
<div class="item-header"> <div class="item-header">
<strong class="item-name">@item.UserFullName </strong> <strong class="item-name">@item.UserFullName </strong>
@if(!string.IsNullOrEmpty(item.GroupName)){
<div class="mb-3">
<Badge Color="BadgeColor.Info" VisuallyHiddenText="Visually hidden text for Info">@item.GroupName</Badge>
</div>
}
<div class="item-time"> <div class="item-time">
<small class="time-text">@item.LastMsgdate</small> <small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small> <small class="time-text">@item.LastMsgtime</small>
</div> </div>
</div> </div>
<div class="item-message">@item.LastText</div> <div class="item-message">@item.LastText</div>
@@ -82,6 +89,12 @@
<div class="item-content"> <div class="item-content">
<div class="item-header"> <div class="item-header">
<strong class="item-name">@item.UserFullName</strong> <strong class="item-name">@item.UserFullName</strong>
@if (!string.IsNullOrEmpty(item.GroupName))
{
<div class="mb-3">
<Badge Color="BadgeColor.Info" VisuallyHiddenText="Visually hidden text for Info">@item.GroupName</Badge>
</div>
}
<div class="item-time"> <div class="item-time">
<small class="time-text">@item.LastMsgdate</small> <small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small> <small class="time-text">@item.LastMsgtime</small>
@@ -108,6 +121,12 @@
<div class="item-content"> <div class="item-content">
<div class="item-header"> <div class="item-header">
<strong class="item-name">@item.UserFullName</strong> <strong class="item-name">@item.UserFullName</strong>
@if (!string.IsNullOrEmpty(item.GroupName))
{
<div class="mb-3">
<Badge Color="BadgeColor.Info" VisuallyHiddenText="Visually hidden text for Info">@item.GroupName</Badge>
</div>
}
<div class="item-time"> <div class="item-time">
<small class="time-text">@item.LastMsgdate</small> <small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small> <small class="time-text">@item.LastMsgtime</small>

View File

@@ -1,4 +1,5 @@
@page "/UserCP/{CompanyID:int}" @page "/UserCP/{CompanyID:int}"
@page "/UserCP/{CompanyID:int}/{ChatID:int?}"
@using Common.Dtos.Company @using Common.Dtos.Company
@using Common.Dtos.Conversation @using Common.Dtos.Conversation
@using Common.Dtos.Group @using Common.Dtos.Group
@@ -100,7 +101,15 @@
<div class="group-card @(GroupID == group.ID ? "selected" : "")" <div class="group-card @(GroupID == group.ID ? "selected" : "")"
@onclick="() => SelectGroup(group.ID)"> @onclick="() => SelectGroup(group.ID)">
<div class="group-card-content"> <div class="group-card-content">
@if (group.img == null || group.img.Length == 0)
{
<Icon Name="IconName.People" Class="group-icon" /> <Icon Name="IconName.People" Class="group-icon" />
}
else
{
<Image src="@GetImageSource(group.img)" class="rounded mx-2" height="50" width="50" alt="Uploaded Image" />
}
<span class="group-name">@group.Name</span> <span class="group-name">@group.Name</span>
</div> </div>
</div> </div>
@@ -154,6 +163,8 @@
</div> </div>
@code { @code {
[Parameter] public int CompanyID { get; set; } [Parameter] public int CompanyID { get; set; }
[Parameter] public int? ChatID { get; set; }
private bool _shouldObserveVisibility = false; private bool _shouldObserveVisibility = false;
int? GroupID = null; int? GroupID = null;
ReadANDUpdate_CompanyDto? CompanyInfo = new(); ReadANDUpdate_CompanyDto? CompanyInfo = new();
@@ -170,7 +181,12 @@
{ {
if (CompanyInfo == null) return string.Empty; if (CompanyInfo == null) return string.Empty;
string value = $"{CompanyInfo.FullName}"; string value = $"{CompanyInfo.FullName}";
if (LastOpenChat != null) if (GroupID.HasValue)
{
value += "/" + CompanyGroups.FirstOrDefault(f => f.ID == GroupID.GetValueOrDefault()).Name;
}
if (LastOpenChat != null && !string.IsNullOrEmpty(LastOpenChat.ExperFullName))
{ {
value += "/" + LastOpenChat.ExperFullName; value += "/" + LastOpenChat.ExperFullName;
} }
@@ -201,9 +217,13 @@
Question = MsgInput, Question = MsgInput,
UserID = 0 UserID = 0
}); });
if (model != null) LastOpenChat = model; if (model != null)
{
LastOpenChat = model;
}
else toastService.Notify(new ToastMessage(ToastType.Danger, "خطا در گفتگو جدید")); else toastService.Notify(new ToastMessage(ToastType.Danger, "خطا در گفتگو جدید"));
} }
await Task.Yield(); await Task.Yield();
// Scroll to bottom for user's own messages // Scroll to bottom for user's own messages
@@ -269,8 +289,9 @@
{ {
if (CompanyInfo != null) if (CompanyInfo != null)
{ {
// LastOpenChat = await ChatService.GetLastOpenChatInCompany(CompanyID); if (ChatID.HasValue) LastOpenChat = await ChatService.Getchat(ChatID.GetValueOrDefault());
LastOpenChat = null; else LastOpenChat = LastOpenChat = await ChatService.GetLastOpenChatInCompany(CompanyID);
if (LastOpenChat != null) if (LastOpenChat != null)
{ {
@@ -324,6 +345,10 @@
GroupID = groupId; GroupID = groupId;
StateHasChanged(); StateHasChanged();
} }
private string GetImageSource(byte[] bytes)
=> $"data:image/jpeg;base64,{Convert.ToBase64String(bytes)}";
} }
<style> <style>
.chat-bubble { .chat-bubble {

View File

@@ -81,5 +81,13 @@ namespace HushianWebApp.Service
return null; return null;
} }
public async Task<ChatItemDto?> Getchat(int ChatID)
{
var response = await _baseController.Get($"{BaseRoute}User/Chat/{ChatID}");
if (response.StatusCode == System.Net.HttpStatusCode.OK)
return await response.Content.ReadFromJsonAsync<ChatItemDto>();
return null;
}
} }
} }