1
0

reblog_service.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # frozen_string_literal: true
  2. class ReblogService < BaseService
  3. include Authorization
  4. include Payloadable
  5. # Reblog a status and notify its remote author
  6. # @param [Account] account Account to reblog from
  7. # @param [Status] reblogged_status Status to be reblogged
  8. # @param [Hash] options
  9. # @option [String] :visibility
  10. # @option [Boolean] :with_rate_limit
  11. # @return [Status]
  12. def call(account, reblogged_status, options = {})
  13. reblogged_status = reblogged_status.reblog if reblogged_status.reblog?
  14. authorize_with account, reblogged_status, :reblog?
  15. reblog = account.statuses.find_by(reblog: reblogged_status)
  16. return reblog unless reblog.nil?
  17. visibility = if reblogged_status.hidden?
  18. reblogged_status.visibility
  19. else
  20. options[:visibility] || account.user&.setting_default_privacy
  21. end
  22. reblog = account.statuses.create!(reblog: reblogged_status, text: '', visibility: visibility, rate_limit: options[:with_rate_limit])
  23. Trends.register!(reblog)
  24. DistributionWorker.perform_async(reblog.id)
  25. ActivityPub::DistributionWorker.perform_async(reblog.id)
  26. create_notification(reblog)
  27. increment_statistics
  28. reblog
  29. end
  30. private
  31. def create_notification(reblog)
  32. reblogged_status = reblog.reblog
  33. LocalNotificationWorker.perform_async(reblogged_status.account_id, reblog.id, reblog.class.name, 'reblog') if reblogged_status.account.local?
  34. end
  35. def increment_statistics
  36. ActivityTracker.increment('activity:interactions')
  37. end
  38. def build_json(reblog)
  39. Oj.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(reblog), ActivityPub::ActivitySerializer, signer: reblog.account))
  40. end
  41. end