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.

29 lines
700 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.create!(account: account, status: status)
  11. if status.local?
  12. NotifyService.new.call(favourite.status.account, favourite)
  13. else
  14. NotificationWorker.perform_async(build_xml(favourite), account.id, status.account_id)
  15. end
  16. favourite
  17. end
  18. private
  19. def build_xml(favourite)
  20. AtomSerializer.render(AtomSerializer.new.favourite_salmon(favourite))
  21. end
  22. end