aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/tweets_controller.rb10
-rw-r--r--app/models/tweet.rb2
-rw-r--r--app/views/tweets/_timeline_thresholds.html.haml7
-rw-r--r--app/views/tweets/all_timeline.html.haml1
-rw-r--r--app/views/tweets/timeline.html.haml1
-rw-r--r--config/routes.rb4
6 files changed, 20 insertions, 5 deletions
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/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
diff --git a/config/routes.rb b/config/routes.rb
index e43d793..0b6a1b0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -21,7 +21,7 @@ Aclog::Application.routes.draw do
get "/i/best" => "tweets#all_best", as: "best"
get "/i/recent" => "tweets#all_recent", as: "recent"
- get "/i/timeline" => "tweets#all_timeline", as: "timeline"
+ get "/i/timeline(/:reactions)" => "tweets#all_timeline", as: "timeline", constraints: { reactions: /\d+/ }
get "/i/filter" => "tweets#filter", as: "filter"
get "/about" => "about#about", as: "about"
@@ -34,7 +34,7 @@ Aclog::Application.routes.draw do
get "/" => "tweets#index", as: "user"
get "/best" => "tweets#best", as: "user_best"
get "/recent" => "tweets#recent", as: "user_recent"
- get "/timeline" => "tweets#timeline", as: "user_timeline"
+ get "/timeline(/:reactions)" => "tweets#timeline", as: "user_timeline", constraints: { reactions: /\d+/ }
get "/discoveries" => "tweets#discoveries", as: "user_discoveries"
get "/favorites" => "tweets#favorites", as: "user_favorites"
get "/retweets" => "tweets#retweets", as: "user_retweets"