The code powering m.abunchtell.com https://m.abunchtell.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

60 Zeilen
2.1 KiB

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