lib/ayadn/view.rb in ayadn-1.4.6 vs lib/ayadn/view.rb in ayadn-1.5.0
- old
+ new
@@ -15,11 +15,11 @@
def show_posts(data, options, niceranks = {})
resp = build_stream_without_index(data, options, niceranks)
puts resp unless resp == ""
end
- def show_raw(stream)
+ def show_raw(stream, options = {})
#puts stream.to_json
jj stream
end
def show_simple_post(post, options)
@@ -81,11 +81,11 @@
t.title = "Current Ayadn settings".color(:cyan)
t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ]
@iter = 0
opts = Settings.options.dup
opts.each do |k,v|
- v.delete_if {|ke,_| ke == :deleted || ke == :annotations } # not mutable values
+ v.delete_if {|ke,_| ke == :deleted || ke == :annotations} # don't show immutable values
v.each do |x,y|
t << :separator if @iter >= 1
unless y.is_a?(Hash)
t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), y.to_s.color(:green) ]
else
@@ -99,11 +99,11 @@
end
clear_screen()
puts table
end
- def show_userinfos(content, token)
+ def show_userinfos(content, token, show_ranks = false)
if content['name']
view = "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name])
else
view = "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
end
@@ -128,14 +128,24 @@
view << "\n\nTimeZone\t\t".color(:cyan) + content['timezone'].color(:green)
view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(:green)
view << "\n\nPosts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(:green)
+
+ unless show_ranks == false
+ # this is ok for one user, but do not call this in a loop
+ # do call them all at once instead if many
+ ranks = NiceRank.new.get_posts_day([content['id'].to_i])
+ unless ranks.empty?
+ view << "\n\nPosts/day\t\t".color(:cyan) + ranks[0][:posts_day].to_s.color(:green)
+ end
+ end
+
view << "\n\nFollowing\t\t".color(:cyan) + content['counts']['following'].to_s.color(:green)
view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(:green)
- if content['username'] == Settings.config[:identity][:username]
+ if content['username'] == Settings.config[:identity][:username] && !token.nil?
view << "\n\nStorage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(:red)
view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(:green)
end
#view << "\nStars\t\t\t".color(:cyan) + content['counts']['stars'].to_s.color(:yellow)
@@ -286,37 +296,37 @@
al = Databases.get_alias_from_id(event_id)
al.nil? ? event_id : al
end
def filter_nicerank posts, options
- if options[:filter] == true # only if this option is true in Action (only global for now)
- unless Settings.options[:nicerank].nil? #in case config file not initialized
- if Settings.options[:nicerank][:filter] == true
- filtered = {}
- posts.each do |id,content|
- if Settings.options[:nicerank][:filter_unranked] == true
- next if content[:nicerank] == false
- end
- unless content[:nicerank] == false
- next if content[:nicerank] < Settings.options[:nicerank][:threshold]
- next if content[:is_human] == false
- next if content[:real_person] == false
- end
- filtered[id] = content
+ if options[:filter] == true # if this option is true in Action (it's only for global, actually)
+ if Settings.options[:nicerank][:filter] == true
+ filtered = {}
+ posts.each do |id,content|
+ if Settings.options[:nicerank][:filter_unranked] == true
+ next if content[:nicerank] == false
end
- return filtered
+ unless content[:nicerank] == false
+ next if content[:nicerank] < Settings.options[:nicerank][:threshold]
+ next if content[:is_human] == false
+ next if content[:real_person] == false
+ end
+ filtered[id] = content
end
+ return filtered
end
end
return posts
end
def build_stream_with_index(data, options, niceranks) #expects an array
@view = ""
posts = filter_nicerank(@workers.build_posts(data.reverse, niceranks), options)
posts.each do |id,content|
- count = "%03d" % content[:count]
+ format = "%03d" % content[:count]
+ arrow = arrow_count(options, content)
+ count = "#{arrow}#{format}"
if content[:username] == Settings.config[:identity][:username]
@view << count.color(Settings.options[:colors][:index]).inverse
elsif content[:mentions].include?(Settings.config[:identity][:username]) && options[:in_mentions].nil?
@view << count.color(Settings.options[:colors][:mentions]).inverse
else
@@ -330,22 +340,41 @@
def build_stream_without_index(data, options, niceranks) #expects an array
@view = ""
posts = filter_nicerank(@workers.build_posts(data.reverse, niceranks), options)
posts.each do |id,content|
+ content[:id] = arrow_id(options, content)
if content[:username] == Settings.config[:identity][:username]
- @view << content[:id].to_s.color(Settings.options[:colors][:id]).inverse + " "
+ @view << content[:id].color(Settings.options[:colors][:id]).inverse + " "
elsif content[:mentions].include?(Settings.config[:identity][:username]) && options[:in_mentions].nil?
- @view << content[:id].to_s.color(Settings.options[:colors][:mentions]).inverse + " "
+ @view << content[:id].color(Settings.options[:colors][:mentions]).inverse + " "
else
- @view << content[:id].to_s.color(Settings.options[:colors][:id]) + " "
+ @view << content[:id].color(Settings.options[:colors][:id]) + " "
end
@view << build_content(content)
end
@view
end
+ def arrow_count options, content
+ if options[:reply_to]
+ return '⬇︎ ' if options[:reply_to] == content[:id]
+ return '⬆︎ ' if options[:post_id] == content[:id]
+ return ''
+ end
+ ''
+ end
+
+ def arrow_id options, content
+ if options[:reply_to]
+ return content[:id].to_s.prepend('⬇︎ ') if options[:reply_to] == content[:id]
+ return content[:id].to_s.prepend('⬆︎ ') if options[:post_id] == content[:id]
+ return content[:id].to_s
+ end
+ content[:id].to_s
+ end
+
def build_interactions_stream(data)
inter = ""
data.reverse.each do |event|
users_array = []
inter << "#{@workers.parsed_time(event['event_date'])}".color(Settings.options[:colors][:date])
@@ -460,18 +489,10 @@
header << content[:handle].color(Settings.options[:colors][:username])
if Settings.options[:timeline][:show_real_name]
header << " "
header << content[:name].color(Settings.options[:colors][:name])
end
-
- if Settings.options[:timeline][:show_nicerank] == true && content[:nicerank]
- if Settings.options[:nicerank][:filter] == true
- header << " "
- header << "[#{content[:nicerank]}]".color(Settings.options[:colors][:nicerank])
- end
- end
-
if Settings.options[:timeline][:show_date]
header << " "
header << content[:date].color(Settings.options[:colors][:date])
end
if Settings.options[:timeline][:show_source]
@@ -495,10 +516,9 @@
end
hd = (".".color(Settings.options[:colors][:dots])) * num_dots
hd << "\n"
formatted = { header: hd }
content[:checkins].each do |key, val|
- #formatted[key] = val unless (val.nil? || !val)
formatted[key] = val
end
formatted[:name] = "" if formatted[:name].nil?
chk = formatted[:header]