lib/ayadn/view.rb in ayadn-1.1.3 vs lib/ayadn/view.rb in ayadn-1.2.0

- old
+ new

@@ -4,27 +4,27 @@ def initialize @workers = Workers.new end - def show_posts_with_index(data, options) - posts, view = build_stream_with_index(data, options) + def show_posts_with_index(data, options, niceranks = {}) + posts, view = build_stream_with_index(data, options, niceranks) puts view Databases.save_indexed_posts(posts) end - def show_posts(data, options) - puts build_stream_without_index(data, options) + def show_posts(data, options, niceranks = {}) + puts build_stream_without_index(data, options, niceranks) end def show_raw(stream) #puts stream.to_json jj stream end def show_simple_post(post, options) - view = build_stream_without_index(post, options) + view = build_stream_without_index(post, options, {}) puts view end def show_posted(resp) show_simple_post([resp['data']], {}) @@ -274,13 +274,35 @@ else event_id end end - def build_stream_with_index(data, options) #expects an array + 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| + (next if content[:nicerank] == false) if Settings.options[:nicerank][:filter_unranked] == true + next if content[:nicerank] < Settings.options[:nicerank][:threshold] + filtered[id] = content + end + return filtered + end + return posts + end + return posts + end + return posts + end + + def build_stream_with_index(data, options, niceranks) #expects an array @view = "" - posts = @workers.build_posts(data.reverse) + posts = @workers.build_posts(data.reverse, niceranks) + + posts = filter_nicerank posts, options + posts.each do |id,content| count = "%03d" % content[:count] 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? @@ -292,13 +314,16 @@ @view << build_content(content) end return posts, @view end - def build_stream_without_index(data, options) #expects an array + def build_stream_without_index(data, options, niceranks) #expects an array @view = "" - posts = @workers.build_posts(data.reverse) + posts = @workers.build_posts(data.reverse, niceranks) + + posts = filter_nicerank posts, options + posts.each do |id,content| if content[:username] == Settings.config[:identity][:username] @view << content[:id].to_s.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 + " " @@ -426,9 +451,15 @@ 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] && content[:nicerank] && Settings.options[:nicerank][:filter] + header << " " + header << "[#{content[:nicerank]}]".color(Settings.options[:colors][:nicerank]) + end + if Settings.options[:timeline][:show_date] header << " " header << content[:date].color(Settings.options[:colors][:date]) end if Settings.options[:timeline][:show_source]