Deduplicate post view notifications

This commit is contained in:
Tim
2025-08-01 11:55:17 +08:00
parent e8e77b6467
commit db31b5d6c1
3 changed files with 28 additions and 0 deletions

View File

@@ -18,4 +18,6 @@ public interface NotificationRepository extends JpaRepository<Notification, Long
List<Notification> findByComment(Comment comment);
void deleteByTypeAndFromUser(NotificationType type, User fromUser);
void deleteByTypeAndFromUserAndPost(NotificationType type, User fromUser, Post post);
}

View File

@@ -58,6 +58,9 @@ public class NotificationService {
public Notification createNotification(User user, NotificationType type, Post post, Comment comment, Boolean approved,
User fromUser, ReactionType reactionType, String content) {
if (type == NotificationType.POST_VIEWED && post != null && fromUser != null) {
notificationRepository.deleteByTypeAndFromUserAndPost(type, fromUser, post);
}
Notification n = new Notification();
n.setUser(user);
n.setType(type);