The code powering m.abunchtell.com https://m.abunchtell.com
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

60 líneas
2.0 KiB

  1. # frozen_string_literal: true
  2. class ReblogService < BaseService
  3. include Authorization
  4. include StreamEntryRenderer
  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. # @return [Status]
  9. def call(account, reblogged_status)
  10. reblogged_status = reblogged_status.reblog if reblogged_status.reblog?
  11. authorize_with account, reblogged_status, :reblog?
  12. reblog = account.statuses.find_by(reblog: reblogged_status)
  13. return reblog unless reblog.nil?
  14. reblog = account.statuses.create!(reblog: reblogged_status, text: '')
  15. DistributionWorker.perform_async(reblog.id)
  16. Pubsubhubbub::DistributionWorker.perform_async(reblog.stream_entry.id)
  17. ActivityPub::DistributionWorker.perform_async(reblog.id)
  18. create_notification(reblog)
  19. bump_potential_friendship(account, reblog)
  20. reblog
  21. end
  22. private
  23. def create_notification(reblog)
  24. reblogged_status = reblog.reblog
  25. if reblogged_status.account.local?
  26. NotifyService.new.call(reblogged_status.account, reblog)
  27. elsif reblogged_status.account.ostatus?
  28. NotificationWorker.perform_async(stream_entry_to_xml(reblog.stream_entry), reblog.account_id, reblogged_status.account_id)
  29. elsif reblogged_status.account.activitypub? && !reblogged_status.account.following?(reblog.account)
  30. ActivityPub::DeliveryWorker.perform_async(build_json(reblog), reblog.account_id, reblogged_status.account.inbox_url)
  31. end
  32. end
  33. def bump_potential_friendship(account, reblog)
  34. ActivityTracker.increment('activity:interactions')
  35. return if account.following?(reblog.reblog.account_id)
  36. PotentialFriendshipTracker.record(account.id, reblog.reblog.account_id, :reblog)
  37. end
  38. def build_json(reblog)
  39. Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
  40. reblog,
  41. serializer: ActivityPub::ActivitySerializer,
  42. adapter: ActivityPub::Adapter
  43. ).as_json).sign!(reblog.account))
  44. end
  45. end