
Merge branch 'issue-1951' of dlab/hive
from pull-request 1404 * refs/heads/issue-1951: Fixed a bug for getting notification events Reviewed-by: 이응준
@5d11f55f55f8ee95b938e373bda1f7cd2bfda440
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
... | ... | @@ -1008,7 +1008,22 @@ |
1008 | 1008 |
scheduleDeleteOldNotifications(); |
1009 | 1009 |
} |
1010 | 1010 |
|
1011 |
+ /** |
|
1012 |
+ * Finds NotificationEvents that are supposed to be shown to the {@code user}. |
|
1013 |
+ * Paginates it with {@code from} and {@code size}. |
|
1014 |
+ * |
|
1015 |
+ * @param user |
|
1016 |
+ * @param from |
|
1017 |
+ * @param size |
|
1018 |
+ * @return |
|
1019 |
+ */ |
|
1011 | 1020 |
public static List<NotificationEvent> findByReceiver(User user, int from, int size) { |
1012 |
- return user.notificationEvents.subList(from, from + size); |
|
1021 |
+ List<NotificationEvent> allEvents = user.notificationEvents; |
|
1022 |
+ int allEventsCount = allEvents.size(); |
|
1023 |
+ if (allEventsCount <= from) { |
|
1024 |
+ return new ArrayList<>(); |
|
1025 |
+ } |
|
1026 |
+ int to = (allEventsCount < from + size) ? allEventsCount : from + size; |
|
1027 |
+ return allEvents.subList(from, to); |
|
1013 | 1028 |
} |
1014 | 1029 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?