2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class NotifyMovedPosts < ::Jobs::Base
|
2013-02-05 14:16:51 -05:00
|
|
|
def execute(args)
|
|
|
|
raise Discourse::InvalidParameters.new(:post_ids) if args[:post_ids].blank?
|
|
|
|
raise Discourse::InvalidParameters.new(:moved_by_id) if args[:moved_by_id].blank?
|
|
|
|
|
|
|
|
# Make sure we don't notify the same user twice (in case multiple posts were moved at once.)
|
|
|
|
users_notified = Set.new
|
|
|
|
posts =
|
|
|
|
Post
|
|
|
|
.where(id: args[:post_ids])
|
|
|
|
.where("user_id <> ?", args[:moved_by_id])
|
|
|
|
.includes(:user, :topic)
|
|
|
|
if posts.present?
|
2014-05-06 09:41:59 -04:00
|
|
|
moved_by = User.find_by(id: args[:moved_by_id])
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
posts.each do |p|
|
|
|
|
unless users_notified.include?(p.user_id)
|
2013-03-01 07:07:44 -05:00
|
|
|
p.user.notifications.create(
|
|
|
|
notification_type: Notification.types[:moved_post],
|
2013-02-05 14:16:51 -05:00
|
|
|
topic_id: p.topic_id,
|
|
|
|
post_number: p.post_number,
|
|
|
|
data: { topic_title: p.topic.title, display_username: moved_by.username }.to_json,
|
|
|
|
)
|
|
|
|
users_notified << p.user_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|