favourite_service.rb 704 B

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