diff --git a/Hushian.Application/Services/ChatService.cs b/Hushian.Application/Services/ChatService.cs index 47f5ea2..73666e7 100644 --- a/Hushian.Application/Services/ChatService.cs +++ b/Hushian.Application/Services/ChatService.cs @@ -285,20 +285,25 @@ namespace Hushian.Application.Services await WriteInHubFromCompany(Response.Value, convModel.UserID.ToString()); else { + List users = new(); + users.Add("C" + convModel.CompanyID.ToString()); + var modelA = convModel.ConversationResponses.OrderBy(o => o.ID) .LastOrDefault(l =>/* l.Type == ConversationType.EU || l.Type == ConversationType.CU*/ l.ExperID.HasValue); - if (modelA != null) - { - string user =""; + if (modelA != null /*&& (modelA.Type == ConversationType.EU || modelA.Type == ConversationType.UE)*/) + // { + - if (modelA.Type == ConversationType.EU || modelA.Type == ConversationType.UE) user = modelA.ExperID.Value.ToString(); + //if () + users.Add(modelA.ExperID.Value.ToString()); - else if (modelA.Type == ConversationType.CU) user ="C"+ modelA.conversation.CompanyID.ToString(); + - await WriteInHubFromUser(Response.Value, user); + - } - else await NewChatInHub(convModel.CompanyID); + // } + //else await NewChatInHub(convModel.CompanyID); + await WriteInHubFromUser(Response.Value, users); } } @@ -502,8 +507,9 @@ namespace Hushian.Application.Services // // .SendAsync("ReceiveNewConversation", conv.Id, conv.Title); //} } - public async Task WriteInHubFromUser(ChatItemResponseDto item, string ToUser) + public async Task WriteInHubFromUser(ChatItemResponseDto item,List< string> ToUserS) { + foreach (var ToUser in ToUserS) await _hubContext.Clients.User(ToUser) .SendAsync("ReceiveNewChatItemFromUser", item); } diff --git a/Presentation/HushianWebApp/Pages/Chat.razor b/Presentation/HushianWebApp/Pages/Chat.razor index 651945b..179ebb3 100644 --- a/Presentation/HushianWebApp/Pages/Chat.razor +++ b/Presentation/HushianWebApp/Pages/Chat.razor @@ -15,6 +15,8 @@ @inject ILocalStorageService localStorageService; @inject HttpClient _Http; @inject NavigationManager nav +@implements IAsyncDisposable + گفتمان @@ -118,9 +120,9 @@ } else { - + } - + @item.LastText @@ -166,9 +168,11 @@
+
@if (ChatCurrent != null) { + @ChatCurrent?.ID)

@SelectedChatUserName

@if (ChatCurrent.status == Common.Enums.ConversationStatus.InProgress) @@ -373,7 +377,7 @@ @code { - + Common.Dtos.CurrentUserInfo CurrentUser { get; set; } List _Group = new List(); //------------------------------------- @@ -386,7 +390,7 @@ ///////////// ChatItemDto? ChatCurrent { get; set; } = null; string MsgInput { get; set; } - IBrowserFile? SelectedImageFile = null; + IBrowserFile? SelectedImageFile = null; byte[]? SelectedImageBytes = null; string? SelectedImagePreview = null; @@ -400,7 +404,7 @@ private DateTime recordingStartTime; bool chatloading = false; - string SelectedChatUserName = "مهدی ربیع نژاد"; + string SelectedChatUserName = ""; private bool _shouldObserveVisibility = false; private ConfirmDialog dialog = default!; private Modal modal = default!; @@ -453,7 +457,7 @@ //NewChat hubConnection.On("NewChat", async (companyid) => { - if (CurrentUser.CompanyID==companyid) + if (CurrentUser.CompanyID==companyid) { Inbox1Items = await chatService.ChatAwaitingOurResponse(); StateHasChanged(); } }); await hubConnection.StartAsync(); @@ -555,7 +559,21 @@ { chatloading = true; - SelectedChatUserName = "در حال گفتگو با " + chatItem.UserFullName; + + SelectedChatUserName = "در حال گفتگو با '" + chatItem.UserFullName + "'"; + + if (CurrentUser.Role == "Company") + { + var mo = chatItem.Responses.OrderBy(o => o.ID).Last(l => l.Type != ConversationType.UE); + if (mo!=null && mo.Type == Common.Enums.ConversationType.EU) + SelectedChatUserName = "گفتگوی '" + mo.ExperName + "' با '" + chatItem.UserFullName+"'"; + + + } + + + + ChatCurrent = chatItem; _shouldObserveVisibility = true; // فعال کن تا در OnAfterRenderAsync صدا زده بشه @@ -766,7 +784,14 @@ SelectedImagePreview = null; return Task.CompletedTask; } - + public async ValueTask DisposeAsync() + { + if (hubConnection is not null) + { + await hubConnection.StopAsync(); + await hubConnection.DisposeAsync(); + } + } }