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.

50 lines
1022 B

  1. # frozen_string_literal: true
  2. class Ostatus::Activity::Base
  3. def initialize(xml, account = nil)
  4. @xml = xml
  5. @account = account
  6. end
  7. def status?
  8. [:activity, :note, :comment].include?(type)
  9. end
  10. def verb
  11. raw = @xml.at_xpath('./activity:verb', activity: TagManager::AS_XMLNS).content
  12. TagManager::VERBS.key(raw)
  13. rescue
  14. :post
  15. end
  16. def type
  17. raw = @xml.at_xpath('./activity:object-type', activity: TagManager::AS_XMLNS).content
  18. TagManager::TYPES.key(raw)
  19. rescue
  20. :activity
  21. end
  22. def id
  23. @xml.at_xpath('./xmlns:id', xmlns: TagManager::XMLNS).content
  24. end
  25. def url
  26. link = @xml.at_xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS)
  27. link.nil? ? nil : link['href']
  28. end
  29. private
  30. def find_status(uri)
  31. if TagManager.instance.local_id?(uri)
  32. local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status')
  33. return Status.find_by(id: local_id)
  34. end
  35. Status.find_by(uri: uri)
  36. end
  37. def redis
  38. Redis.current
  39. end
  40. end