...
This commit is contained in:
@@ -4,6 +4,7 @@ using Hushian.Application.Contracts.Persistence;
|
||||
using Hushian.Application.Models;
|
||||
using Hushian.Domain.Entites;
|
||||
using Hushian.WebApi;
|
||||
using Microsoft.AspNetCore.Routing.Constraints;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
@@ -77,7 +78,7 @@ namespace Hushian.Application.Services
|
||||
.Where(w => w.CompanyID == CompanyID && w.Status == status)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
ID = s.ID,
|
||||
ID = s.ID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last(l => l.ExperID.HasValue).ExperID,
|
||||
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last(l => l.ExperID.HasValue).Exper.FullName,
|
||||
GroupID = s.GroupID,
|
||||
@@ -117,7 +118,7 @@ namespace Hushian.Application.Services
|
||||
.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));
|
||||
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,
|
||||
@@ -237,7 +238,7 @@ namespace Hushian.Application.Services
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w => w.ID == dto.ConversationID);
|
||||
|
||||
|
||||
if (convModel != null)
|
||||
{
|
||||
if (ExperID.HasValue && !await _experService.CheckExperInCompany(convModel.CompanyID, ExperID.Value))
|
||||
@@ -277,7 +278,24 @@ namespace Hushian.Application.Services
|
||||
await _ConversationRepository.UPDATE(convModel);
|
||||
}
|
||||
if (dto.Type != ConversationType.UE)
|
||||
await WriteInHubFromCompany(Response.Value, convModel.UserID);
|
||||
await WriteInHubFromCompany(Response.Value, convModel.UserID);
|
||||
else
|
||||
{
|
||||
var modelA = convModel.ConversationResponses.OrderBy(o => o.ID)
|
||||
.LastOrDefault(l => l.Type == ConversationType.EU || l.Type == ConversationType.CU);
|
||||
if (modelA != null)
|
||||
{
|
||||
int userid = 0;
|
||||
|
||||
if (modelA.Type == ConversationType.EU) userid = modelA.ExperID.Value;
|
||||
|
||||
else if (modelA.Type == ConversationType.CU) userid = modelA.conversation.CompanyID;
|
||||
|
||||
await WriteInHubFromUser(Response.Value, userid);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else Response.Errors.Add("گفتگویی یافت نشد");
|
||||
@@ -360,8 +378,23 @@ namespace Hushian.Application.Services
|
||||
{
|
||||
item.IsRead = true;
|
||||
item.ReadDateTime = DateTime.Now;
|
||||
if (!item.ExperID.HasValue)
|
||||
item.ExperID = ExperID;
|
||||
return (await _ConversationResponseRepository.UPDATE(item)) != null;
|
||||
|
||||
|
||||
if( (await _ConversationResponseRepository.UPDATE(item)) != null)
|
||||
{
|
||||
int userID = 0;
|
||||
if (item.Type == ConversationType.EU) userID = item.ExperID.Value;
|
||||
|
||||
else if (item.Type == ConversationType.CU) userID = item.conversation.CompanyID;
|
||||
|
||||
else if (item.Type == ConversationType.UE) userID = item.conversation.UserID;
|
||||
|
||||
await CheckMarkAsReadInHub(item.ID, userID);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +413,7 @@ namespace Hushian.Application.Services
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
ID = s.ID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last(l=>l.ExperID.HasValue).ExperID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last(l => l.ExperID.HasValue).ExperID,
|
||||
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last(l => l.ExperID.HasValue).Exper.FullName,
|
||||
GroupID = s.GroupID,
|
||||
GroupName = s.Group.Name,
|
||||
@@ -451,7 +484,7 @@ namespace Hushian.Application.Services
|
||||
if (Response.Value != null) Response.Success = true;
|
||||
return Response;
|
||||
}
|
||||
public async Task WriteInHubFromCompany(ChatItemResponseDto item,int UserID)
|
||||
public async Task WriteInHubFromCompany(ChatItemResponseDto item, int UserID)
|
||||
{
|
||||
await _hubContext.Clients.User(UserID.ToString())
|
||||
.SendAsync("ReceiveNewChatItemFromCompany", item);
|
||||
@@ -465,19 +498,16 @@ namespace Hushian.Application.Services
|
||||
// // .SendAsync("ReceiveNewConversation", conv.Id, conv.Title);
|
||||
//}
|
||||
}
|
||||
public async Task WriteInHubFromUser(ChatItemResponseDto item)
|
||||
public async Task WriteInHubFromUser(ChatItemResponseDto item, int UserID)
|
||||
{
|
||||
await _hubContext.Clients.User(UserID.ToString())
|
||||
.SendAsync("ReceiveNewChatItemFromCompany", item);
|
||||
|
||||
//// فرض: لیستی از کاربرانی که به گفتگو دسترسی دارند
|
||||
//var usernames = new List<string>();
|
||||
|
||||
//foreach (var usn in usernames)
|
||||
//{
|
||||
// //await _hubContext.Clients.User(usn)
|
||||
// // .SendAsync("ReceiveNewConversation", conv.Id, conv.Title);
|
||||
//}
|
||||
.SendAsync("ReceiveNewChatItemFromUser", item);
|
||||
}
|
||||
public async Task CheckMarkAsReadInHub(int item, int UserID)
|
||||
{
|
||||
await _hubContext.Clients.User(UserID.ToString())
|
||||
.SendAsync("CheckMarkAsRead", item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user