mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-11 17:41:04 +08:00
Fix notification pagination after filtering disabled types
This commit is contained in:
@@ -23,7 +23,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** Service for creating and retrieving notifications. */
|
||||
@Service
|
||||
@@ -187,11 +186,19 @@ public class NotificationService {
|
||||
org.springframework.data.domain.Pageable pageable = org.springframework.data.domain.PageRequest.of(page, size);
|
||||
org.springframework.data.domain.Page<Notification> result;
|
||||
if (read == null) {
|
||||
result = notificationRepository.findByUserOrderByCreatedAtDesc(user, pageable);
|
||||
if (disabled.isEmpty()) {
|
||||
result = notificationRepository.findByUserOrderByCreatedAtDesc(user, pageable);
|
||||
} else {
|
||||
result = notificationRepository.findByUserAndTypeNotInOrderByCreatedAtDesc(user, disabled, pageable);
|
||||
}
|
||||
} else {
|
||||
result = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read, pageable);
|
||||
if (disabled.isEmpty()) {
|
||||
result = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read, pageable);
|
||||
} else {
|
||||
result = notificationRepository.findByUserAndReadAndTypeNotInOrderByCreatedAtDesc(user, read, disabled, pageable);
|
||||
}
|
||||
}
|
||||
return result.stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
|
||||
return result.getContent();
|
||||
}
|
||||
|
||||
public void markRead(String username, List<Long> ids) {
|
||||
@@ -210,8 +217,10 @@ public class NotificationService {
|
||||
User user = userRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||
Set<NotificationType> disabled = user.getDisabledNotificationTypes();
|
||||
return notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, false).stream()
|
||||
.filter(n -> !disabled.contains(n.getType())).count();
|
||||
if (disabled.isEmpty()) {
|
||||
return notificationRepository.countByUserAndRead(user, false);
|
||||
}
|
||||
return notificationRepository.countByUserAndReadAndTypeNotIn(user, false, disabled);
|
||||
}
|
||||
|
||||
public void notifyMentions(String content, User fromUser, Post post, Comment comment) {
|
||||
|
||||
Reference in New Issue
Block a user