X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FNewRemotePostHandler.kt;h=91eaae00f744dd8fb042bc085f255e288590bc17;hp=acf998028162b8e5fba8c74802360730a8c501cc;hb=438378deab1514f0f608d975ef65f5b7aea44ccb;hpb=0dc7811a459455dd2b670eb1924df27f65c36a24 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt index acf9980..91eaae0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt @@ -1,5 +1,5 @@ /** - * Sone - NewRemotePostHandler.kt - Copyright © 2019 David ‘Bombe’ Roden + * Sone - NewRemotePostHandler.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 @@ -22,19 +22,32 @@ import net.pterodactylus.sone.core.event.* import net.pterodactylus.sone.data.* import net.pterodactylus.sone.notify.* import net.pterodactylus.util.notify.* +import javax.inject.* /** * Handler for [NewPostFoundEvent]s that adds the new post to the “new posts” notification and * displays the notification if the “first start” notification is not being shown. */ -class NewRemotePostHandler(private val notificationManager: NotificationManager, private val notification: ListNotification) { +class NewRemotePostHandler @Inject constructor(private val notificationManager: NotificationManager, @Named("newRemotePost") private val notification: ListNotification) { @Subscribe fun newPostFound(newPostFoundEvent: NewPostFoundEvent) { - notification.add(newPostFoundEvent.post) - if (!notificationManager.hasFirstStartNotification()) { - notificationManager.addNotification(notification) + if (!newPostFoundEvent.post.sone.isLocal) { + notification.add(newPostFoundEvent.post) + if (!notificationManager.hasFirstStartNotification()) { + notificationManager.addNotification(notification) + } } } + @Subscribe + fun postRemoved(event: PostRemovedEvent) { + notification.remove(event.post) + } + + @Subscribe + fun postMarkedKnown(event: MarkPostKnownEvent) { + notification.remove(event.post) + } + }