/** Sone locked notification ticker objects. */
private final Map<Sone, ScheduledFuture<?>> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, ScheduledFuture<?>>());
- /** The “new version” notification. */
- private final TemplateNotification newVersionNotification;
-
/** The “inserting images” notification. */
private final ListNotification<Image> insertingImagesNotification;
Template mentionNotificationTemplate = loaders.loadTemplate("/templates/notify/mentionNotification.html");
mentionNotification = new ListNotification<>("mention-notification", "posts", mentionNotificationTemplate, false);
- Template newVersionTemplate = loaders.loadTemplate("/templates/notify/newVersionNotification.html");
- newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
-
Template insertingImagesTemplate = loaders.loadTemplate("/templates/notify/inserting-images-notification.html");
insertingImagesNotification = new ListNotification<>("inserting-images-notification", "images", insertingImagesTemplate);
}
/**
- * Notifies the web interface that a new Sone version was found.
- *
- * @param updateFoundEvent
- * The event
- */
- @Subscribe
- public void updateFound(UpdateFoundEvent updateFoundEvent) {
- newVersionNotification.set("latestVersion", updateFoundEvent.getVersion());
- newVersionNotification.set("latestEdition", updateFoundEvent.getLatestEdition());
- newVersionNotification.set("releaseTime", updateFoundEvent.getReleaseTime());
- newVersionNotification.set("disruptive", updateFoundEvent.isDisruptive());
- notificationManager.addNotification(newVersionNotification);
- }
-
- /**
* Notifies the web interface that an image insert was started
*
* @param imageInsertStartedEvent
import com.google.common.eventbus.*
import net.pterodactylus.sone.core.event.*
import net.pterodactylus.util.notify.*
+import javax.inject.*
/**
* Handler for the “new version” notification.
*/
-class NewVersionHandler(private val notificationManager: NotificationManager, private val notification: TemplateNotification) {
+class NewVersionHandler @Inject constructor(private val notificationManager: NotificationManager, @Named("newVersion") private val notification: TemplateNotification) {
@Subscribe
fun newVersionFound(updateFoundEvent: UpdateFoundEvent) {
newSoneHandler: NewSoneHandler,
newRemotePostHandler: NewRemotePostHandler,
soneLockedOnStartupHandler: SoneLockedOnStartupHandler,
- soneLockedHandler: SoneLockedHandler
+ soneLockedHandler: SoneLockedHandler,
+ newVersionHandler: NewVersionHandler
)
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.*
bind<NewRemotePostHandler>().asSingleton()
bind<SoneLockedHandler>().asSingleton()
bind<LocalPostHandler>().asSingleton()
+ bind<NewVersionHandler>().asSingleton()
}
@Provides
fun getLocalPostNotification(loaders: Loaders) =
ListNotification<Post>("local-post-notification", "posts", loaders.loadTemplate("/templates/notify/newPostNotification.html"), dismissable = false)
+ @Provides
+ @Singleton
+ @Named("newVersion")
+ fun getNewVersionNotification(loaders: Loaders) =
+ TemplateNotification("new-version-notification", loaders.loadTemplate("/templates/notify/newVersionNotification.html"))
+
private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
injector.verifySingletonInstance<LocalPostHandler>()
}
+ @Test
+ fun `new-version notification is created as singleton`() {
+ injector.verifySingletonInstance<TemplateNotification>(named("newVersion"))
+ }
+
+ @Test
+ fun `new-version notification has correct ID`() {
+ assertThat(injector.getInstance<TemplateNotification>(named("newVersion")).id, equalTo("new-version-notification"))
+ }
+
+ @Test
+ fun `new-version notification is dismissable`() {
+ assertThat(injector.getInstance<TemplateNotification>(named("newVersion")).isDismissable, equalTo(true))
+ }
+
+ @Test
+ fun `new-version notification loads correct template`() {
+ loaders.templates += "/templates/notify/newVersionNotification.html" to "1".asTemplate()
+ val notification = injector.getInstance<TemplateNotification>(named("newVersion"))
+ assertThat(notification.render(), equalTo("1"))
+ }
+
+ @Test
+ fun `new-version handler can be created`() {
+ assertThat(injector.getInstance<NewVersionHandler>(), notNullValue())
+ }
+
+ @Test
+ fun `new-version handler is created as singleton`() {
+ injector.verifySingletonInstance<NewVersionHandler>()
+ }
+
}