FEATURE: Send email message if post is not spam (#14)

FEATURE: Send email message if post is not spam (#14)

The user receives a private message when the post is first marked as spam and deleted. This commit ensures that the user receives another message after a staff member marked the post as ‘not spam’.

diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 6d65fcf..62e02ff 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -27,3 +27,10 @@ en:
         A [staff member](%{base_url}/about) will review your post soon, and it should appear shortly.
 
         We apologize for the inconvenience.
+
+    akismet_not_spam:
+      subject_template: "Your post is no longer hidden"
+      text_body_template: |
+        Hello,
+
+        A [staff member](%{base_url}/about) reviewed [your post](%{post_link}) in *%{topic_title}* and it is now visible.
diff --git a/models/reviewable_akismet_post.rb b/models/reviewable_akismet_post.rb
index 556b6d9..deed670 100644
--- a/models/reviewable_akismet_post.rb
+++ b/models/reviewable_akismet_post.rb
@@ -47,7 +47,13 @@ class ReviewableAkismetPost < Reviewable
     bouncer.submit_feedback(post, 'ham')
     log_confirmation(performed_by, 'confirmed_ham')
 
-    PostDestroyer.new(performed_by, post).recover if post.deleted_at
+    if post.deleted_at
+      PostDestroyer.new(performed_by, post).recover
+      if SiteSetting.akismet_notify_user?
+        post.reload
+        SystemMessage.new(post.user).create('akismet_not_spam', topic_title: post.topic.title, post_link: post.full_url)
+      end
+    end
 
     successful_transition :rejected, :disagreed
   end
diff --git a/spec/models/reviewable_akismet_post_spec.rb b/spec/models/reviewable_akismet_post_spec.rb
index 52e93ec..0ef67f5 100644
--- a/spec/models/reviewable_akismet_post_spec.rb
+++ b/spec/models/reviewable_akismet_post_spec.rb
@@ -164,6 +164,14 @@ describe 'ReviewableAkismetPost' do
           DiscourseEvent.off(:post_recovered, &blk)
         end
       end
+
+      it 'Sends a system message to the user' do
+        expect { reviewable.perform admin, action }
+          .to change { Topic.private_messages.count }.by(1)
+
+        pm = Topic.private_messages.last
+        expect(pm.allowed_users).to contain_exactly(Discourse.system_user, post.user)
+      end
     end
 
     describe '#perform_ignore' do

GitHub sha: 92989297

This commit appears in #14 which was approved by eviltrout. It was merged by udan11.