This commit is contained in:
mmrbnjd
2025-08-07 22:41:22 +03:30
parent d153c4bde0
commit 0736632a59
5 changed files with 67 additions and 4 deletions

View File

@@ -5,6 +5,9 @@
@using Common.Dtos.Group
@using HushianWebApp.Service
@using HushianWebApp.Services
@using Microsoft.AspNetCore.SignalR.Client;
@inject NavigationManager NavigationManager
@inject ChatService ChatService
@inject ILocalStorageService localStorageService;
@inject AuthService authService;
@@ -173,7 +176,7 @@
[Parameter] public int CompanyID { get; set; }
[Parameter] public int? ChatID { get; set; }
private ConfirmDialog dialog = default!;
private HubConnection? hubConnection;
private bool _shouldObserveVisibility = false;
int? GroupID = null;
ReadANDUpdate_CompanyDto? CompanyInfo = new();
@@ -259,7 +262,34 @@
}
protected override async Task OnInitializedAsync()
{
Console.WriteLine($"🔔 welcome");
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();
}
async Task IsOnline()
@@ -336,7 +366,6 @@
}
await Task.CompletedTask;
}
// Method to handle new messages from other users
public async Task HandleNewMessage()
{

View File

@@ -119,6 +119,8 @@
public int? SelectedGroup { get; set; }
public string InputMessage { get; set; }
public bool Sending { get; set; } = false;
#endregion
}
@functions {