2019-05-12 20:55:44 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-08 02:18:56 -05:00
|
|
|
module Jobs
|
2019-10-01 23:01:53 -05:00
|
|
|
class NotifyPostRevision < ::Jobs::Base
|
2019-05-08 02:18:56 -05:00
|
|
|
def execute(args)
|
2019-05-08 02:58:08 -05:00
|
|
|
raise Discourse::InvalidParameters.new(:user_ids) unless args[:user_ids]
|
2019-05-08 02:18:56 -05:00
|
|
|
|
|
|
|
post_revision = PostRevision.find_by(id: args[:post_revision_id])
|
|
|
|
raise Discourse::InvalidParameters.new(:post_revision_id) unless post_revision
|
|
|
|
|
2019-05-08 02:58:08 -05:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
User.where(id: args[:user_ids]).find_each do |user|
|
2019-06-04 14:48:06 -05:00
|
|
|
next if post_revision.hidden && !user.staff?
|
|
|
|
|
2019-05-08 02:58:08 -05:00
|
|
|
PostActionNotifier.alerter.create_notification(
|
|
|
|
user,
|
|
|
|
Notification.types[:edited],
|
|
|
|
post_revision.post,
|
|
|
|
display_username: post_revision.user.username,
|
|
|
|
acting_user_id: post_revision&.user_id,
|
|
|
|
revision_number: post_revision.number
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-05-08 02:18:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|