mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-11 09:30:56 +08:00
Revert "feat: support paginated notifications"
This reverts commit a64fd71bbe.
This commit is contained in:
@@ -24,10 +24,6 @@ import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/** Service for creating and retrieving notifications. */
|
||||
@Service
|
||||
@@ -184,24 +180,15 @@ public class NotificationService {
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
public List<Notification> listNotifications(String username, int page, int size) {
|
||||
return listNotifications(username, null, page, size);
|
||||
}
|
||||
|
||||
public List<Notification> listUnreadNotifications(String username, int page, int size) {
|
||||
return listNotifications(username, false, page, size);
|
||||
}
|
||||
|
||||
private List<Notification> listNotifications(String username, Boolean read, int page, int size) {
|
||||
public List<Notification> listNotifications(String username, Boolean read) {
|
||||
User user = userRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||
Set<NotificationType> disabled = user.getDisabledNotificationTypes();
|
||||
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt"));
|
||||
Page<Notification> list;
|
||||
List<Notification> list;
|
||||
if (read == null) {
|
||||
list = notificationRepository.findByUser(user, pageable);
|
||||
list = notificationRepository.findByUserOrderByCreatedAtDesc(user);
|
||||
} else {
|
||||
list = notificationRepository.findByUserAndRead(user, read, pageable);
|
||||
list = notificationRepository.findByUserAndReadOrderByCreatedAtDesc(user, read);
|
||||
}
|
||||
return list.stream().filter(n -> !disabled.contains(n.getType())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user