30 lines
997 B
C#
30 lines
997 B
C#
using IM_API.Domain.Events;
|
|
using IM_API.Dtos;
|
|
using IM_API.Hubs;
|
|
using IM_API.VOs.Group;
|
|
using MassTransit;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace IM_API.Application.EventHandlers.GroupRequestUpdateHandler
|
|
{
|
|
public class RequestUpdateSignalrHandler : IConsumer<GroupRequestUpdateEvent>
|
|
{
|
|
private readonly IHubContext<ChatHub> _hub;
|
|
public RequestUpdateSignalrHandler(IHubContext<ChatHub> hub)
|
|
{
|
|
_hub = hub;
|
|
}
|
|
|
|
public async Task Consume(ConsumeContext<GroupRequestUpdateEvent> context)
|
|
{
|
|
var msg = new HubResponse<GroupRequestUpdateVo>("Event", new GroupRequestUpdateVo
|
|
{
|
|
GroupId = context.Message.GroupId,
|
|
RequestId = context.Message.RequestId,
|
|
UserId = context.Message.UserId
|
|
});
|
|
await _hub.Clients.User(context.Message.UserId.ToString()).SendAsync("ReceiveMessage", msg);
|
|
}
|
|
}
|
|
}
|