From a48a0b0977c2ccc52bcd22ade47cd6b3645422ad 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: Thu, 19 Mar 2026 23:15:30 +0300 Subject: [PATCH] Fix favorites chat logic and story avatar layout --- .../Application/Chats/GetChats/GetChats.cs | 61 ++++++++----------- .../src/core/presentation/layouts/Sidebar.tsx | 3 +- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/backend/src/Modules/Chats/Application/Chats/GetChats/GetChats.cs b/backend/src/Modules/Chats/Application/Chats/GetChats/GetChats.cs index 726b4e4..654f67e 100644 --- a/backend/src/Modules/Chats/Application/Chats/GetChats/GetChats.cs +++ b/backend/src/Modules/Chats/Application/Chats/GetChats/GetChats.cs @@ -31,27 +31,24 @@ internal sealed class GetChatsQueryHandler : IQueryHandler(); - bool hasFavorites = false; foreach (var chat in userChats) { var latestMessage = await _messageRepository.GetLatestChatMessageAsync(chat.Id, cancellationToken); - - if (latestMessage == null) - { - continue; - } - var userIdsToFetch = new HashSet(); + foreach (var member in chat.Members) { userIdsToFetch.Add(member.UserId); } - userIdsToFetch.Add(latestMessage.SenderId); - foreach (var r in latestMessage.Reactions) + if (latestMessage != null) { - userIdsToFetch.Add(r.UserId); + userIdsToFetch.Add(latestMessage.SenderId); + foreach (var r in latestMessage.Reactions) + { + userIdsToFetch.Add(r.UserId); + } } var usersInfo = await _userProvider.GetUsersInfoAsync(userIdsToFetch, cancellationToken); @@ -76,25 +73,27 @@ internal sealed class GetChatsQueryHandler : IQueryHandler(); - var reactionsWithUser = new List(); - foreach (var reaction in latestMessage.Reactions) + if (latestMessage != null) { - usersInfo.TryGetValue(reaction.UserId, out var reactionUser); - reactionsWithUser.Add(new ReactionDto( - reaction.Id, - reaction.Emoji, - reaction.UserId, - reactionUser != null - ? new MessageSenderDto(reactionUser.Id, reactionUser.Username, reactionUser.DisplayName, reactionUser.Avatar) - : new MessageSenderDto(reaction.UserId, "unknown", "Unknown", null) - )); - } + usersInfo.TryGetValue(latestMessage.SenderId, out var senderObj); - var messagesList = new List - { - new ChatMessageDto( + var reactionsWithUser = new List(); + foreach (var reaction in latestMessage.Reactions) + { + usersInfo.TryGetValue(reaction.UserId, out var reactionUser); + reactionsWithUser.Add(new ReactionDto( + reaction.Id, + reaction.Emoji, + reaction.UserId, + reactionUser != null + ? new MessageSenderDto(reactionUser.Id, reactionUser.Username, reactionUser.DisplayName, reactionUser.Avatar) + : new MessageSenderDto(reaction.UserId, "unknown", "Unknown", null) + )); + } + + messagesList.Add(new ChatMessageDto( latestMessage.Id, latestMessage.ChatId, latestMessage.SenderId, @@ -117,8 +116,8 @@ internal sealed class GetChatsQueryHandler : IQueryHandler new ReadByDto(readReceipt.UserId)).ToList() - ) - }; + )); + } var unreadCount = await _messageRepository.GetUnreadCountAsync(chat.Id, request.UserId, cancellationToken); @@ -135,12 +134,6 @@ internal sealed class GetChatsQueryHandler : IQueryHandler(), new List(), 0); - dtos.Add(favs); - } - var sorted = dtos.OrderByDescending(d => d.Messages.FirstOrDefault()?.CreatedAt ?? d.CreatedAt).ToList(); return Result.Success(sorted); } diff --git a/client-web/src/core/presentation/layouts/Sidebar.tsx b/client-web/src/core/presentation/layouts/Sidebar.tsx index ebae475..8645ca4 100644 --- a/client-web/src/core/presentation/layouts/Sidebar.tsx +++ b/client-web/src/core/presentation/layouts/Sidebar.tsx @@ -178,12 +178,11 @@ export default function Sidebar() { ? 'border border-zinc-600' : 'border border-zinc-700' }`}> -
+