This commit is contained in:
mmrbnjd
2025-08-03 23:41:54 +03:30
parent 65eeb4694e
commit ba0c513830
4 changed files with 199 additions and 82 deletions

View File

@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Hushian.Application.Services namespace Hushian.Application.Services
{ {
public class ChatService public class ChatService
{ {
private readonly IGenericRepository<Conversation> _ConversationRepository; private readonly IGenericRepository<Conversation> _ConversationRepository;
private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository; private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository;
@@ -55,7 +55,7 @@ namespace Hushian.Application.Services
status = s.Status, status = s.Status,
UserID = s.UserID, UserID = s.UserID,
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName, UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
Responses = s.ConversationResponses.Select(ss=>new ChatItemResponseDto() Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
{ {
ChatItemID = ss.ConversationID, ChatItemID = ss.ConversationID,
ExperID = ss.ExperID, ExperID = ss.ExperID,
@@ -104,40 +104,50 @@ namespace Hushian.Application.Services
}).ToList() }).ToList()
}).ToListAsync(); }).ToListAsync();
public async Task<List<ChatItemDto>> ChatsAwaitingOurResponse(int CompanyID) public async Task<List<ChatItemDto>> ChatsAwaitingOurResponse(int CompanyID, int? ExperID)
=> await _ConversationRepository.Get()
.Include(inc => inc.Group)
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.Status == ConversationStatus.Recorded && w.CompanyID == CompanyID)
.Select(s => new ChatItemDto()
{ {
ID = s.ID, int[]? groupallow = null;
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID, if (ExperID.HasValue)
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, var groups = await _groupService.GetGroupsExper(ExperID.Value);
ExperID = ss.ExperID, if (groups.Count > 0) groupallow = groups.Select(s => s.ID).ToArray();
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()
}).ToListAsync(); var request = _ConversationRepository.Get()
.Include(inc => inc.Group)
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.Status == ConversationStatus.Recorded && w.CompanyID == CompanyID);
if (groupallow != null) request = request.Where(w=>!w.GroupID.HasValue || groupallow.Contains(w.GroupID.Value));
return await request.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()
}).ToListAsync();
}
//------------------------ //------------------------
public async Task<ResponseBase<ChatItemDto>> NewChat(ADD_ConversationDto dto, ConversationType type = ConversationType.UE) public async Task<ResponseBase<ChatItemDto>> NewChat(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
{ {
@@ -167,39 +177,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);
if(mi.ID > 0) if (mi.ID > 0)
Response.Value = await _ConversationRepository.Get() Response.Value = await _ConversationRepository.Get()
.Include(inc => inc.Group).Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper) .Include(inc => inc.Group).Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
.Where(w => w.ID==mi.ID) .Where(w => w.ID == mi.ID)
.Select(s => new ChatItemDto() .Select(s => new ChatItemDto()
{ {
ID = s.ID, ID = s.ID,
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID, ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName, ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
GroupID = s.GroupID, GroupID = s.GroupID,
GroupName = s.Group.Name, GroupName = s.Group.Name,
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text, LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
LastMsgdate = s.Cdatetime.GetDatePersian(), LastMsgdate = s.Cdatetime.GetDatePersian(),
LastMsgtime = s.Cdatetime.GetTime(), LastMsgtime = s.Cdatetime.GetTime(),
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type, LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
status = s.Status, status = s.Status,
UserID = s.UserID, UserID = s.UserID,
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName, UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto() Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
{ {
ChatItemID = ss.ConversationID, ChatItemID = ss.ConversationID,
ExperID = ss.ExperID, ExperID = ss.ExperID,
ExperName = ss.Exper.FullName, ExperName = ss.Exper.FullName,
FileContent = ss.FileContent, FileContent = ss.FileContent,
FileName = ss.FileName, FileName = ss.FileName,
FileType = ss.FileType, FileType = ss.FileType,
ID = ss.ID, ID = ss.ID,
IsRead = ss.IsRead, IsRead = ss.IsRead,
text = ss.Text, text = ss.Text,
Type = ss.Type Type = ss.Type
}).ToList() }).ToList()
}).FirstOrDefaultAsync(); }).FirstOrDefaultAsync();
Response.Success = mi.ID > 0; Response.Success = mi.ID > 0;
} }
else Response.Errors.Add("شناسه گروه صحیح نمی باشد"); else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
@@ -272,11 +282,11 @@ namespace Hushian.Application.Services
return Response; return Response;
} }
public async Task<bool> FinishChat(int ChatID, int CompanyID,int? ExperID) public async Task<bool> FinishChat(int ChatID, int CompanyID, int? ExperID)
{ {
var convModel = await _ConversationRepository.Get() var convModel = await _ConversationRepository.Get()
.Include(inc => inc.ConversationResponses) .Include(inc => inc.ConversationResponses)
.FirstOrDefaultAsync(w => w.ID == ChatID && w.CompanyID==CompanyID); .FirstOrDefaultAsync(w => w.ID == ChatID && w.CompanyID == CompanyID);
if (ExperID.HasValue && !convModel.ConversationResponses.Any(a => a.ExperID == ExperID.Value)) return false; if (ExperID.HasValue && !convModel.ConversationResponses.Any(a => a.ExperID == ExperID.Value)) return false;
if (convModel != null && convModel.Status != ConversationStatus.Finished) if (convModel != null && convModel.Status != ConversationStatus.Finished)
@@ -288,7 +298,7 @@ namespace Hushian.Application.Services
return true; return true;
} }
public async Task<bool> OpenChat(int ChatID, int CompanyID,int? ExperID) public async Task<bool> OpenChat(int ChatID, int CompanyID, int? ExperID)
{ {
var convModel = await _ConversationRepository.Get() var convModel = await _ConversationRepository.Get()
.Include(inc => inc.ConversationResponses) .Include(inc => inc.ConversationResponses)
@@ -322,7 +332,11 @@ namespace Hushian.Application.Services
return true; return true;
} }
public async Task<bool> Attachedto(int ChatID, int? FromExperID, int toExperID, int CompanyID)
{
return false;
}
public async Task<bool> MarkAsReadChatItem(int ID, ConversationType Type, int? ExperID) public async Task<bool> MarkAsReadChatItem(int ID, ConversationType Type, int? ExperID)
{ {
var item = await _ConversationResponseRepository.Get() var item = await _ConversationResponseRepository.Get()
@@ -352,14 +366,14 @@ namespace Hushian.Application.Services
} }
return false; return false;
} }
public async Task<ResponseBase<ChatItemDto>> GetLastOpenChatInCompany(int CompanyID,int UserID) public async Task<ResponseBase<ChatItemDto>> GetLastOpenChatInCompany(int CompanyID, int UserID)
{ {
ResponseBase<ChatItemDto> Response = new(); ResponseBase<ChatItemDto> Response = new();
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.CompanyID==CompanyID && w.Status != ConversationStatus.Finished) .Where(w => w.UserID == UserID && w.CompanyID == CompanyID && w.Status != ConversationStatus.Finished)
.OrderByDescending(o=>o.ID) .OrderByDescending(o => o.ID)
.Select(s => new ChatItemDto() .Select(s => new ChatItemDto()
{ {
ID = s.ID, ID = s.ID,
@@ -399,7 +413,7 @@ 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.ID == ChatID ) .Where(w => w.UserID == UserID && w.ID == ChatID)
.OrderByDescending(o => o.ID) .OrderByDescending(o => o.ID)
.Select(s => new ChatItemDto() .Select(s => new ChatItemDto()
{ {

View File

@@ -69,12 +69,13 @@ namespace Hushian.WebApi.Controllers.v1
public async Task<ActionResult> ChatsAwaitingOurResponse() public async Task<ActionResult> ChatsAwaitingOurResponse()
{ {
int CompanyID = 0; int CompanyID = 0;
int? ExperID = null;
if (User.IsInRole("Exper")) if (User.IsInRole("Exper"))
{ {
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First(); string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int ExperID = Convert.ToInt32(strExperID); ExperID = Convert.ToInt32(strExperID);
CompanyID = await _experService.GetCompanyIDExper(ExperID); CompanyID = await _experService.GetCompanyIDExper(ExperID.Value);
} }
else if (User.IsInRole("Company")) else if (User.IsInRole("Company"))
{ {
@@ -82,9 +83,31 @@ namespace Hushian.WebApi.Controllers.v1
CompanyID = Convert.ToInt32(strCompanyID); CompanyID = Convert.ToInt32(strCompanyID);
} }
var response = await _chatService.ChatsAwaitingOurResponse(CompanyID); var response = await _chatService.ChatsAwaitingOurResponse(CompanyID,ExperID);
return Ok(response); return Ok(response);
} }
[HttpPut("Attached-to/{toExperID}/{ChatID}")]
[Authorize(Roles = "Company,Exper")]
public async Task<ActionResult> Attachedto(int toExperID,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.Value);
}
else if (User.IsInRole("Company"))
{
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
CompanyID = Convert.ToInt32(strCompanyID);
}
var response = await _chatService.Attachedto(ChatID, ExperID,toExperID,CompanyID);
return response ?NoContent(): BadRequest(new List<string> { "خطا در بروزرسانی وضعیت" });
}
[HttpPost("NewChatFromCurrentUser")] [HttpPost("NewChatFromCurrentUser")]
public async Task<ActionResult> NewChatFromCurrentUser(ADD_ConversationDto conversation) public async Task<ActionResult> NewChatFromCurrentUser(ADD_ConversationDto conversation)
{ {

View File

@@ -26,8 +26,8 @@
<!-- A2: Buttons --> <!-- A2: Buttons -->
<div class="sidebar-tabs" id="A2"> <div class="sidebar-tabs" id="A2">
<!-- Inbox1 --> <!-- Inbox1 -->
<Button Outline="@isSelectedInbox1" Type="ButtonType.Link" @onclick="async()=>{await OnclickInbox(1);}" Size=ButtonSize.Small Color="ButtonColor.Primary" <Button Outline="@isSelectedInbox1" Type="ButtonType.Link" @onclick="async()=>{await OnclickInbox(1);}" Size=ButtonSize.Small Color="ButtonColor.Warning"
class=@($"tab-button {(isSelectedInbox1 ? "active-tab" : "")}")> class=@($"tab-button inbox1-button {(isSelectedInbox1 ? "active-tab inbox1-active" : "")}")>
<Icon Name="IconName.Inbox" Class="tab-icon" /> <Icon Name="IconName.Inbox" Class="tab-icon" />
<span class="tab-text">پیام های آمده</span> <span class="tab-text">پیام های آمده</span>
<Badge Color="BadgeColor.Warning" Class="tab-badge">@Inbox1Items.Count()</Badge> <Badge Color="BadgeColor.Warning" Class="tab-badge">@Inbox1Items.Count()</Badge>
@@ -35,15 +35,15 @@
<!-- Inbox2 --> <!-- Inbox2 -->
<Button Outline="@isSelectedInbox2" Type="ButtonType.Link" @onclick="async()=>{await OnclickInbox(2);}" Size=ButtonSize.Small Color="ButtonColor.Primary" <Button Outline="@isSelectedInbox2" Type="ButtonType.Link" @onclick="async()=>{await OnclickInbox(2);}" Size=ButtonSize.Small Color="ButtonColor.Primary"
class=@($"tab-button {(isSelectedInbox2 ? "active-tab" : "")}")> class=@($"tab-button inbox2-button {(isSelectedInbox2 ? "active-tab inbox2-active" : "")}")>
<Icon Name="IconName.Send" Class="tab-icon" /> <Icon Name="IconName.Send" Class="tab-icon" />
<span class="tab-text">پیام های من</span> <span class="tab-text">پیام های من</span>
<Badge Color="BadgeColor.Warning" Class="tab-badge">@Inbox2Items.Count()</Badge> <Badge Color="BadgeColor.Warning" Class="tab-badge">@Inbox2Items.Count()</Badge>
</Button> </Button>
<!-- Inbox3 --> <!-- Inbox3 -->
<Button Outline="@isSelectedInbox3" Type="ButtonType.Link" @onclick="async()=>{await OnclickInbox(3);}" Size=ButtonSize.Small Color="ButtonColor.Primary" <Button Outline="@isSelectedInbox3" Type="ButtonType.Link" @onclick="async()=>{await OnclickInbox(3);}" Size=ButtonSize.Small Color="ButtonColor.Danger"
class=@($"tab-button {(isSelectedInbox3 ? "active-tab" : "")}")> class=@($"tab-button inbox3-button {(isSelectedInbox3 ? "active-tab inbox3-active" : "")}")>
<Icon Name="IconName.Archive" Class="tab-icon" /> <Icon Name="IconName.Archive" Class="tab-icon" />
<span class="tab-text">پیام های بسته</span> <span class="tab-text">پیام های بسته</span>
</Button> </Button>
@@ -159,7 +159,7 @@
</Button> </Button>
<Button Color="ButtonColor.Secondary" Size=ButtonSize.ExtraSmall Outline="true" Class="toexper-btn"> <Button Color="ButtonColor.Secondary" Size=ButtonSize.ExtraSmall Outline="true" Class="toexper-btn">
<Icon Name="IconName.EnvelopeArrowUp" /> ارجاع به... <Icon Name="IconName.EnvelopeArrowUp" /> پیوست به...
</Button> </Button>
} }
else if (ChatCurrent.status == Common.Enums.ConversationStatus.Finished else if (ChatCurrent.status == Common.Enums.ConversationStatus.Finished
@@ -520,6 +520,81 @@
box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3); box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
} }
/* Smaller tab buttons */
.tab-button {
padding: 0.5rem 0.75rem;
font-size: 0.8rem;
border-radius: 10px;
}
.tab-text {
font-size: 0.8rem;
}
.tab-icon {
font-size: 0.9rem;
}
/* Inbox1 - Yellow theme */
.inbox1-button {
border-color: #ffc107;
color: #856404;
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
}
.inbox1-button:hover {
border-color: #e0a800;
background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
color: #856404;
}
.inbox1-active {
background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%) !important;
color: #212529 !important;
border-color: #ffc107 !important;
box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3) !important;
}
/* Inbox2 - Blue theme */
.inbox2-button {
border-color: #0d6efd;
color: #0d6efd;
background: linear-gradient(135deg, #e7f1ff 0%, #cce7ff 100%);
}
.inbox2-button:hover {
border-color: #0b5ed7;
background: linear-gradient(135deg, #cce7ff 0%, #b3d9ff 100%);
color: #0b5ed7;
}
.inbox2-active {
background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%) !important;
color: white !important;
border-color: #0d6efd !important;
box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3) !important;
}
/* Inbox3 - Red theme */
.inbox3-button {
border-color: #dc3545;
color: #721c24;
background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
}
.inbox3-button:hover {
border-color: #c82333;
background: linear-gradient(135deg, #f5c6cb 0%, #f1b0b7 100%);
color: #721c24;
}
.inbox3-active {
background: linear-gradient(135deg, #dc3545 0%, #c82333 100%) !important;
color: white !important;
border-color: #dc3545 !important;
box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3) !important;
}
.tab-icon { .tab-icon {
margin-right: 0.5rem; margin-right: 0.5rem;
font-size: 1.1rem; font-size: 1.1rem;

View File

@@ -73,6 +73,11 @@ namespace HushianWebApp.Service
var response = await _baseController.Put($"{BaseRoute}ChatIsFinish/{ChatID}"); var response = await _baseController.Put($"{BaseRoute}ChatIsFinish/{ChatID}");
return response.IsSuccessStatusCode; return response.IsSuccessStatusCode;
} }
public async Task<bool> Attachedto(int toExperID, int ChatID)
{
var response = await _baseController.Put($"{BaseRoute}Attached-to/{toExperID}/{ChatID}");
return response.IsSuccessStatusCode;
}
public async Task<bool> ChatIsFinishFromUser(int ChatID) public async Task<bool> ChatIsFinishFromUser(int ChatID)
{ {
var response = await _baseController.Put($"{BaseRoute}ChatIsFinishFromUser/{ChatID}"); var response = await _baseController.Put($"{BaseRoute}ChatIsFinishFromUser/{ChatID}");