闭社主体 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
845 B

  1. # frozen_string_literal: true
  2. class UnsubscribeService < BaseService
  3. def call(account)
  4. @account = account
  5. @response = build_request.perform
  6. Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{@response.status}" unless @response.status.success?
  7. @account.secret = ''
  8. @account.subscription_expires_at = nil
  9. @account.save!
  10. rescue HTTP::Error, OpenSSL::SSL::SSLError
  11. Rails.logger.debug "PuSH subscription request for #{@account.acct} could not be made due to HTTP or SSL error"
  12. end
  13. private
  14. def build_request
  15. Request.new(:post, @account.hub_url, form: subscription_params)
  16. end
  17. def subscription_params
  18. {
  19. 'hub.topic': @account.remote_url,
  20. 'hub.mode': 'unsubscribe',
  21. 'hub.callback': api_subscription_url(@account.id),
  22. 'hub.verify': 'async',
  23. }
  24. end
  25. end