UX: Display a banner on the topic page if it was deleted by Akismet (#57)

UX: Display a banner on the topic page if it was deleted by Akismet (#57)

diff --git a/assets/javascripts/discourse-akismet/connectors/topic-above-post-stream/topic-removed-notification.hbs b/assets/javascripts/discourse-akismet/connectors/topic-above-post-stream/topic-removed-notification.hbs
new file mode 100644
index 0000000..66d7591
--- /dev/null
+++ b/assets/javascripts/discourse-akismet/connectors/topic-above-post-stream/topic-removed-notification.hbs
@@ -0,0 +1,5 @@
+{{#if akismetFlaggedTopic}}
+  <div class="alert alert-info category-read-only-banner">
+    {{i18n "akismet.topic_deleted"}}
+  </div>
+{{/if}}
\ No newline at end of file
diff --git a/assets/javascripts/discourse-akismet/connectors/topic-above-post-stream/topic-removed-notification.js.es6 b/assets/javascripts/discourse-akismet/connectors/topic-above-post-stream/topic-removed-notification.js.es6
new file mode 100644
index 0000000..253f278
--- /dev/null
+++ b/assets/javascripts/discourse-akismet/connectors/topic-above-post-stream/topic-removed-notification.js.es6
@@ -0,0 +1,8 @@
+export default {
+  setupComponent(args, component) {
+    const akismetDeletedTopicChannel = `/discourse-akismet/topic-deleted/${args.model.id}`;
+    component.messageBus.subscribe(akismetDeletedTopicChannel, () => {
+      component.set("akismetFlaggedTopic", true);
+    });
+  }
+};
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 15ef047..28673bd 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -25,6 +25,8 @@ en:
       dismiss: "Dismiss"
       ignore: "Ignore"
       reviewable_delete_prompt: "Are you sure you want to delete this user? This will remove all of their posts and block their email and ip address."
+      topic_deleted: Our automated spam filter, Akismet, has temporarily hidden your topic.
+
 
     review:
       user:
diff --git a/lib/discourse_akismet/posts_bouncer.rb b/lib/discourse_akismet/posts_bouncer.rb
index 69765f7..b912343 100644
--- a/lib/discourse_akismet/posts_bouncer.rb
+++ b/lib/discourse_akismet/posts_bouncer.rb
@@ -2,7 +2,7 @@
 
 module DiscourseAkismet
   class PostsBouncer < Bouncer
-
+    TOPIC_DELETED_CHANNEL = "/discourse-akismet/topic-deleted/"
     @@munger = nil
 
     def self.to_check
@@ -103,6 +103,14 @@ module DiscourseAkismet
       # Send a message to the user explaining that it happened
       notify_poster(post) if SiteSetting.akismet_notify_user?
 
+      if post.is_first_post?
+        MessageBus.publish(
+          [TOPIC_DELETED_CHANNEL, post.topic_id].join,
+          "spam_found",
+          user_ids: [post.user_id]
+        )
+      end
+
       reviewable = ReviewableAkismetPost.needs_review!(
         created_by: spam_reporter, target: post, topic: post.topic, reviewable_by_moderator: true,
         payload: { post_cooked: post.cooked }
diff --git a/spec/lib/posts_bouncer_spec.rb b/spec/lib/posts_bouncer_spec.rb
index 02eabc9..a548160 100644
--- a/spec/lib/posts_bouncer_spec.rb
+++ b/spec/lib/posts_bouncer_spec.rb
@@ -90,9 +90,9 @@ describe DiscourseAkismet::PostsBouncer do
   describe '#check_post' do
     let(:client) { Akismet::Client.build_client }
 
-    it 'Creates a new ReviewableAkismetPost when spam is confirmed by Akismet' do
-      subject.move_to_state(post, 'new')
+    before { subject.move_to_state(post, 'new') }
 
+    it 'Creates a new ReviewableAkismetPost when spam is confirmed by Akismet' do
       stub_spam_confirmation
 
       subject.perform_check(client, post)
@@ -109,8 +109,6 @@ describe DiscourseAkismet::PostsBouncer do
     end
 
     it 'Creates a new score for the new reviewable' do
-      subject.move_to_state(post, 'new')
-
       stub_spam_confirmation
 
       subject.perform_check(client, post)
@@ -121,6 +119,19 @@ describe DiscourseAkismet::PostsBouncer do
       expect(reviewable_akismet_score.take_action_bonus).to be_zero
     end
 
+    it 'publishes a message to display a banner on the topic page' do
+      stub_spam_confirmation
+
+      channel = [described_class::TOPIC_DELETED_CHANNEL, post.topic_id].join
+      message = MessageBus.track_publish(channel) do
+        subject.perform_check(client, post)
+      end.first
+
+      data = message.data
+
+      expect(data).to eq("spam_found")
+    end
+
     it 'Creates a new ReviewableAkismetPost when an API error is returned' do
       subject.move_to_state(post, 'new')
 

GitHub sha: 3cb2bafc

This commit appears in #57 which was approved by eviltrout. It was merged by romanrizzi.