闭社主体 forked from https://github.com/tootsuite/mastodon
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.

31 lines
681 B

  1. # frozen_string_literal: true
  2. class Pubsubhubbub::UnsubscribeService < BaseService
  3. attr_reader :account, :callback
  4. def call(account, callback)
  5. @account = account
  6. @callback = Addressable::URI.parse(callback).normalize.to_s
  7. process_unsubscribe
  8. end
  9. private
  10. def process_unsubscribe
  11. if account.nil?
  12. ['Invalid topic URL', 422]
  13. else
  14. confirm_unsubscribe unless subscription.nil?
  15. ['', 202]
  16. end
  17. end
  18. def confirm_unsubscribe
  19. Pubsubhubbub::ConfirmationWorker.perform_async(subscription.id, 'unsubscribe')
  20. end
  21. def subscription
  22. @_subscription ||= Subscription.find_by(account: account, callback_url: callback)
  23. end
  24. end