The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

37 linhas
1.2 KiB

  1. # frozen_string_literal: true
  2. class UnfollowService < BaseService
  3. # Unfollow and notify the remote user
  4. # @param [Account] source_account Where to unfollow from
  5. # @param [Account] target_account Which to unfollow
  6. def call(source_account, target_account)
  7. follow = source_account.unfollow!(target_account)
  8. return unless follow
  9. create_notification(follow) unless target_account.local?
  10. UnmergeWorker.perform_async(target_account.id, source_account.id)
  11. follow
  12. end
  13. private
  14. def create_notification(follow)
  15. if follow.target_account.ostatus?
  16. NotificationWorker.perform_async(build_xml(follow), follow.account_id, follow.target_account_id)
  17. elsif follow.target_account.activitypub?
  18. ActivityPub::DeliveryWorker.perform_async(build_json(follow), follow.account_id, follow.target_account.inbox_url)
  19. end
  20. end
  21. def build_json(follow)
  22. Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
  23. follow,
  24. serializer: ActivityPub::UndoFollowSerializer,
  25. adapter: ActivityPub::Adapter
  26. ).as_json).sign!(follow.account))
  27. end
  28. def build_xml(follow)
  29. OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unfollow_salmon(follow))
  30. end
  31. end