logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

unblock_service.rb (1051B)


  1. # frozen_string_literal: true
  2. class UnblockService < BaseService
  3. def call(account, target_account)
  4. return unless account.blocking?(target_account)
  5. unblock = account.unblock!(target_account)
  6. create_notification(unblock) unless target_account.local?
  7. unblock
  8. end
  9. private
  10. def create_notification(unblock)
  11. if unblock.target_account.ostatus?
  12. NotificationWorker.perform_async(build_xml(unblock), unblock.account_id, unblock.target_account_id)
  13. elsif unblock.target_account.activitypub?
  14. ActivityPub::DeliveryWorker.perform_async(build_json(unblock), unblock.account_id, unblock.target_account.inbox_url)
  15. end
  16. end
  17. def build_json(unblock)
  18. Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
  19. unblock,
  20. serializer: ActivityPub::UndoBlockSerializer,
  21. adapter: ActivityPub::Adapter
  22. ).as_json).sign!(unblock.account))
  23. end
  24. def build_xml(block)
  25. OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unblock_salmon(block))
  26. end
  27. end