Store filtered notifications in all templates.
[Sone.git] / src / main / java / net / pterodactylus / sone / template / NotificationManagerAccessor.java
index 1c27b29..c4468ea 100644 (file)
@@ -21,10 +21,12 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.notify.ListNotificationFilters;
 import net.pterodactylus.util.notify.Notification;
 import net.pterodactylus.util.notify.NotificationManager;
-import net.pterodactylus.util.template.DataProvider;
 import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
 
 /**
  * Adds additional properties to a {@link NotificationManager}.
@@ -44,18 +46,14 @@ public class NotificationManagerAccessor extends ReflectionAccessor {
         * {@inheritDoc}
         */
        @Override
-       public Object get(DataProvider dataProvider, Object object, String member) {
+       public Object get(TemplateContext templateContext, Object object, String member) {
                NotificationManager notificationManager = (NotificationManager) object;
                if ("all".equals(member)) {
-                       List<Notification> notifications = new ArrayList<Notification>(notificationManager.getNotifications());
+                       List<Notification> notifications = ListNotificationFilters.filterNotifications(new ArrayList<Notification>(notificationManager.getNotifications()), (Sone) templateContext.get("currentSone"));
                        Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
                        return notifications;
-               } else if ("new".equals(member)) {
-                       List<Notification> notifications = new ArrayList<Notification>(notificationManager.getChangedNotifications());
-                       Collections.sort(notifications, Notification.LAST_UPDATED_TIME_SORTER);
-                       return notifications;
                }
-               return super.get(dataProvider, object, member);
+               return super.get(templateContext, object, member);
        }
 
 }