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

37 lines
909 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. begin
  7. @response = build_request.perform
  8. Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{@response.status}" unless @response.status.success?
  9. @response.connection&.close
  10. rescue HTTP::Error, OpenSSL::SSL::SSLError => e
  11. Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{e}"
  12. end
  13. @account.secret = ''
  14. @account.subscription_expires_at = nil
  15. @account.save!
  16. end
  17. private
  18. def build_request
  19. Request.new(:post, @account.hub_url, form: subscription_params)
  20. end
  21. def subscription_params
  22. {
  23. 'hub.topic': @account.remote_url,
  24. 'hub.mode': 'unsubscribe',
  25. 'hub.callback': api_subscription_url(@account.id),
  26. 'hub.verify': 'async',
  27. }
  28. end
  29. end