A platform for community discussion. Free, open, simple.
FEATURE: Send the user a notification when their post is approved
Robin Ward3ceff0a92a8a
diff --git a/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 b/app/assets/javascripts/discourse-common/lib/icon-library.js.es6index 5f39e062866..a8751806a47 100644--- a/app/assets/javascripts/discourse-common/lib/icon-library.js.es6+++ b/app/assets/javascripts/discourse-common/lib/icon-library.js.es6@@ -34,7 +34,8 @@ const REPLACEMENTS = {"notification.granted_badge": "certificate","notification.topic_reminder": "far-clock","notification.watching_first_post": "far-dot-circle",- "notification.group_message_summary": "group"+ "notification.group_message_summary": "group",+ "notification.post_approved": "check"};// TODO: use lib/svg_sprite/fa4-renames.json herediff --git a/app/models/notification.rb b/app/models/notification.rbindex ba49fbb624a..60ffd7f26c9 100644--- a/app/models/notification.rb+++ b/app/models/notification.rb@@ -61,6 +61,7 @@ class Notification < ActiveRecord::Basewatching_first_post: 17,topic_reminder: 18,liked_consolidated: 19,+ post_approved: 20)end@@ -124,10 +125,10 @@ class Notification < ActiveRecord::Base# Be wary of calling this frequently. O(n) JSON parsing can suck.def data_hash@data_hash ||= begin- return nil if data.blank?+ return {} if data.blank?parsed = JSON.parse(data)- return nil if parsed.blank?+ return {} if parsed.blank?parsed.with_indifferent_accessenddiff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rbindex ddf2b4dc28b..289705b8152 100644--- a/app/models/reviewable_queued_post.rb+++ b/app/models/reviewable_queued_post.rb@@ -72,6 +72,14 @@ class ReviewableQueuedPost < Reviewable# Backwards compatibility, new code should listen for `reviewable_transitioned_to`DiscourseEvent.trigger(:approved_post, self, created_post)+ Notification.create!(+ notification_type: Notification.types[:post_approved],+ user_id: created_by.id,+ data: {},+ topic_id: created_post.topic_id,+ post_number: created_post.post_number+ )+create_result(:success, :approved) { |result| result.created_post = created_post }enddiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex c7d34c3e21c..fdf332d66d6 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -1638,6 +1638,7 @@ en:none: "Unable to load notifications at this time."empty: "No notifications found."more: "view older notifications"+ post_approved: "Your post was approved"total_flagged: "total flagged posts"mentioned: "<span>{{username}}</span> {{description}}"group_mentioned: "<span>{{username}}</span> {{description}}"diff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rbindex 17cba67f6ed..a7c78f49900 100644--- a/spec/models/reviewable_queued_post_spec.rb+++ b/spec/models/reviewable_queued_post_spec.rb@@ -57,6 +57,12 @@ RSpec.describe ReviewableQueuedPost, type: :model doexpect(Topic.count).to eq(topic_count)expect(Post.count).to eq(post_count + 1)+ notifications = Notification.where(+ user: reviewable.created_by,+ notification_type: Notification.types[:post_approved]+ )+ expect(notifications).to be_present+# We can't approve twiceexpect(-> { reviewable.perform(moderator, :approve) }).to raise_error(Reviewable::InvalidAction)end