Files
IM_NEW/GroupService.WebApi/Application/EventHandler/MessageCreatedHandler.cs
2026-05-09 17:06:30 +08:00

33 lines
1.0 KiB
C#

using GroupService.Domain.IReposities;
using GroupService.Infrastructure;
using IM.Commons.IntegrationEvents;
using MassTransit;
namespace GroupService.WebApi.Application.EventHandler
{
public class MessageCreatedHandler : IConsumer<MsgCreatedEvent>
{
private readonly IGroupReposity reposity;
private readonly GroupDbContext groupDb;
public MessageCreatedHandler(IGroupReposity reposity, GroupDbContext groupDb)
{
this.reposity = reposity;
this.groupDb = groupDb;
}
public async Task Consume(ConsumeContext<MsgCreatedEvent> context)
{
var @event = context.Message;
if(@event.MsgType == "GROUP")
{
var group = await reposity.FindByIdAsync(@event.TargetId);
if (group is null) return;
group.UpdateLastMsg(@event.SequenceId, @event.Content.Fallback, "未知用户");
groupDb.Groups.Update(group);
await groupDb.SaveChangesAsync();
}
}
}
}