package net.pterodactylus.sone.web.notification
-import com.google.common.eventbus.*
-import net.pterodactylus.sone.core.event.*
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.notify.*
-import net.pterodactylus.util.notify.*
-import javax.inject.*
+import com.google.common.eventbus.Subscribe
+import net.pterodactylus.sone.core.event.MarkPostKnownEvent
+import net.pterodactylus.sone.core.event.NewPostFoundEvent
+import net.pterodactylus.sone.core.event.PostRemovedEvent
+import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.notify.ListNotification
+import net.pterodactylus.sone.notify.hasFirstStartNotification
+import net.pterodactylus.util.notify.NotificationManager
+import javax.inject.Inject
+import javax.inject.Named
/**
* Handler for local posts.
}
private fun Post.onLocal(action: (Post) -> Unit) =
- if (sone.isLocal) action(this) else Unit
+ if ((sone == null) || sone!!.isLocal) action(this) else Unit
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.notify.*
+import net.pterodactylus.sone.test.createPost
import net.pterodactylus.util.notify.*
import net.pterodactylus.util.template.*
import org.hamcrest.MatcherAssert.*
}
@Test
+ // this scenario can happen when sones are removed.
+ fun `handler removes post from notification if sone is missing`() {
+ val post = createPost(sone = null)
+ notification.add(post)
+ eventBus.post(PostRemovedEvent(post))
+ assertThat(notification.elements, emptyIterable())
+ }
+
+ @Test
fun `handler removes post from notification when post is marked as known`() {
notification.add(localPost)
notificationManager.addNotification(notification)