sledgemapper/Sledgemapper.Api/Handlers/SendNewWallMessage.cs
2020-12-03 19:38:03 +00:00

34 lines
1.2 KiB
C#

using MediatR;
using Microsoft.AspNetCore.SignalR;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Clients;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Api.Hubs;
namespace Sledgemapper.Api.Handlers
{
public class SendNewWallMessage : INotificationHandler<NewWallNotification>
{
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
public SendNewWallMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
public async Task Handle(NewWallNotification notification, CancellationToken cancellationToken)
{
await _hub.Clients.Groups(notification.Session.SessionName).NewWall(notification.Wall);
}
}
public class SendNewNoteMessage : INotificationHandler<NewNoteNotification>
{
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
public SendNewNoteMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
public async Task Handle(NewNoteNotification notification, CancellationToken cancellationToken)
{
await _hub.Clients.Groups(notification.Session.SessionName).NewNote(notification.Note);
}
}
}