前端:
增加会话缓存 后端: 增加触发消息创建事件 增加消息创建事件触发后的处理函数
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using IM_API.Application.Interfaces;
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
@@ -9,15 +12,20 @@ namespace IM_API.Application.EventHandlers
|
||||
public class SignalREventHandler : IEventHandler<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
public SignalREventHandler(IHubContext<ChatHub> hub)
|
||||
private readonly IMapper _mapper;
|
||||
public SignalREventHandler(IHubContext<ChatHub> hub, IMapper mapper)
|
||||
{
|
||||
_hub = hub;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task Handle(MessageCreatedEvent @event)
|
||||
{
|
||||
var streamKey = @event.StreamKey;
|
||||
await _hub.Clients.Group(streamKey).SendAsync(SignalRMethodDefine.ReceiveMessage, @event);
|
||||
if(@event.ChatType == Models.ChatType.PRIVATE)
|
||||
{
|
||||
MessageBaseDto messageBaseDto = _mapper.Map<MessageBaseDto>(_mapper.Map<Message>(@event));
|
||||
await _hub.Clients.Users(@event.MsgRecipientId.ToString()).SendAsync("ReceiveMessage", messageBaseDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user