FEATURE: Send the user a notification when their post is approved
This commit is contained in:
parent
de10bd7fb4
commit
3ceff0a92a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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}}"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue