Class: Twterm::Tab::Statuses::Conversation
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Dumpable
included
Methods included from Cacheable
#retrieve_from_cache!
#append, #delete, #destroy_status, #drawable_item_count, #favorite, #items, #matches?, #open_link, #prepend, #quote, #reply, #respond_to_key, #retweet, #search_query_window, #show_conversation, #show_user, #statuses, #total_item_count
Methods included from Utils
check_type
Methods included from Loadable
#initially_loaded!, #initially_loaded?
Methods included from Subscriber
included, #subscribe, #unsubscribe
#matches?, #search_query_window
#scroller, #total_item_count
Methods included from Publisher
#publish
Methods inherited from AbstractTab
#close, #find_or_fetch_list, #find_or_fetch_status, #find_or_fetch_user, #render, #respond_to_key
Constructor Details
#initialize(app, client, status_id) ⇒ Conversation
Returns a new instance of Conversation.
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 112
def initialize(app, client, status_id)
super(app, client)
@status_id = status_id
retrieve_from_cache!
reload.then do
scroller.move_to_top
sort
end
end
|
Instance Attribute Details
#status_id ⇒ Object
Returns the value of attribute status_id.
14
15
16
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 14
def status_id
@status_id
end
|
Instance Method Details
#==(other) ⇒ Object
16
17
18
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 16
def ==(other)
other.is_a?(self.class) && status_id == other.status_id
end
|
#dump ⇒ Object
108
109
110
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 108
def dump
@status_id
end
|
#fetch ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 20
def fetch
find_or_fetch_status(status_id).then do |status|
append(status)
fetch_ancestor(status)
fetch_quoted_status(status)
find_descendants(status)
fetch_possible_quotes(status)
fetch_possible_replies(status)
end
end
|
#fetch_ancestor(status) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 31
def fetch_ancestor(status)
in_reply_to_status_id = status.in_reply_to_status_id
if in_reply_to_status_id.nil?
Concurrent::Promise.fulfill(nil)
elsif (instance = app.status_repository.find(in_reply_to_status_id))
Concurrent::Promise.fulfill(instance)
else
client.show_status(in_reply_to_status_id)
end
.then do |in_reply_to|
next if in_reply_to.nil?
append(in_reply_to)
sort
fetch_ancestor(in_reply_to)
end
end
|
#fetch_possible_quotes(status) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 49
def fetch_possible_quotes(status)
client.search(status.url).then do |statuses|
statuses
.select { |s| !s. && s.quoted_status_id == status.id }
.each { |s| prepend(s) }
sort
render
end
end
|
#fetch_possible_replies(status) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 60
def fetch_possible_replies(status)
user = app.user_repository.find(status.user_id)
return if user.nil?
client.search("to:#{user.screen_name}").then do |statuses|
statuses
.select { |s| !s. && s.in_reply_to_status_id == status.id }
.each { |s| prepend(s) }
sort
render
end
end
|
#fetch_quoted_status(status) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 75
def fetch_quoted_status(status)
quoted_status_id = status.quoted_status_id
if quoted_status_id.nil?
Concurrent::Promise.fulfill(nil)
elsif (instance = app.status_repository.find(quoted_status_id))
Concurrent::Promise.fulfill(instance)
else
client.show_status(quoted_status_id)
end
.then do |quoted_status|
next if quoted_status.nil?
append(quoted_status)
sort
fetch_ancestor(quoted_status)
fetch_quoted_status(quoted_status)
end
end
|
#find_descendants(status) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 94
def find_descendants(status)
app.status_repository.find_replies_for(status.id).reject { |s| s. }.each do |reply|
prepend(reply)
find_descendants(reply)
end
app.status_repository.find_quotes_for(status.id).reject { |s| s. }.each do |quote|
prepend(quote)
find_descendants(quote)
end
sort
end
|
#title ⇒ Object
125
126
127
|
# File 'lib/twterm/tab/statuses/conversation.rb', line 125
def title
'Conversation'.freeze
end
|