📄 Update year in file headers
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / notification / NotificationHandlerModule.kt
index 2b147fc..18aefd6 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Sone - NotificationHandlerModuleTest.kt - Copyright Â© 2019 David â€˜Bombe’ Roden
+ * Sone - NotificationHandlerModule.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
@@ -44,8 +44,10 @@ class NotificationHandlerModule : AbstractModule() {
                bind<SoneLockedOnStartupHandler>().asSingleton()
                bind<NewSoneHandler>().asSingleton()
                bind<NewRemotePostHandler>().asSingleton()
+               bind<RemotePostReplyHandler>().asSingleton()
                bind<SoneLockedHandler>().asSingleton()
                bind<LocalPostHandler>().asSingleton()
+               bind<LocalReplyHandler>().asSingleton()
                bind<NewVersionHandler>().asSingleton()
                bind<ImageInsertHandler>().asSingleton()
                bind<FirstStartHandler>().asSingleton()
@@ -54,6 +56,7 @@ class NotificationHandlerModule : AbstractModule() {
                bind<WebOfTrustHandler>().asSingleton()
                bind<SoneMentionDetector>().asSingleton()
                bind<SoneMentionedHandler>().asSingleton()
+               bind<SoneInsertHandler>().asSingleton()
        }
 
        @Provides
@@ -81,6 +84,12 @@ class NotificationHandlerModule : AbstractModule() {
 
        @Provides
        @Singleton
+       @Named("newRemotePostReply")
+       fun getNewRemotePostReplyNotification(loaders: Loaders) =
+                       ListNotification<PostReply>("new-reply-notification", "replies", loaders.loadTemplate("/templates/notify/newReplyNotification.html"), dismissable = false)
+
+       @Provides
+       @Singleton
        @Named("soneLocked")
        fun getSoneLockedNotification(loaders: Loaders) =
                        ListNotification<Sone>("sones-locked-notification", "sones", loaders.loadTemplate("/templates/notify/lockedSonesNotification.html"), dismissable = true)
@@ -93,6 +102,12 @@ class NotificationHandlerModule : AbstractModule() {
 
        @Provides
        @Singleton
+       @Named("localReply")
+       fun getLocalReplyNotification(loaders: Loaders) =
+                       ListNotification<PostReply>("local-reply-notification", "replies", loaders.loadTemplate("/templates/notify/newReplyNotification.html"), dismissable = false)
+
+       @Provides
+       @Singleton
        @Named("newVersion")
        fun getNewVersionNotification(loaders: Loaders) =
                        TemplateNotification("new-version-notification", loaders.loadTemplate("/templates/notify/newVersionNotification.html"))
@@ -157,6 +172,20 @@ class NotificationHandlerModule : AbstractModule() {
        fun getSoneMentionedNotification(loaders: Loaders) =
                        ListNotification<Post>("mention-notification", "posts", loaders.loadTemplate("/templates/notify/mentionNotification.html"), dismissable = false)
 
+       @Provides
+       @Singleton
+       fun getSoneNotificationSupplier(loaders: Loaders): SoneInsertNotificationSupplier =
+                       mutableMapOf<Sone, TemplateNotification>()
+                                       .let { cache ->
+                                               { sone ->
+                                                       cache.computeIfAbsent(sone) {
+                                                               loaders.loadTemplate("/templates/notify/soneInsertNotification.html")
+                                                                               .let(::TemplateNotification)
+                                                                               .also { it["insertSone"] = sone }
+                                                       }
+                                               }
+                                       }
+
        private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
        private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)