...
This commit is contained in:
@@ -5,6 +5,6 @@ namespace Common.Contracts.Infrastructure
|
|||||||
{
|
{
|
||||||
public interface IMessageSender
|
public interface IMessageSender
|
||||||
{
|
{
|
||||||
Task<bool> SendMassage(Message message);
|
Task<bool> SendMessageVerification(string To, string Code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,12 @@ namespace Hushian.Application.Models.Message
|
|||||||
{
|
{
|
||||||
public class Message
|
public class Message
|
||||||
{
|
{
|
||||||
|
public Message(string to, string msg)
|
||||||
|
{
|
||||||
|
To = to;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
public string To { get; set; }
|
public string To { get; set; }
|
||||||
public string msg { get; set; }
|
public string msg { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ using Hushian.Application.Contracts.Persistence;
|
|||||||
using Hushian.Application.Models;
|
using Hushian.Application.Models;
|
||||||
using Hushian.Domain.Entites;
|
using Hushian.Domain.Entites;
|
||||||
using Hushian.WebApi;
|
using Hushian.WebApi;
|
||||||
|
using Microsoft.AspNetCore.Components.Routing;
|
||||||
using Microsoft.AspNetCore.Routing.Constraints;
|
using Microsoft.AspNetCore.Routing.Constraints;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -280,20 +281,20 @@ namespace Hushian.Application.Services
|
|||||||
await _ConversationRepository.UPDATE(convModel);
|
await _ConversationRepository.UPDATE(convModel);
|
||||||
}
|
}
|
||||||
if (dto.Type != ConversationType.UE)
|
if (dto.Type != ConversationType.UE)
|
||||||
await WriteInHubFromCompany(Response.Value, convModel.UserID);
|
await WriteInHubFromCompany(Response.Value, "U"+convModel.UserID);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var modelA = convModel.ConversationResponses.OrderBy(o => o.ID)
|
var modelA = convModel.ConversationResponses.OrderBy(o => o.ID)
|
||||||
.LastOrDefault(l => l.Type == ConversationType.EU || l.Type == ConversationType.CU);
|
.LastOrDefault(l => l.Type == ConversationType.EU || l.Type == ConversationType.CU);
|
||||||
if (modelA != null)
|
if (modelA != null)
|
||||||
{
|
{
|
||||||
int userid = 0;
|
string user ="";
|
||||||
|
|
||||||
if (modelA.Type == ConversationType.EU) userid = modelA.ExperID.Value;
|
if (modelA.Type == ConversationType.EU) user = modelA.ExperID.Value.ToString();
|
||||||
|
|
||||||
else if (modelA.Type == ConversationType.CU) userid = modelA.conversation.CompanyID;
|
else if (modelA.Type == ConversationType.CU) user = "C"+modelA.conversation.CompanyID;
|
||||||
|
|
||||||
await WriteInHubFromUser(Response.Value, userid);
|
await WriteInHubFromUser(Response.Value, user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,14 +387,14 @@ namespace Hushian.Application.Services
|
|||||||
|
|
||||||
if( (await _ConversationResponseRepository.UPDATE(item)) != null)
|
if( (await _ConversationResponseRepository.UPDATE(item)) != null)
|
||||||
{
|
{
|
||||||
int userID = 0;
|
string user = "";
|
||||||
if (item.Type == ConversationType.EU) userID = item.ExperID.Value;
|
if (item.Type == ConversationType.EU) user = item.ExperID.Value.ToString();
|
||||||
|
|
||||||
else if (item.Type == ConversationType.CU) userID = item.conversation.CompanyID;
|
else if (item.Type == ConversationType.CU) user = "C" + item.conversation.CompanyID;
|
||||||
|
|
||||||
else if (item.Type == ConversationType.UE) userID = item.conversation.UserID;
|
else if (item.Type == ConversationType.UE) user = "U"+ item.conversation.UserID;
|
||||||
|
|
||||||
await CheckMarkAsReadInHub(item.ID, userID);
|
await CheckMarkAsReadInHub(item.ID, user);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -486,9 +487,9 @@ namespace Hushian.Application.Services
|
|||||||
if (Response.Value != null) Response.Success = true;
|
if (Response.Value != null) Response.Success = true;
|
||||||
return Response;
|
return Response;
|
||||||
}
|
}
|
||||||
public async Task WriteInHubFromCompany(ChatItemResponseDto item, int UserID)
|
public async Task WriteInHubFromCompany(ChatItemResponseDto item, string ToUser)
|
||||||
{
|
{
|
||||||
await _hubContext.Clients.User(UserID.ToString())
|
await _hubContext.Clients.User(ToUser)
|
||||||
.SendAsync("ReceiveNewChatItemFromCompany", item);
|
.SendAsync("ReceiveNewChatItemFromCompany", item);
|
||||||
|
|
||||||
//// فرض: لیستی از کاربرانی که به گفتگو دسترسی دارند
|
//// فرض: لیستی از کاربرانی که به گفتگو دسترسی دارند
|
||||||
@@ -500,14 +501,14 @@ namespace Hushian.Application.Services
|
|||||||
// // .SendAsync("ReceiveNewConversation", conv.Id, conv.Title);
|
// // .SendAsync("ReceiveNewConversation", conv.Id, conv.Title);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
public async Task WriteInHubFromUser(ChatItemResponseDto item, int UserID)
|
public async Task WriteInHubFromUser(ChatItemResponseDto item, string ToUser)
|
||||||
{
|
{
|
||||||
await _hubContext.Clients.User(UserID.ToString())
|
await _hubContext.Clients.User(ToUser)
|
||||||
.SendAsync("ReceiveNewChatItemFromUser", item);
|
.SendAsync("ReceiveNewChatItemFromUser", item);
|
||||||
}
|
}
|
||||||
public async Task CheckMarkAsReadInHub(int item, int UserID)
|
public async Task CheckMarkAsReadInHub(int item, string ToUser)
|
||||||
{
|
{
|
||||||
await _hubContext.Clients.User(UserID.ToString())
|
await _hubContext.Clients.User(ToUser)
|
||||||
.SendAsync("CheckMarkAsRead", item);
|
.SendAsync("CheckMarkAsRead", item);
|
||||||
}
|
}
|
||||||
public async Task NewChatInHub(int CompanyID)
|
public async Task NewChatInHub(int CompanyID)
|
||||||
|
@@ -27,7 +27,10 @@ namespace Hushian.Application.Services
|
|||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
new Claim(JwtRegisteredClaimNames.Sub,userId.ToString()),
|
new Claim(JwtRegisteredClaimNames.Sub,
|
||||||
|
Role=="User" ? "U"+userId.ToString()
|
||||||
|
:Role=="Company" ? "C"+userId.ToString()
|
||||||
|
:userId.ToString()),
|
||||||
new Claim(ClaimTypes.NameIdentifier, UserName),
|
new Claim(ClaimTypes.NameIdentifier, UserName),
|
||||||
new Claim(CustomClaimTypes.Uid,userId.ToString()),
|
new Claim(CustomClaimTypes.Uid,userId.ToString()),
|
||||||
new Claim(ClaimTypes.Role, Role)
|
new Claim(ClaimTypes.Role, Role)
|
||||||
|
@@ -45,11 +45,7 @@ namespace Hushian.Application.Services
|
|||||||
string Code = await GenerateCode();
|
string Code = await GenerateCode();
|
||||||
var response= await _VerificationCodeRepository.ADD
|
var response= await _VerificationCodeRepository.ADD
|
||||||
(new Identity.Models.VerificationCode(VerificationCodeType.Login, Code, Mobile));
|
(new Identity.Models.VerificationCode(VerificationCodeType.Login, Code, Mobile));
|
||||||
await _messageSender.SendMassage(new Models.Message.Message()
|
await _messageSender.SendMessageVerification(Mobile, Code);
|
||||||
{
|
|
||||||
msg = Code,
|
|
||||||
To = Mobile
|
|
||||||
});
|
|
||||||
return response.ID;
|
return response.ID;
|
||||||
}
|
}
|
||||||
public async Task<int> GenerateCodeByPhoneNumberConfirmed(string Mobile)
|
public async Task<int> GenerateCodeByPhoneNumberConfirmed(string Mobile)
|
||||||
@@ -57,11 +53,7 @@ namespace Hushian.Application.Services
|
|||||||
string Code = await GenerateCode();
|
string Code = await GenerateCode();
|
||||||
var response = await _VerificationCodeRepository.ADD
|
var response = await _VerificationCodeRepository.ADD
|
||||||
(new Identity.Models.VerificationCode(VerificationCodeType.PhoneNumberConfirmed, Code, Mobile));
|
(new Identity.Models.VerificationCode(VerificationCodeType.PhoneNumberConfirmed, Code, Mobile));
|
||||||
await _messageSender.SendMassage(new Models.Message.Message()
|
await _messageSender.SendMessageVerification(Mobile, Code);
|
||||||
{
|
|
||||||
msg = Code,
|
|
||||||
To = Mobile
|
|
||||||
});
|
|
||||||
return response.ID;
|
return response.ID;
|
||||||
}
|
}
|
||||||
public async Task<int> GenerateCodeByForgetPassword(string Mobile)
|
public async Task<int> GenerateCodeByForgetPassword(string Mobile)
|
||||||
@@ -69,11 +61,7 @@ namespace Hushian.Application.Services
|
|||||||
string Code = await GenerateCode();
|
string Code = await GenerateCode();
|
||||||
var response = await _VerificationCodeRepository.ADD
|
var response = await _VerificationCodeRepository.ADD
|
||||||
(new Identity.Models.VerificationCode(VerificationCodeType.ForgetPassword, Code, Mobile));
|
(new Identity.Models.VerificationCode(VerificationCodeType.ForgetPassword, Code, Mobile));
|
||||||
await _messageSender.SendMassage(new Models.Message.Message()
|
await _messageSender.SendMessageVerification(Mobile, Code);
|
||||||
{
|
|
||||||
msg = Code,
|
|
||||||
To = Mobile
|
|
||||||
});
|
|
||||||
return response.ID;
|
return response.ID;
|
||||||
}
|
}
|
||||||
public async Task<ResponseBase<AuthResponse>> VerificationCode(ConfirmedCodeDto model)
|
public async Task<ResponseBase<AuthResponse>> VerificationCode(ConfirmedCodeDto model)
|
||||||
@@ -193,11 +181,7 @@ namespace Hushian.Application.Services
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return await _messageSender.SendMassage(new Models.Message.Message()
|
return await _messageSender.SendMessageVerification(model.Mobile, model.Code);
|
||||||
{
|
|
||||||
msg = model.Code,
|
|
||||||
To = model.Mobile
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async Task<string> GenerateCode()
|
private async Task<string> GenerateCode()
|
||||||
|
@@ -14,11 +14,14 @@ namespace Hushian.Infrastructure
|
|||||||
_restClient = restClient;
|
_restClient = restClient;
|
||||||
_msgSettings = msgSettings.Value;
|
_msgSettings = msgSettings.Value;
|
||||||
}
|
}
|
||||||
|
public async Task<bool> SendMessageVerification(string To,string Code)
|
||||||
public Task<bool> SendMassage(Message message)
|
{
|
||||||
|
return await SendMassage(new Message(To,$"برای ادامه از کد {Code} استفاده کنید"));
|
||||||
|
}
|
||||||
|
private Task<bool> SendMassage(Message message)
|
||||||
{
|
{
|
||||||
string From = _msgSettings.From;
|
string From = _msgSettings.From;
|
||||||
// _restClient.Send(message.To, From, message.msg, false);
|
_restClient.Send(message.To, From, message.msg, false);
|
||||||
return Task.Run(()=>true);
|
return Task.Run(()=>true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,10 @@
|
|||||||
@using HushianWebApp.Services
|
@using HushianWebApp.Services
|
||||||
@using Microsoft.AspNetCore.SignalR.Client;
|
@using Microsoft.AspNetCore.SignalR.Client;
|
||||||
@using System.Threading;
|
@using System.Threading;
|
||||||
<PageTitle>گفتگو با @CompanyInfo.FullName</PageTitle>
|
@if(CompanyInfo!=null)
|
||||||
|
{
|
||||||
|
<PageTitle>گفتگو با @CompanyInfo?.FullName</PageTitle>
|
||||||
|
}
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject ChatService ChatService
|
@inject ChatService ChatService
|
||||||
@inject ILocalStorageService localStorageService;
|
@inject ILocalStorageService localStorageService;
|
||||||
@@ -131,12 +134,12 @@
|
|||||||
هوشیان
|
هوشیان
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@if (CompanyGroups != null && CompanyGroups.Any())
|
@if (CompanyGroups != null && CompanyGroups.Any(w => w.Available))
|
||||||
{
|
{
|
||||||
<div class="groups-container mt-4">
|
<div class="groups-container mt-4">
|
||||||
<h6 class="text-center mb-3 text-muted">انتخاب گروه:</h6>
|
<h6 class="text-center mb-3 text-muted">انتخاب گروه:</h6>
|
||||||
<div class="groups-grid">
|
<div class="groups-grid">
|
||||||
@foreach (var group in CompanyGroups)
|
@foreach (var group in CompanyGroups.Where(w=>w.Available))
|
||||||
{
|
{
|
||||||
<div class="group-card @(GroupID == group.ID ? "selected" : "")"
|
<div class="group-card @(GroupID == group.ID ? "selected" : "")"
|
||||||
@onclick="() => SelectGroup(group.ID)">
|
@onclick="() => SelectGroup(group.ID)">
|
||||||
@@ -162,7 +165,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (LastOpenChat == null || (LastOpenChat != null && LastOpenChat.status != Common.Enums.ConversationStatus.Finished && LastOpenChat.Responses != null))
|
@if (CompanyInfo != null && (LastOpenChat == null || (LastOpenChat != null && LastOpenChat.status != Common.Enums.ConversationStatus.Finished && LastOpenChat.Responses != null)))
|
||||||
{
|
{
|
||||||
<!-- B2: Message input -->
|
<!-- B2: Message input -->
|
||||||
<div class="message-input-container" id="B2">
|
<div class="message-input-container" id="B2">
|
||||||
@@ -270,7 +273,7 @@
|
|||||||
ReadANDUpdate_CompanyDto? CompanyInfo = new();
|
ReadANDUpdate_CompanyDto? CompanyInfo = new();
|
||||||
Common.Dtos.CurrentUserInfo CurrentUser = new();
|
Common.Dtos.CurrentUserInfo CurrentUser = new();
|
||||||
List<Read_GroupDto> CompanyGroups = new();
|
List<Read_GroupDto> CompanyGroups = new();
|
||||||
ChatItemDto? LastOpenChat = new();
|
ChatItemDto? LastOpenChat = null;
|
||||||
string MsgInput = string.Empty;
|
string MsgInput = string.Empty;
|
||||||
IBrowserFile? SelectedImageFile = null;
|
IBrowserFile? SelectedImageFile = null;
|
||||||
byte[]? SelectedImageBytes = null;
|
byte[]? SelectedImageBytes = null;
|
||||||
@@ -566,8 +569,8 @@
|
|||||||
{
|
{
|
||||||
CompanyInfo = await companyService.GetCompany(CompanyID);
|
CompanyInfo = await companyService.GetCompany(CompanyID);
|
||||||
if (CompanyInfo != null)
|
if (CompanyInfo != null)
|
||||||
CompanyGroups = await groupService.GetGroupsCompany(CompanyID);
|
{ CompanyGroups = await groupService.GetGroupsCompany(CompanyID);
|
||||||
await IsLastChat();
|
await IsLastChat();}
|
||||||
}
|
}
|
||||||
async Task IsLastChat()
|
async Task IsLastChat()
|
||||||
{
|
{
|
||||||
@@ -594,6 +597,7 @@
|
|||||||
[JSInvokable]
|
[JSInvokable]
|
||||||
public async Task MarkAsRead(int id)
|
public async Task MarkAsRead(int id)
|
||||||
{
|
{
|
||||||
|
if (LastOpenChat == null) return;
|
||||||
var msg = LastOpenChat.Responses.FirstOrDefault(m => m.ID == id);
|
var msg = LastOpenChat.Responses.FirstOrDefault(m => m.ID == id);
|
||||||
if (msg != null && !msg.IsRead && msg.Type != Common.Enums.ConversationType.UE)
|
if (msg != null && !msg.IsRead && msg.Type != Common.Enums.ConversationType.UE)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user