...
This commit is contained in:
@@ -276,6 +276,9 @@ namespace Hushian.Application.Services
|
|||||||
convModel.Status = ConversationStatus.InProgress;
|
convModel.Status = ConversationStatus.InProgress;
|
||||||
await _ConversationRepository.UPDATE(convModel);
|
await _ConversationRepository.UPDATE(convModel);
|
||||||
}
|
}
|
||||||
|
if (dto.Type != ConversationType.UE)
|
||||||
|
await WriteInHubFromCompany(Response.Value, convModel.UserID);
|
||||||
|
|
||||||
}
|
}
|
||||||
else Response.Errors.Add("گفتگویی یافت نشد");
|
else Response.Errors.Add("گفتگویی یافت نشد");
|
||||||
}
|
}
|
||||||
@@ -448,5 +451,33 @@ 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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
public async Task WriteInHubFromUser(ChatItemResponseDto item)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
//}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@ namespace Hushian.Application.Services
|
|||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
new Claim(JwtRegisteredClaimNames.Sub,UserName),
|
new Claim(JwtRegisteredClaimNames.Sub,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)
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
<PackageReference Include="Blazor.Bootstrap" Version="3.3.1" />
|
<PackageReference Include="Blazor.Bootstrap" Version="3.3.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.2" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.2" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.8" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
@using Common.Dtos.Group
|
@using Common.Dtos.Group
|
||||||
@using HushianWebApp.Service
|
@using HushianWebApp.Service
|
||||||
@using HushianWebApp.Services
|
@using HushianWebApp.Services
|
||||||
|
@using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
@inject ChatService ChatService
|
@inject ChatService ChatService
|
||||||
@inject ILocalStorageService localStorageService;
|
@inject ILocalStorageService localStorageService;
|
||||||
@inject AuthService authService;
|
@inject AuthService authService;
|
||||||
@@ -173,7 +176,7 @@
|
|||||||
[Parameter] public int CompanyID { get; set; }
|
[Parameter] public int CompanyID { get; set; }
|
||||||
[Parameter] public int? ChatID { get; set; }
|
[Parameter] public int? ChatID { get; set; }
|
||||||
private ConfirmDialog dialog = default!;
|
private ConfirmDialog dialog = default!;
|
||||||
|
private HubConnection? hubConnection;
|
||||||
private bool _shouldObserveVisibility = false;
|
private bool _shouldObserveVisibility = false;
|
||||||
int? GroupID = null;
|
int? GroupID = null;
|
||||||
ReadANDUpdate_CompanyDto? CompanyInfo = new();
|
ReadANDUpdate_CompanyDto? CompanyInfo = new();
|
||||||
@@ -259,7 +262,34 @@
|
|||||||
}
|
}
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"🔔 welcome");
|
||||||
|
|
||||||
await IsOnline();
|
await IsOnline();
|
||||||
|
//-------------hub
|
||||||
|
var token = await localStorageService.GetItem<string>("U/key");
|
||||||
|
|
||||||
|
hubConnection = new HubConnectionBuilder()
|
||||||
|
.WithUrl("http://localhost:5089/chatNotificationHub", options =>
|
||||||
|
{
|
||||||
|
options.AccessTokenProvider = () => Task.FromResult(token);
|
||||||
|
})
|
||||||
|
.WithAutomaticReconnect()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
hubConnection.On<ChatItemResponseDto>("ReceiveNewChatItemFromCompany",async (chatitem) =>
|
||||||
|
{
|
||||||
|
if (LastOpenChat.ID == chatitem.ChatItemID)
|
||||||
|
{
|
||||||
|
LastOpenChat.Responses.Add(chatitem);
|
||||||
|
StateHasChanged();
|
||||||
|
await MarkAsRead(chatitem.ID);
|
||||||
|
// Scroll to target if exists, otherwise scroll to bottom
|
||||||
|
await JS.InvokeVoidAsync("scrollToTargetOrBottom");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await hubConnection.StartAsync();
|
||||||
|
//---------end hub
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
async Task IsOnline()
|
async Task IsOnline()
|
||||||
@@ -336,7 +366,6 @@
|
|||||||
}
|
}
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to handle new messages from other users
|
// Method to handle new messages from other users
|
||||||
public async Task HandleNewMessage()
|
public async Task HandleNewMessage()
|
||||||
{
|
{
|
||||||
|
@@ -119,6 +119,8 @@
|
|||||||
public int? SelectedGroup { get; set; }
|
public int? SelectedGroup { get; set; }
|
||||||
public string InputMessage { get; set; }
|
public string InputMessage { get; set; }
|
||||||
public bool Sending { get; set; } = false;
|
public bool Sending { get; set; } = false;
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@functions {
|
@functions {
|
||||||
|
Reference in New Issue
Block a user