이응준 2015-01-07
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
+++ app/models/NotificationEvent.java
@@ -1008,7 +1008,22 @@
         scheduleDeleteOldNotifications();
     }
 
+    /**
+     * Finds NotificationEvents that are supposed to be shown to the {@code user}.
+     * Paginates it with {@code from} and {@code size}.
+     *
+     * @param user
+     * @param from
+     * @param size
+     * @return
+     */
     public static List<NotificationEvent> findByReceiver(User user, int from, int size) {
-        return user.notificationEvents.subList(from, from + size);
+        List<NotificationEvent> allEvents = user.notificationEvents;
+        int allEventsCount = allEvents.size();
+        if (allEventsCount <= from) {
+            return new ArrayList<>();
+        }
+        int to = (allEventsCount < from + size) ? allEventsCount : from + size;
+        return allEvents.subList(from, to);
     }
 }
Add a comment
List