You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class UnfavouriteService < BaseService
  3. def call(account, status)
  4. favourite = Favourite.find_by!(account: account, status: status)
  5. favourite.destroy!
  6. NotificationWorker.perform_async(build_xml(favourite), account.id, status.account_id) unless status.local?
  7. favourite
  8. end
  9. private
  10. def build_xml(favourite)
  11. description = "#{favourite.account.acct} no longer favourites a status by #{favourite.status.account.acct}"
  12. Nokogiri::XML::Builder.new do |xml|
  13. entry(xml, true) do
  14. unique_id xml, Time.now.utc, favourite.id, 'Favourite'
  15. title xml, description
  16. content xml, description
  17. author(xml) do
  18. include_author xml, favourite.account
  19. end
  20. object_type xml, :activity
  21. verb xml, :unfavorite
  22. in_reply_to xml, TagManager.instance.uri_for(favourite.status), TagManager.instance.url_for(favourite.status)
  23. target(xml) do
  24. include_target xml, favourite.status
  25. end
  26. end
  27. end.to_xml
  28. end
  29. end