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

33 lines
883 B

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