logo

mastofe

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

unsubscribe_service.rb (681B)


  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