fix: align backend APIs and upload flow

This commit is contained in:
2026-09-11 18:18:59 +08:00
parent 32177a7293
commit 898cf5dba0
69 changed files with 1081 additions and 153 deletions
@@ -6,7 +6,7 @@ using MessageService.Infrastructure;
namespace MessageService.WebApi.Application.EventHandlers
{
public class ConversationAddHandler : IConsumer<GroupMemberJoinedEvent>,
IConsumer<FriendAddedEvent>
IConsumer<FriendAddedEvent>, IConsumer<GroupMemberLeftEvent>
{
private readonly IConversationReposity reposity;
@@ -21,6 +21,11 @@ namespace MessageService.WebApi.Application.EventHandlers
public async Task Consume(ConsumeContext<GroupMemberJoinedEvent> context)
{
var @event = context.Message;
var existing = await reposity.FindByTargetIdAsync(@event.GroupId);
if (existing.Any(x => x.UserId == @event.UserId && x.ChatType == Domain.Enums.ChatType.GROUP))
{
return;
}
reposity.Create(new Domain.Entities.Conversation(
userId: @event.UserId,
targetId: @event.GroupId,
@@ -32,12 +37,17 @@ namespace MessageService.WebApi.Application.EventHandlers
lastMessage: string.Empty
));
await messageDb.SaveChangesAsync();
await messageDb.SaveChangesAsync(context.CancellationToken);
}
public async Task Consume(ConsumeContext<FriendAddedEvent> context)
{
var @event = context.Message;
var existing = await reposity.FindByUserIdAsync(@event.OwnerId);
if (existing.Any(x => x.TargetId == @event.TargetId && x.ChatType == Domain.Enums.ChatType.PRIVATE))
{
return;
}
reposity.Create(new Domain.Entities.Conversation(
userId: @event.OwnerId,
targetId: @event.TargetId,
@@ -49,7 +59,18 @@ namespace MessageService.WebApi.Application.EventHandlers
lastMessage: string.Empty
));
await messageDb.SaveChangesAsync();
await messageDb.SaveChangesAsync(context.CancellationToken);
}
public async Task Consume(ConsumeContext<GroupMemberLeftEvent> context)
{
var conversations = await reposity.FindByTargetIdAsync(context.Message.GroupId);
foreach (var conversation in conversations.Where(x =>
x.UserId == context.Message.UserId && x.ChatType == Domain.Enums.ChatType.GROUP))
{
conversation.SoftDelete();
}
await messageDb.SaveChangesAsync(context.CancellationToken);
}
}
}