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=18aefd665732e0c38ad03319abec5190f8a3f4d2;hp=74c9f432c85871181f0d525d2f78c4954f412076;hb=438378deab1514f0f608d975ef65f5b7aea44ccb;hpb=2ec60e8d6d2efadd7b4d35de3c3d257a0bc5f190 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 74c9f43..18aefd6 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt @@ -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 @@ -24,6 +24,7 @@ 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.* @@ -39,23 +40,32 @@ 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 getMarkPostKnownHandler(core: Core): Consumer = Consumer { core.markPostKnown(it) } @Provides + fun getMarkPostReplyKnownHandler(core: Core): Consumer = Consumer { core.markReplyKnown(it) } + + @Provides @Singleton @Named("soneLockedOnStartup") fun getSoneLockedOnStartupNotification(loaders: Loaders) = @@ -74,6 +84,12 @@ class NotificationHandlerModule : AbstractModule() { @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) @@ -86,6 +102,12 @@ class NotificationHandlerModule : AbstractModule() { @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")) @@ -144,6 +166,26 @@ class NotificationHandlerModule : AbstractModule() { 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)