Восстановление очистки админки

This commit is contained in:
Халимов Рустам
2026-03-31 21:31:22 +03:00
parent aa69c44a64
commit bce8f92101
3 changed files with 20 additions and 3 deletions

View File

@@ -33,7 +33,7 @@ public sealed class ChatsDbContext : DbContext, Knot.Modules.Conversations.Appli
public DbSet<UserChatSettings> UserChatSettings => Set<UserChatSettings>();
IQueryable<Knot.Contracts.Conversations.Infrastructure.Persistence.Chat> Knot.Contracts.Conversations.Infrastructure.Persistence.IChatsDbContext.Chats =>
Set<DomainChat>().Select(c => new Knot.Contracts.Conversations.Infrastructure.Persistence.Chat { Avatar = c.Avatar });
Set<DomainChat>().Select(c => new Knot.Contracts.Conversations.Infrastructure.Persistence.Chat { Id = c.Id, Avatar = c.Avatar });
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{

View File

@@ -32,6 +32,7 @@ public static class DependencyInjection
services.AddScoped<IMessageReactionRepository, MessageReactionRepository>();
services.AddScoped<ModuleUserStatsService, UserStatsService>();
services.AddScoped<ContractUserStatsService, UserStatsServiceAdapter>();
services.AddScoped<Knot.Contracts.Messaging.Application.Abstractions.IMessageQueryService, MessageQueryService>();
services.AddMediatR(config =>
config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Messaging.Abstractions;
using Knot.Contracts.Messaging.Application.Abstractions;
using Knot.Contracts.Messaging.Domain;
using MongoDB.Driver;
@@ -25,7 +25,23 @@ public sealed class MessageQueryService : IMessageQueryService
m.Id,
m.ChatId,
m.State.HasFlag(MessageState.IsDeleted),
m is MediaMessage mm && mm.Media.Any() ? mm.Media.First().Url : null
m is MediaMessage mm && mm.Media.Any() ? mm.Media.First().Url : null,
m is MediaMessage mm2 && mm2.Media.Any() ? mm2.Media.Select(media => new Contracts.Messaging.Application.Abstractions.MediaInfo(media.Url)).ToList() : null
)).ToList();
}
public async Task<List<MessageInfo>> GetOrphanedMessagesAsync(HashSet<Guid> activeChatIds, CancellationToken cancellationToken)
{
var builder = Builders<Message>.Filter;
var inFilter = builder.In(m => m.ChatId, activeChatIds);
var filter = builder.Not(inFilter);
var messages = await _messages.Find(filter).ToListAsync(cancellationToken);
return messages.Select(m => new MessageInfo(
m.Id,
m.ChatId,
m.State.HasFlag(MessageState.IsDeleted),
m is MediaMessage mm && mm.Media.Any() ? mm.Media.First().Url : null,
m is MediaMessage mm2 && mm2.Media.Any() ? mm2.Media.Select(media => new Contracts.Messaging.Application.Abstractions.MediaInfo(media.Url)).ToList() : null
)).ToList();
}