Class: Twterm::Tab::DirectMessage::Conversation
Instance Attribute Summary
Attributes included from Scrollable
#scroller
Attributes inherited from Base
#window
Instance Method Summary
collapse
Methods included from Subscriber
included, #subscribe, #unsubscribe
Methods included from Scrollable
#total_item_count
#filter, #filter_query, #reset_filter
Methods included from Publisher
#publish
Methods included from Utils
check_type
Methods inherited from Base
#==, #close, #refresh
Constructor Details
#initialize(conversation) ⇒ Conversation
Returns a new instance of Conversation.
22
23
24
25
26
27
28
|
# File 'lib/twterm/tab/direct_message/conversation.rb', line 22
def initialize(conversation)
super()
@conversation = conversation
subscribe(Event::DirectMessage::Fetched) { refresh }
end
|
Instance Method Details
#drawable_item_count ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/twterm/tab/direct_message/conversation.rb', line 14
def drawable_item_count
messages.drop(scroller.offset).lazy
.map { |m| m.text.split_by_width(window.maxx - 4).count + 2 }
.scan(0, :+)
.select { |l| l < window.maxy }
.count
end
|
#items ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/twterm/tab/direct_message/conversation.rb', line 30
def items
if filter_query.empty?
messages
else
messages.select { |m| m.matches?(filter_query) }
end
end
|
#respond_to_key(key) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/twterm/tab/direct_message/conversation.rb', line 38
def respond_to_key(key)
return true if scroller.respond_to_key(key)
case key
when ?/
filter
when ?n, ?r
DirectMessageComposer.instance.compose(conversation.collocutor)
when ?q
reset_filter
else
return false
end
true
end
|
#title ⇒ Object
89
90
91
|
# File 'lib/twterm/tab/direct_message/conversation.rb', line 89
def title
'@%s messages' % conversation.collocutor.screen_name
end
|
#update ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/twterm/tab/direct_message/conversation.rb', line 55
def update
line = 0
scroller.drawable_items.each.with_index(0) do |message, i|
formatted_lines = message.text.split_by_width(window.maxx - 4).count
window.with_color(:black, :magenta) do
formatted_lines.+(1).times do |j|
window.setpos(line + j, 0)
window.addch(' ')
end
end if scroller.current_item?(i)
window.setpos(line, 2)
window.bold do
window.with_color(message.sender.color) do
window.addstr(message.sender.name)
end
end
window.addstr(' (@%s)' % message.sender.screen_name)
window.addstr(' [%s]' % message.date)
message.text.split_by_width(window.maxx - 4).each do |str|
line += 1
window.setpos(line, 2)
window.addstr(str)
end
line += 2
end
end
|