diff options
-rw-r--r-- | app/assets/stylesheets/tweets.css.sass | 2 | ||||
-rw-r--r-- | app/controllers/tweets_controller.rb | 10 | ||||
-rw-r--r-- | app/models/tweet.rb | 2 | ||||
-rw-r--r-- | app/views/tweets/_timeline_thresholds.html.haml | 7 | ||||
-rw-r--r-- | app/views/tweets/_tweet.html.haml | 4 | ||||
-rw-r--r-- | app/views/tweets/all_timeline.html.haml | 1 | ||||
-rw-r--r-- | app/views/tweets/timeline.html.haml | 1 |
7 files changed, 21 insertions, 6 deletions
diff --git a/app/assets/stylesheets/tweets.css.sass b/app/assets/stylesheets/tweets.css.sass index 41e8e2c..a5a19c4 100644 --- a/app/assets/stylesheets/tweets.css.sass +++ b/app/assets/stylesheets/tweets.css.sass @@ -4,7 +4,7 @@ width: 572px .tweet margin: 15px 0 - .tweet + .content overflow: hidden background: #ffffff border: 1px solid #c1c5cb diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index 56db341..f25a7e2 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -15,6 +15,10 @@ class TweetsController < ApplicationController optional :screen_name, "toshi_a", "The username of the user for whom to return results for." end + param_group :threshold do + optional :reactions, 5, "Returns Tweets which has received reactions more than (or equal to) the specified number of times." + end + def index begin best @@ -68,10 +72,11 @@ class TweetsController < ApplicationController description "Returns the newest Tweets of a user, specified by username or user ID." param_group :user param_group :pagination_with_ids + param_group :threshold def timeline @user = require_user authorize_to_show_user! @user - @tweets = paginate(@user.tweets.reacted.order_by_id) + @tweets = paginate(@user.tweets.reacted(params[:reactions]).order_by_id) end get "tweets/discoveries" @@ -137,8 +142,9 @@ class TweetsController < ApplicationController get "tweets/all_timeline" nodoc param_group :pagination_with_ids + param_group :threshold def all_timeline - @tweets = paginate(Tweet.reacted.order_by_id) + @tweets = paginate(Tweet.reacted(params[:reactions]).order_by_id) end get "tweets/filter" diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 0dfe47a..c9c9c14 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -12,7 +12,7 @@ class Tweet < ActiveRecord::Base has_many :retweeters, -> { order("retweets.id") }, through: :retweets, source: :user scope :recent, ->(days = 3) { where("tweets.id > ?", snowflake_min(Time.zone.now - days.days)) } - scope :reacted, -> { where.not(reactions_count: 0) } + scope :reacted, ->(count = nil) { where("reactions_count >= ?", [count.to_i, 1].max) } scope :not_protected, -> { includes(:user).where(users: {protected: false}) } scope :max_id, -> id { where("tweets.id <= ?", id.to_i) if id } diff --git a/app/views/tweets/_timeline_thresholds.html.haml b/app/views/tweets/_timeline_thresholds.html.haml new file mode 100644 index 0000000..785cad2 --- /dev/null +++ b/app/views/tweets/_timeline_thresholds.html.haml @@ -0,0 +1,7 @@ +.thresholds + .btn-group + - counts.sort.each do |c| + - if [params[:reactions].to_i, 1].max == c + %button.btn.btn-default.active{type: "button"}= "#{c} acts" + - else + = link_to "#{c} acts", params.merge(reactions: c), class: "btn btn-default" diff --git a/app/views/tweets/_tweet.html.haml b/app/views/tweets/_tweet.html.haml index 875c9b8..1b62911 100644 --- a/app/views/tweets/_tweet.html.haml +++ b/app/views/tweets/_tweet.html.haml @@ -1,6 +1,6 @@ .tweet - unless authorized_to_show_user? tweet.user - .tweet + .content .left .avatar = image_tag "missing_profile_image.png", alt: "protected", title: "protected user" @@ -25,7 +25,7 @@ %span.count= count %span.type= title - else - .tweet + .content .left .avatar = link_to user_path(tweet.user_screen_name) do diff --git a/app/views/tweets/all_timeline.html.haml b/app/views/tweets/all_timeline.html.haml index 3ee3b23..4fa088a 100644 --- a/app/views/tweets/all_timeline.html.haml +++ b/app/views/tweets/all_timeline.html.haml @@ -1,4 +1,5 @@ - title "Newest" - caption :title - sidebar :i += render "timeline_thresholds", counts: [1, 10, 50, 100, 500, 1000] = render @tweets diff --git a/app/views/tweets/timeline.html.haml b/app/views/tweets/timeline.html.haml index c326087..17e385a 100644 --- a/app/views/tweets/timeline.html.haml +++ b/app/views/tweets/timeline.html.haml @@ -1,4 +1,5 @@ - title @user.screen_name + "'s Newest" - caption :title - sidebar :users += render "timeline_thresholds", counts: [1, 3, 10, 30, 50] = render @tweets |