forked from ddrilling/AsbCloudServer
Степанов Дмитрий Александрович
83ee280fbb
1. Поменял время жизни для отправителей уведомлений. 2. Добавил метод в контроллере для получения уведомления по Id. 3. Поправил хаб уведомлений 4. Небольшие фиксы в репозитории и сервисах
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services.Notifications;
|
|
using AsbCloudWebApi.SignalR.ConnectionManager;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace AsbCloudWebApi.SignalR;
|
|
|
|
[Authorize]
|
|
public class NotificationHub : BaseHub
|
|
{
|
|
private readonly IConnectionManager connectionManager;
|
|
private readonly INotificationService notificationService;
|
|
|
|
public NotificationHub(IConnectionManager connectionManager,
|
|
INotificationService notificationService)
|
|
{
|
|
this.connectionManager = connectionManager;
|
|
this.notificationService = notificationService;
|
|
}
|
|
|
|
public async Task OnConnected(int idUser)
|
|
{
|
|
try
|
|
{
|
|
string connectionId = Context.ConnectionId;
|
|
|
|
connectionManager.AddConnection(idUser, connectionId);
|
|
|
|
await notificationService.ResendNotificationAsync(idUser,
|
|
NotificationTransport.SignalR,
|
|
CancellationToken.None);
|
|
|
|
await base.OnConnectedAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public Task OnDisconnected(int idUser)
|
|
{
|
|
connectionManager.RemoveConnection(idUser);
|
|
|
|
return base.OnDisconnectedAsync(null);
|
|
}
|
|
} |