diff --git a/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 b/app/assets/javascripts/discourse-common/lib/icon-library.js.es6
index 5f39e06286..a8751806a4 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 here
diff --git a/app/models/notification.rb b/app/models/notification.rb
index ba49fbb624..60ffd7f26c 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -61,6 +61,7 @@ class Notification < ActiveRecord::Base
watching_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_access
end
diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rb
index ddf2b4dc28..289705b815 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 }
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c7d34c3e21..fdf332d66d 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: "{{username}} {{description}}"
group_mentioned: "{{username}} {{description}}"
diff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rb
index 17cba67f6e..a7c78f4990 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 do
expect(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 twice
expect(-> { reviewable.perform(moderator, :approve) }).to raise_error(Reviewable::InvalidAction)
end