return from(allNewReplies).filter(replyVisibilityFilter.isVisible(currentSone)).toSet();
}
- /**
- * Sets whether Sone was started with a fresh configuration file.
- *
- * @param newConfig
- * {@code true} if Sone was started with a fresh configuration,
- * {@code false} if the existing configuration could be read
- */
- public void setNewConfig(boolean newConfig) {
- if (newConfig && !hasFirstStartNotification()) {
- Template configNotReadNotificationTemplate = loaders.loadTemplate("/templates/notify/configNotReadNotification.html");
- Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
- notificationManager.addNotification(configNotReadNotification);
- }
- }
-
//
// PRIVATE ACCESSORS
//
import com.google.common.eventbus.*
import net.pterodactylus.sone.core.event.*
import net.pterodactylus.util.notify.*
+import javax.inject.*
/**
* Handler for [ConfigNotRead] events.
*/
-class ConfigNotReadHandler(private val notificationManager: NotificationManager, private val notification: TemplateNotification) {
+class ConfigNotReadHandler @Inject constructor(private val notificationManager: NotificationManager, @Named("configNotRead") private val notification: TemplateNotification) {
@Subscribe
fun configNotRead(configNotRead: ConfigNotRead) {
soneLockedHandler: SoneLockedHandler,
newVersionHandler: NewVersionHandler,
imageInsertHandler: ImageInsertHandler,
- firstStartHandler: FirstStartHandler
+ firstStartHandler: FirstStartHandler,
+ configNotReadHandler: ConfigNotReadHandler
)
bind<NewVersionHandler>().asSingleton()
bind<ImageInsertHandler>().asSingleton()
bind<FirstStartHandler>().asSingleton()
+ bind<ConfigNotReadHandler>().asSingleton()
}
@Provides
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"))
+
private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
injector.verifySingletonInstance<FirstStartHandler>()
}
+ @Test
+ fun `config-not-read notification is created as singleton`() {
+ injector.verifySingletonInstance<TemplateNotification>(named("configNotRead"))
+ }
+
+ @Test
+ fun `config-not-read notification has correct ID `() {
+ assertThat(injector.getInstance<TemplateNotification>(named("configNotRead")).id, equalTo("config-not-read-notification"))
+ }
+
+ @Test
+ fun `config-not-read notification is dismissable`() {
+ assertThat(injector.getInstance<TemplateNotification>(named("configNotRead")).isDismissable, equalTo(true))
+ }
+
+ @Test
+ fun `config-not-read notification loads correct template`() {
+ loaders.templates += "/templates/notify/configNotReadNotification.html" to "1".asTemplate()
+ val notification = injector.getInstance<TemplateNotification>(named("configNotRead"))
+ assertThat(notification.render(), equalTo("1"))
+ }
+
+ @Test
+ fun `config-not-read handler is created as singleton`() {
+ injector.verifySingletonInstance<ConfigNotReadHandler>()
+ }
+
}