/**
- * 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
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<Post>) {
+class NewRemotePostHandler @Inject constructor(private val notificationManager: NotificationManager, @Named("newRemotePost") private val notification: ListNotification<Post>) {
@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)
+ }
+
}