2019-05-13 09:55:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-08 15:18:56 +08:00
|
|
|
module Jobs
|
2019-10-02 12:01:53 +08:00
|
|
|
class NotifyPostRevision < ::Jobs::Base
|
2019-05-08 15:18:56 +08:00
|
|
|
def execute(args)
|
2019-05-08 15:58:08 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user_ids) unless args[:user_ids]
|
2019-05-08 15:18:56 +08:00
|
|
|
|
|
|
|
post_revision = PostRevision.find_by(id: args[:post_revision_id])
|
2020-03-06 02:51:51 +08:00
|
|
|
return if post_revision.nil?
|
2019-05-08 15:18:56 +08:00
|
|
|
|
2019-05-08 15:58:08 +08:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
User
|
|
|
|
.where(id: args[:user_ids])
|
|
|
|
.find_each do |user|
|
2019-06-05 03:48:06 +08:00
|
|
|
next if post_revision.hidden && !user.staff?
|
|
|
|
|
2019-05-08 15:58:08 +08: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 15:18:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|