blob: 2972d94f61a5c8b1609f66355462e5bbe4d3ee2e (
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
51
52
|
class StreamEntry < ActiveRecord::Base
include Paginable
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
self.activity.respond_to?(:mentions) ? self.activity.mentions.map { |x| x.account } : []
end
private
def orphaned?
self.activity.nil?
end
end
|