🐛 Fix sone-locked handler
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 10 Dec 2019 15:55:07 +0000 (16:55 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 11 Dec 2019 15:59:17 +0000 (16:59 +0100)
src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt
src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt

index c75cbc1..7918758 100644 (file)
@@ -23,7 +23,6 @@ import net.pterodactylus.sone.core.*
 import net.pterodactylus.sone.data.*
 import net.pterodactylus.sone.main.*
 import net.pterodactylus.sone.notify.*
-import net.pterodactylus.util.notify.*
 import java.util.concurrent.Executors.*
 import java.util.function.*
 import javax.inject.*
@@ -40,6 +39,7 @@ class NotificationHandlerModule : AbstractModule() {
                bind<SoneLockedOnStartupHandler>().asSingleton()
                bind<NewSoneHandler>().asSingleton()
                bind<NewRemotePostHandler>().asSingleton()
+               bind<SoneLockedHandler>().asSingleton()
        }
 
        @Provides
@@ -69,9 +69,8 @@ class NotificationHandlerModule : AbstractModule() {
                        ListNotification<Sone>("sones-locked-notification", "sones", loaders.loadTemplate("/templates/notify/lockedSonesNotification.html"), dismissable = true)
 
        @Provides
-       @Singleton
-       fun getSoneLockedHandler(notificationManager: NotificationManager, @Named("soneLocked") soneLockedNotification: ListNotification<Sone>) =
-                       SoneLockedHandler(notificationManager, soneLockedNotification, newScheduledThreadPool(1))
+       fun getScheduledExecutorService() =
+                       newScheduledThreadPool(1)
 
        private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
        private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
index 8bfbda4..583601b 100644 (file)
@@ -24,12 +24,16 @@ import net.pterodactylus.sone.notify.*
 import net.pterodactylus.util.notify.*
 import java.util.concurrent.*
 import java.util.concurrent.atomic.*
+import javax.inject.*
 
 /**
  * Handler for [SoneLockedEvent]s and [SoneUnlockedEvent]s that can schedule notifications after
  * a certain timeout.
  */
-class SoneLockedHandler(private val notificationManager: NotificationManager, private val notification: ListNotification<Sone>, private val executor: ScheduledExecutorService) {
+class SoneLockedHandler @Inject constructor(
+               private val notificationManager: NotificationManager,
+               @Named("soneLocked") private val notification: ListNotification<Sone>,
+               private val executor: ScheduledExecutorService) {
 
        private val future: AtomicReference<ScheduledFuture<*>> = AtomicReference()