about summary refs log tree commit diff
path: root/app/models/stream_entry.rb
blob: 68a33ccf70870d214bc8ad2f4ca6f9e57ca50589 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class StreamEntry < ActiveRecord::Base
  belongs_to :account, inverse_of: :stream_entries
  belongs_to :activity, polymorphic: true

  validates :account, :activity, presence: true

  scope :with_includes, -> { includes(:activity) }

  def object_type
    orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)
  end

  def verb
    orphaned? ? :delete : self.activity.verb
  end

  def targeted?
    [:follow, :share, :favorite].include? verb
  end

  def target
    orphaned? ? nil : self.activity.target
  end

  def title
    orphaned? ? nil : self.activity.title
  end

  def content
    orphaned? ? nil : self.activity.content
  end

  def threaded?
    verb == :favorite || object_type == :comment
  end

  def thread
    orphaned? ? nil : self.activity.thread
  end

  def mentions
    orphaned? ? [] : self.activity.mentions
  end

  private

  def orphaned?
    self.activity.nil?
  end
end