The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

39 satır
1.0 KiB

  1. class ProcessInteractionService
  2. def call(envelope, target_account)
  3. body = salmon.unpack(envelope)
  4. xml = Nokogiri::XML(body)
  5. return if xml.at_xpath('//author/name').nil? || xml.at_xpath('//author/uri').nil?
  6. username = xml.at_xpath('//author/name').content
  7. url = xml.at_xpath('//author/uri').content
  8. domain = Addressable::URI.parse(url).host
  9. account = Account.find_by(username: username, domain: domain)
  10. if account.nil?
  11. account = follow_remote_account_service.("acct:#{username}@#{domain}")
  12. end
  13. if salmon.verify(envelope, account.keypair)
  14. verb = xml.at_path('//activity:verb').content
  15. case verb
  16. when 'http://activitystrea.ms/schema/1.0/follow', 'follow'
  17. account.follow!(target_account)
  18. when 'http://activitystrea.ms/schema/1.0/unfollow', 'unfollow'
  19. account.unfollow!(target_account)
  20. end
  21. end
  22. end
  23. private
  24. def salmon
  25. OStatus2::Salmon.new
  26. end
  27. def follow_remote_account_service
  28. FollowRemoteAccountService.new
  29. end
  30. end