logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

unsubscribe_service.rb (886B)


  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. build_request.perform do |response|
  8. Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{response.status}" unless response.status.success?
  9. end
  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