X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FLocalPostHandler.kt;h=5951997e27f5d797764a8acc61fd2df9281b42ce;hb=c66657eb61d863fe2b1f1ea534a2bd46e5064b89;hp=a5153ce2254691bc1e4d96376305ab49446385f6;hpb=2a83103aab6254d877c1b5214ca5a3ef19a6fe83;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandler.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandler.kt index a5153ce..5951997 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandler.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandler.kt @@ -1,5 +1,5 @@ /** - * Sone - NewLocalPostHandler.kt - Copyright © 2019 David ‘Bombe’ Roden + * Sone - LocalPostHandler.kt - Copyright © 2019–2020 David ‘Bombe’ Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +17,16 @@ 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. @@ -33,9 +37,9 @@ class LocalPostHandler @Inject constructor(private val notificationManager: Noti fun newPostFound(newPostFoundEvent: NewPostFoundEvent) { newPostFoundEvent.post.onLocal { post -> notification.add(post) - } - if (!notificationManager.hasFirstStartNotification()) { - notificationManager.addNotification(notification) + if (!notificationManager.hasFirstStartNotification()) { + notificationManager.addNotification(notification) + } } } @@ -56,4 +60,4 @@ class LocalPostHandler @Inject constructor(private val notificationManager: Noti } private fun Post.onLocal(action: (Post) -> Unit) = - if (sone.isLocal) action(this) else Unit + if ((sone == null) || sone!!.isLocal) action(this) else Unit