This commit is contained in:
mmrbnjd
2025-08-08 18:10:25 +03:30
parent 0736632a59
commit f6013e482b
5 changed files with 242 additions and 148 deletions

View File

@@ -18,6 +18,7 @@
@inject ChatService chatService
@inject IJSRuntime JS
@inject ToastService toastService
@inject HttpClient _Http;
@layout UserPanelLayout
<ConfirmDialog @ref="dialog" />
@@ -262,14 +263,14 @@
}
protected override async Task OnInitializedAsync()
{
Console.WriteLine($"🔔 welcome");
await IsOnline();
//-------------hub
var token = await localStorageService.GetItem<string>("U/key");
string AddressHub = _Http.BaseAddress.AbsoluteUri.Replace("api/", "");
hubConnection = new HubConnectionBuilder()
.WithUrl("http://localhost:5089/chatNotificationHub", options =>
.WithUrl($"{AddressHub}chatNotificationHub", options =>
{
options.AccessTokenProvider = () => Task.FromResult(token);
})
@@ -282,11 +283,20 @@
{
LastOpenChat.Responses.Add(chatitem);
StateHasChanged();
await MarkAsRead(chatitem.ID);
await MarkAsRead(chatitem.ID);
// Scroll to target if exists, otherwise scroll to bottom
await JS.InvokeVoidAsync("scrollToTargetOrBottom");
}
});
//-------------------------------------
hubConnection.On<int>("CheckMarkAsRead", async (chatresponseid) =>
{
if (LastOpenChat.Responses.Any(a=>a.ID==chatresponseid && !a.IsRead && a.Type==Common.Enums.ConversationType.UE))
{
LastOpenChat.Responses.First(a => a.ID == chatresponseid).IsRead = true;
StateHasChanged();
}
});
await hubConnection.StartAsync();
//---------end hub