From bce8f9210179494f51ee9cb7548bbe1f1456ff55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D0=BB=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BC?= Date: Tue, 31 Mar 2026 21:31:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=BA=D0=B8=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Persistence/ConversationsDbContext.cs | 2 +- .../Modules/Messaging/DependencyInjection.cs | 1 + .../Persistence/MessageQueryService.cs | 20 +++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/src/Modules/Conversations/Infrastructure/Persistence/ConversationsDbContext.cs b/backend/src/Modules/Conversations/Infrastructure/Persistence/ConversationsDbContext.cs index 540d299..3721f3f 100644 --- a/backend/src/Modules/Conversations/Infrastructure/Persistence/ConversationsDbContext.cs +++ b/backend/src/Modules/Conversations/Infrastructure/Persistence/ConversationsDbContext.cs @@ -33,7 +33,7 @@ public sealed class ChatsDbContext : DbContext, Knot.Modules.Conversations.Appli public DbSet UserChatSettings => Set(); IQueryable Knot.Contracts.Conversations.Infrastructure.Persistence.IChatsDbContext.Chats => - Set().Select(c => new Knot.Contracts.Conversations.Infrastructure.Persistence.Chat { Avatar = c.Avatar }); + Set().Select(c => new Knot.Contracts.Conversations.Infrastructure.Persistence.Chat { Id = c.Id, Avatar = c.Avatar }); protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/backend/src/Modules/Messaging/DependencyInjection.cs b/backend/src/Modules/Messaging/DependencyInjection.cs index c869799..49d9ced 100644 --- a/backend/src/Modules/Messaging/DependencyInjection.cs +++ b/backend/src/Modules/Messaging/DependencyInjection.cs @@ -32,6 +32,7 @@ public static class DependencyInjection services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddMediatR(config => config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly)); diff --git a/backend/src/Modules/Messaging/Infrastructure/Persistence/MessageQueryService.cs b/backend/src/Modules/Messaging/Infrastructure/Persistence/MessageQueryService.cs index 7a772eb..7cc3719 100644 --- a/backend/src/Modules/Messaging/Infrastructure/Persistence/MessageQueryService.cs +++ b/backend/src/Modules/Messaging/Infrastructure/Persistence/MessageQueryService.cs @@ -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> GetOrphanedMessagesAsync(HashSet activeChatIds, CancellationToken cancellationToken) + { + var builder = Builders.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(); }