2019-01-05 11:43:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PublishScheduledStatusWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2020-03-31 19:59:03 +00:00
|
|
|
sidekiq_options lock: :until_executed
|
2019-01-20 11:57:05 +00:00
|
|
|
|
2019-01-05 11:43:28 +00:00
|
|
|
def perform(scheduled_status_id)
|
|
|
|
scheduled_status = ScheduledStatus.find(scheduled_status_id)
|
|
|
|
scheduled_status.destroy!
|
|
|
|
|
|
|
|
PostStatusService.new.call(
|
|
|
|
scheduled_status.account,
|
|
|
|
options_with_objects(scheduled_status.params.with_indifferent_access)
|
|
|
|
)
|
2023-01-08 16:07:46 +00:00
|
|
|
|
|
|
|
remove_scheduled_status(scheduled_status)
|
2019-01-05 11:43:28 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def options_with_objects(options)
|
|
|
|
options.tap do |options_hash|
|
|
|
|
options_hash[:application] = Doorkeeper::Application.find(options_hash.delete(:application_id)) if options[:application_id]
|
2019-01-06 11:03:27 +00:00
|
|
|
options_hash[:thread] = Status.find(options_hash.delete(:in_reply_to_id)) if options_hash[:in_reply_to_id]
|
2023-01-08 16:07:46 +00:00
|
|
|
options_hash[:notify] = true
|
2019-01-05 11:43:28 +00:00
|
|
|
end
|
|
|
|
end
|
2023-01-08 16:07:46 +00:00
|
|
|
|
|
|
|
def remove_scheduled_status(scheduled_status)
|
|
|
|
Redis.current.publish("timeline:#{scheduled_status.account.id}", Oj.dump(event: :scheduled_status, payload: scheduled_status.id.to_s))
|
|
|
|
end
|
2019-01-05 11:43:28 +00:00
|
|
|
end
|