RenderFilter renderFilter,
LinkedElementRenderFilter linkedElementRenderFilter,
PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry, Translation translation, L10nFilter l10nFilter,
- NotificationManager notificationManager, @Named("newRemotePost") ListNotification<Post> newPostNotification) {
+ NotificationManager notificationManager, @Named("newRemotePost") ListNotification<Post> newPostNotification,
+ @Named("localPost") ListNotification<Post> localPostNotification) {
this.sonePlugin = sonePlugin;
this.loaders = loaders;
this.listNotificationFilter = listNotificationFilter;
this.translation = translation;
this.notificationManager = notificationManager;
this.newPostNotification = newPostNotification;
+ this.localPostNotification = localPostNotification;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
soneTextParser = new SoneTextParser(getCore(), getCore());
templateContextFactory.addTemplateObject("formPassword", formPassword);
/* create notifications. */
- Template localPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
- localPostNotification = new ListNotification<>("local-post-notification", "posts", localPostNotificationTemplate, false);
-
Template newReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
newReplyNotification = new ListNotification<>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
Post post = newPostFoundEvent.getPost();
boolean isLocal = post.getSone().isLocal();
- if (isLocal) {
- localPostNotification.add(post);
- }
if (!hasFirstStartNotification()) {
- if (isLocal) {
- notificationManager.addNotification(localPostNotification);
- }
if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
mentionNotification.add(post);
notificationManager.addNotification(mentionNotification);
private void removePost(Post post) {
newPostNotification.remove(post);
- localPostNotification.remove(post);
if (!localSoneMentionedInNewPostOrReply(post)) {
mentionNotification.remove(post);
}
bind<NewSoneHandler>().asSingleton()
bind<NewRemotePostHandler>().asSingleton()
bind<SoneLockedHandler>().asSingleton()
+ bind<LocalPostHandler>().asSingleton()
}
@Provides
fun getScheduledExecutorService() =
newScheduledThreadPool(1)
+ @Provides
+ @Singleton
+ @Named("localPost")
+ fun getLocalPostNotification(loaders: Loaders) =
+ ListNotification<Post>("local-post-notification", "posts", loaders.loadTemplate("/templates/notify/newPostNotification.html"), dismissable = false)
+
private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
injector.verifySingletonInstance<SoneLockedHandler>()
}
+ @Test
+ fun `local-post notification can be created`() {
+ assertThat(injector.getInstance<ListNotification<Post>>(named("localPost")), notNullValue())
+ }
+
+ @Test
+ fun `local-post notification is not dismissable`() {
+ assertThat(injector.getInstance<ListNotification<Post>>(named("localPost")).isDismissable, equalTo(false))
+ }
+
+ @Test
+ fun `local-post notification has correct ID`() {
+ assertThat(injector.getInstance<ListNotification<Post>>(named("localPost")).id, equalTo("local-post-notification"))
+ }
+
+ @Test
+ fun `local-post notification has correct key and template`() {
+ loaders.templates += "/templates/notify/newPostNotification.html" to "<% posts>".asTemplate()
+ val notification = injector.getInstance<ListNotification<Post>>(named("localPost"))
+ val posts = listOf(EmptyPost("post1"), EmptyPost("post2"))
+ posts.forEach(notification::add)
+ assertThat(notification.render(), equalTo(posts.toString()))
+ }
+
+ @Test
+ fun `local-post notification is created as singleton`() {
+ injector.verifySingletonInstance<ListNotification<Post>>(named("localPost"))
+ }
+
+ @Test
+ fun `local-post handler can be created`() {
+ assertThat(injector.getInstance<LocalPostHandler>(), notNullValue())
+ }
+
+ @Test
+ fun `local-post handler is created as singleton`() {
+ injector.verifySingletonInstance<LocalPostHandler>()
+ }
+
}