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.

33 lines
831 B

  1. # frozen_string_literal: true
  2. class FavouriteService < BaseService
  3. include Authorization
  4. # Favourite a status and notify remote user
  5. # @param [Account] account
  6. # @param [Status] status
  7. # @return [Favourite]
  8. def call(account, status)
  9. authorize_with account, status, :show?
  10. favourite = Favourite.find_by(account: account, status: status)
  11. return favourite unless favourite.nil?
  12. favourite = Favourite.create!(account: account, status: status)
  13. if status.local?
  14. NotifyService.new.call(favourite.status.account, favourite)
  15. else
  16. NotificationWorker.perform_async(build_xml(favourite), account.id, status.account_id)
  17. end
  18. favourite
  19. end
  20. private
  21. def build_xml(favourite)
  22. Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.favourite_salmon(favourite))
  23. end
  24. end