favourite_service.rb 652 B

1234567891011121314151617181920212223
  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::NotPermitted unless status.permitted?(account)
  9. favourite = Favourite.create!(account: account, status: status)
  10. Pubsubhubbub::DistributionWorker.perform_async(favourite.stream_entry.id)
  11. if status.local?
  12. NotifyService.new.call(favourite.status.account, favourite)
  13. else
  14. NotificationWorker.perform_async(favourite.stream_entry.id, status.account_id)
  15. end
  16. favourite
  17. end
  18. end