fix: align backend APIs and upload flow

This commit is contained in:
2026-09-15 14:10:55 +08:00
parent 32177a7293
commit 53e6195938
149 changed files with 4791 additions and 435 deletions
@@ -1,5 +1,6 @@
using MessageService.Domain.Entities;
using MessageService.Domain.IReposities;
using MessageService.Domain.Models;
using Microsoft.EntityFrameworkCore;
namespace MessageService.Infrastructure.Reposities
@@ -18,31 +19,54 @@ namespace MessageService.Infrastructure.Reposities
db.Conversations.Add(conversation);
}
public async Task<IEnumerable<string>> FindAllStreamKeyAsync(Guid userId)
public async Task<IEnumerable<string>> FindAllStreamKeyAsync(Guid userId, CancellationToken cancellationToken = default)
{
return await db.Conversations.Where(x => x.UserId == userId)
.AsNoTracking()
.Select(s => s.StreamKey)
.ToListAsync();
.ToListAsync(cancellationToken);
}
public async Task<Conversation?> FindByIdAsync(Guid id)
public async Task<Conversation?> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await db.Conversations.FirstOrDefaultAsync(x => x.Id == id);
return await db.Conversations.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
}
public async Task<IEnumerable<Conversation>> FindByStreamKeyAsync(string streamKey)
public async Task<IEnumerable<Conversation>> FindByStreamKeyAsync(string streamKey, CancellationToken cancellationToken = default)
{
return await db.Conversations.Where(x => x.StreamKey == streamKey).ToListAsync();
return await db.Conversations.Where(x => x.StreamKey == streamKey).ToListAsync(cancellationToken);
}
public async Task<IEnumerable<Conversation>> FindByTargetIdAsync(Guid targetId)
public async Task<IEnumerable<Conversation>> FindByTargetIdAsync(Guid targetId, CancellationToken cancellationToken = default)
{
return await db.Conversations.Where(x => x.TargetId == targetId).ToListAsync();
return await db.Conversations.Where(x => x.TargetId == targetId).ToListAsync(cancellationToken);
}
public async Task<IEnumerable<Conversation>> FindByUserIdAsync(Guid userId)
public async Task<IReadOnlyList<ConversationSummary>> ListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default)
{
return await db.Conversations.Where(x => x.UserId == userId).ToListAsync();
return await db.Conversations
.AsNoTracking()
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.LastMessageTime ?? x.CreationTime)
.Select(x => new ConversationSummary(
x.Id,
x.UserId,
x.TargetId,
x.TargetAvatar,
x.TargetName,
x.LastReadSequenceId,
x.UnreadCount,
x.ChatType,
x.LastMessage,
x.LastMessageTime ?? x.CreationTime))
.ToListAsync(cancellationToken);
}
public Task<Conversation?> FindActiveAsync(Guid userId, Guid targetId, Domain.Enums.ChatType chatType, CancellationToken cancellationToken = default)
{
return db.Conversations.FirstOrDefaultAsync(
x => x.UserId == userId && x.TargetId == targetId && x.ChatType == chatType,
cancellationToken);
}
}
}