added filter on title and description on post

This commit is contained in:
SlimusMinus
2026-07-06 00:47:07 +03:00
parent 04f29001ac
commit 97f28b9eca
6 changed files with 84 additions and 69 deletions

View File

@@ -8,6 +8,7 @@ import com.krylov.refound.repository.ChatRepository;
import com.krylov.refound.repository.MessageRepository;
import com.krylov.refound.repository.UserRepository;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.simp.SimpMessagingTemplate;
@@ -64,7 +65,6 @@ public class ChatService {
Chat chat = chatRepository.findById(chatId)
.orElseThrow(() -> new IllegalArgumentException("Чат не найден"));
// Проверка что отправитель - участник чата
if (!chat.getUserOneId().equals(senderId) && !chat.getUserTwoId().equals(senderId)) {
throw new SecurityException("Вы не участник этого чата");
}
@@ -77,9 +77,21 @@ public class ChatService {
MessageDto dto = toMessageDto(message);
// Отправляем сообщение через WebSocket в топик конкретного чата
messagingTemplate.convertAndSend("/topic/chat/" + chatId, dto);
// Уведомляем получателя об непрочитанных
Long recipientId = chat.getUserOneId().equals(senderId)
? chat.getUserTwoId()
: chat.getUserOneId();
long unreadCount = messageRepository
.countByChatIdAndIsReadFalseAndSenderIdNot(chatId, recipientId);
messagingTemplate.convertAndSend(
"/topic/user/" + recipientId + "/unread",
Map.of("chatId", chatId, "unreadCount", unreadCount)
);
return dto;
}
@@ -122,4 +134,13 @@ public class ChatService {
dto.setCreatedAt(m.getCreatedAt());
return dto;
}
public void deleteChat(Long chatId) {
chatRepository.deleteById(chatId);
}
@Transactional
public void markAsRead(Long chatId, Long userId) {
messageRepository.markAsReadByChatIdAndRecipient(chatId, userId);
}
}