X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FNotificationHandlerModule.kt;h=bdbbc320533b3591d36bf0adb9a26caf4c7e3204;hp=b843cca913a3d5e4e21091856323f10b8c971400;hb=a1fa131a44204b2b42de3b5d467373cd113dab28;hpb=eb828bec5212bba8b9745f45defdc47711968ce6 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt index b843cca..bdbbc32 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt @@ -18,11 +18,17 @@ package net.pterodactylus.sone.web.notification import com.google.inject.* +import com.google.inject.binder.* import net.pterodactylus.sone.core.* import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.freenet.wot.* import net.pterodactylus.sone.main.* import net.pterodactylus.sone.notify.* +import net.pterodactylus.sone.text.* import net.pterodactylus.util.notify.* +import java.util.concurrent.* +import java.util.concurrent.TimeUnit.* +import java.util.function.* import javax.inject.* import javax.inject.Singleton @@ -33,16 +39,31 @@ class NotificationHandlerModule : AbstractModule() { override fun configure() { bind(NotificationHandler::class.java).`in`(Singleton::class.java) + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() + bind().asSingleton() } @Provides - fun getMarkPostKnownDuringFirstStartHandler(core: Core, notificationManager: NotificationManager) = - MarkPostKnownDuringFirstStartHandler(notificationManager, core::markPostKnown) + fun getMarkPostKnownHandler(core: Core): Consumer = Consumer { core.markPostKnown(it) } @Provides - @Singleton - fun getSoneLockedOnStartupHandler(notificationManager: NotificationManager, @Named("soneLockedOnStartup") notification: ListNotification) = - SoneLockedOnStartupHandler(notificationManager, notification) + fun getMarkPostReplyKnownHandler(core: Core): Consumer = Consumer { core.markReplyKnown(it) } @Provides @Singleton @@ -51,13 +72,121 @@ class NotificationHandlerModule : AbstractModule() { ListNotification("sone-locked-on-startup", "sones", loaders.loadTemplate("/templates/notify/soneLockedOnStartupNotification.html")) @Provides - @Singleton - fun getNewSoneHandler(notificationManager: NotificationManager, @Named("newSone") notification: ListNotification) = - NewSoneHandler(notificationManager, notification) - - @Provides @Named("newSone") fun getNewSoneNotification(loaders: Loaders) = ListNotification("new-sone-notification", "sones", loaders.loadTemplate("/templates/notify/newSoneNotification.html"), dismissable = false) + @Provides + @Singleton + @Named("newRemotePost") + fun getNewPostNotification(loaders: Loaders) = + ListNotification("new-post-notification", "posts", loaders.loadTemplate("/templates/notify/newPostNotification.html"), dismissable = false) + + @Provides + @Singleton + @Named("newRemotePostReply") + fun getNewRemotePostReplyNotification(loaders: Loaders) = + ListNotification("new-reply-notification", "replies", loaders.loadTemplate("/templates/notify/newReplyNotification.html"), dismissable = false) + + @Provides + @Singleton + @Named("soneLocked") + fun getSoneLockedNotification(loaders: Loaders) = + ListNotification("sones-locked-notification", "sones", loaders.loadTemplate("/templates/notify/lockedSonesNotification.html"), dismissable = true) + + @Provides + @Singleton + @Named("localPost") + fun getLocalPostNotification(loaders: Loaders) = + ListNotification("local-post-notification", "posts", loaders.loadTemplate("/templates/notify/newPostNotification.html"), dismissable = false) + + @Provides + @Singleton + @Named("localReply") + fun getLocalReplyNotification(loaders: Loaders) = + ListNotification("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")) + + @Provides + @Singleton + @Named("imageInserting") + fun getImageInsertingNotification(loaders: Loaders) = + ListNotification("inserting-images-notification", "images", loaders.loadTemplate("/templates/notify/inserting-images-notification.html"), dismissable = true) + + @Provides + @Singleton + @Named("imageFailed") + fun getImageInsertingFailedNotification(loaders: Loaders) = + ListNotification("image-insert-failed-notification", "images", loaders.loadTemplate("/templates/notify/image-insert-failed-notification.html"), dismissable = true) + + @Provides + @Singleton + @Named("imageInserted") + fun getImageInsertedNotification(loaders: Loaders) = + ListNotification("inserted-images-notification", "images", loaders.loadTemplate("/templates/notify/inserted-images-notification.html"), dismissable = true) + + @Provides + @Singleton + @Named("firstStart") + fun getFirstStartNotification(loaders: Loaders) = + TemplateNotification("first-start-notification", loaders.loadTemplate("/templates/notify/firstStartNotification.html")) + + @Provides + @Singleton + @Named("configNotRead") + fun getConfigNotReadNotification(loaders: Loaders) = + TemplateNotification("config-not-read-notification", loaders.loadTemplate("/templates/notify/configNotReadNotification.html")) + + @Provides + @Singleton + @Named("startup") + fun getStartupNotification(loaders: Loaders) = + TemplateNotification("startup-notification", loaders.loadTemplate("/templates/notify/startupNotification.html")) + + @Provides + @Singleton + @Named("webOfTrust") + fun getWebOfTrustNotification(loaders: Loaders) = + TemplateNotification("wot-missing-notification", loaders.loadTemplate("/templates/notify/wotMissingNotification.html")) + + @Provides + @Singleton + @Named("webOfTrustReacher") + fun getWebOfTrustReacher(webOfTrustConnector: WebOfTrustConnector): Runnable = + Runnable { webOfTrustConnector.ping() } + + @Provides + @Singleton + @Named("webOfTrustReschedule") + fun getWebOfTrustReschedule(@Named("notification") ticker: ScheduledExecutorService) = + Consumer { ticker.schedule(it, 15, SECONDS) } + + @Provides + @Singleton + @Named("soneMentioned") + fun getSoneMentionedNotification(loaders: Loaders) = + ListNotification("mention-notification", "posts", loaders.loadTemplate("/templates/notify/mentionNotification.html"), dismissable = false) + + @Provides + @Singleton + fun getSoneNotificationSupplier(loaders: Loaders): SoneInsertNotificationSupplier = + mutableMapOf() + .let { cache -> + { sone -> + cache.computeIfAbsent(sone) { + loaders.loadTemplate("/templates/notify/soneInsertNotification.html") + .let(::TemplateNotification) + .also { it["insertSone"] = sone } + } + } + } + + private inline fun bind(): AnnotatedBindingBuilder = bind(T::class.java) + private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java) + }