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 System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -166,22 +167,39 @@ namespace Hushian.Application.Services
ConversationResponses = new List<ConversationResponse>() { new() { Text = dto.Question, Type = type } }
};
var mi = await _ConversationRepository.ADD(conversation);
Response.Value = new ChatItemDto()
{
ID = mi.ID,
ExperID = mi.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
ExperFullName = /*mi.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName*/ "",
GroupID = mi.GroupID,
GroupName = /*mi.Group.Name*/ "",
LastText = mi.ConversationResponses.OrderBy(o => o.ID).Last().Text,
LastMsgdate = mi.Cdatetime.GetDatePersian(),
LastMsgtime = mi.Cdatetime.GetTime(),
LastMsgType = mi.ConversationResponses.OrderBy(o => o.ID).Last().Type,
status = mi.Status,
UserID = mi.UserID,
UserFullName = /*string.IsNullOrEmpty(mi.User.FullName) ? mi.User.Mobile : mi.User.FullName*/ ""
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 = 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();
Response.Success = mi.ID > 0;
}
else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
@@ -305,7 +323,49 @@ namespace Hushian.Application.Services
Response.Value= await _ConversationRepository.Get()
.Include(inc => inc.Group)
.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()
{
ID = s.ID,

View File

@@ -52,6 +52,17 @@ namespace Hushian.WebApi.Controllers.v1
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")]
[Authorize(Roles = "Company,Exper")]

View File

@@ -58,10 +58,17 @@
<div class="item-content">
<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">
<small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small>
</div>
</div>
<div class="item-message">@item.LastText</div>
@@ -82,6 +89,12 @@
<div class="item-content">
<div class="item-header">
<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">
<small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small>
@@ -108,6 +121,12 @@
<div class="item-content">
<div class="item-header">
<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">
<small class="time-text">@item.LastMsgdate</small>
<small class="time-text">@item.LastMsgtime</small>

View File

@@ -1,4 +1,5 @@
@page "/UserCP/{CompanyID:int}"
@page "/UserCP/{CompanyID:int}/{ChatID:int?}"
@using Common.Dtos.Company
@using Common.Dtos.Conversation
@using Common.Dtos.Group
@@ -89,7 +90,7 @@
<p style="margin-top: 15px; font-size: 1.5rem; color: #0d6efd; font-weight: bold; text-shadow: 1px 1px 2px rgba(0,0,0,0.2);">
هوشیان
</p>
@if (CompanyGroups != null && CompanyGroups.Any())
{
<div class="groups-container mt-4">
@@ -97,10 +98,18 @@
<div class="groups-grid">
@foreach (var group in CompanyGroups)
{
<div class="group-card @(GroupID == group.ID ? "selected" : "")"
<div class="group-card @(GroupID == group.ID ? "selected" : "")"
@onclick="() => SelectGroup(group.ID)">
<div class="group-card-content">
<Icon Name="IconName.People" Class="group-icon" />
@if (group.img == null || group.img.Length == 0)
{
<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>
</div>
</div>
@@ -154,6 +163,8 @@
</div>
@code {
[Parameter] public int CompanyID { get; set; }
[Parameter] public int? ChatID { get; set; }
private bool _shouldObserveVisibility = false;
int? GroupID = null;
ReadANDUpdate_CompanyDto? CompanyInfo = new();
@@ -170,7 +181,12 @@
{
if (CompanyInfo == null) return string.Empty;
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;
}
@@ -201,9 +217,13 @@
Question = MsgInput,
UserID = 0
});
if (model != null) LastOpenChat = model;
else toastService.Notify(new ToastMessage(ToastType.Danger, "خطا در گفتگو جدید"));
if (model != null)
{
LastOpenChat = model;
}
else toastService.Notify(new ToastMessage(ToastType.Danger, "خطا در گفتگو جدید"));
}
await Task.Yield();
// Scroll to bottom for user's own messages
@@ -269,8 +289,9 @@
{
if (CompanyInfo != null)
{
// LastOpenChat = await ChatService.GetLastOpenChatInCompany(CompanyID);
LastOpenChat = null;
if (ChatID.HasValue) LastOpenChat = await ChatService.Getchat(ChatID.GetValueOrDefault());
else LastOpenChat = LastOpenChat = await ChatService.GetLastOpenChatInCompany(CompanyID);
if (LastOpenChat != null)
{
@@ -318,12 +339,16 @@
IsLogin = false;
StateHasChanged();
}
async Task SelectGroup(int groupId)
{
GroupID = groupId;
StateHasChanged();
}
private string GetImageSource(byte[] bytes)
=> $"data:image/jpeg;base64,{Convert.ToBase64String(bytes)}";
}
<style>
.chat-bubble {
@@ -891,9 +916,9 @@
color: white;
}
.group-card.selected:hover .group-icon {
color: rgba(255, 255, 255, 0.9);
}
.group-card.selected:hover .group-icon {
color: rgba(255, 255, 255, 0.9);
}
.group-name {
font-weight: 600;
@@ -910,9 +935,9 @@
color: white;
}
.group-card.selected:hover .group-name {
color: rgba(255, 255, 255, 0.9);
}
.group-card.selected:hover .group-name {
color: rgba(255, 255, 255, 0.9);
}
/* Responsive design for group cards */
@@media (max-width: 768px) {
@@ -945,11 +970,11 @@
.group-card {
padding: 0.5rem;
}
.group-icon {
font-size: 1rem;
}
.group-name {
font-size: 0.75rem;
}

View File

@@ -81,5 +81,13 @@ namespace HushianWebApp.Service
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;
}
}
}