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.

52 lines
991 B

  1. class StreamEntry < ApplicationRecord
  2. include Paginable
  3. belongs_to :account, inverse_of: :stream_entries
  4. belongs_to :activity, polymorphic: true
  5. validates :account, :activity, presence: true
  6. scope :with_includes, -> { includes(:activity) }
  7. def object_type
  8. orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)
  9. end
  10. def verb
  11. orphaned? ? :delete : self.activity.verb
  12. end
  13. def targeted?
  14. [:follow, :share, :favorite].include? verb
  15. end
  16. def target
  17. orphaned? ? nil : self.activity.target
  18. end
  19. def title
  20. orphaned? ? nil : self.activity.title
  21. end
  22. def content
  23. orphaned? ? nil : self.activity.content
  24. end
  25. def threaded?
  26. verb == :favorite || object_type == :comment
  27. end
  28. def thread
  29. orphaned? ? nil : self.activity.thread
  30. end
  31. def mentions
  32. self.activity.respond_to?(:mentions) ? self.activity.mentions.map { |x| x.account } : []
  33. end
  34. private
  35. def orphaned?
  36. self.activity.nil?
  37. end
  38. end