You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
999 B

  1. # frozen_string_literal: true
  2. class ReblogService < BaseService
  3. include StreamEntryRenderer
  4. # Reblog a status and notify its remote author
  5. # @param [Account] account Account to reblog from
  6. # @param [Status] reblogged_status Status to be reblogged
  7. # @return [Status]
  8. def call(account, reblogged_status)
  9. reblogged_status = reblogged_status.reblog if reblogged_status.reblog?
  10. raise Mastodon::NotPermittedError if reblogged_status.direct_visibility? || reblogged_status.private_visibility? || !reblogged_status.permitted?(account)
  11. reblog = account.statuses.create!(reblog: reblogged_status, text: '')
  12. DistributionWorker.perform_async(reblog.id)
  13. Pubsubhubbub::DistributionWorker.perform_async(reblog.stream_entry.id)
  14. if reblogged_status.local?
  15. NotifyService.new.call(reblog.reblog.account, reblog)
  16. else
  17. NotificationWorker.perform_async(stream_entry_to_xml(reblog.stream_entry), account.id, reblog.reblog.account_id)
  18. end
  19. reblog
  20. end
  21. end