aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-01-23 23:34:30 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-01-23 23:34:30 +0900
commit841e9796cdeda4288675a3df7b2e984454698a49 (patch)
tree494e7071b4efcf4d9ca999e718edaaa04475afab /app/models
parentc3d4489f007ecd22328c90e4dbcf873776014735 (diff)
downloadaclog-841e9796cdeda4288675a3df7b2e984454698a49.tar.gz
web: get rid of page=x in user/public best
Diffstat (limited to 'app/models')
-rw-r--r--app/models/tweet.rb14
1 files changed, 2 insertions, 12 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb
index 9dbb289..ba39f78 100644
--- a/app/models/tweet.rb
+++ b/app/models/tweet.rb
@@ -17,24 +17,14 @@ class Tweet < ActiveRecord::Base
scope :max_id, ->(id) { where("tweets.id <= ?", id.to_i) if id }
scope :since_id, ->(id) { where("tweets.id > ?", id.to_i) if id }
+ scope :not_reacted_than, ->(last_count, last_id) { where("reactions_count < ? OR (reactions_count = ? AND id < ?)", last_count, last_count, last_id) if last_count }
scope :page, ->(page, page_per) { limit(page_per).offset((page - 1) * page_per) }
scope :order_by_id, -> { order(id: :desc) }
- scope :order_by_reactions, -> { order(reactions_count: :desc) }
+ scope :order_by_reactions, -> { order(reactions_count: :desc, id: :desc) }
scope :favorited_by, ->(user) { joins(:favorites).where(favorites: { user: user }) }
- # should be called in last
- scope :paginate, ->(params) {
- page_per = params[:count] ? [params[:count].to_i, Settings.tweets.count.max].min : Settings.tweets.count.default
-
- if !params[:page] && self.all.order_values.all? {|o| !o.is_a?(String) && o.expr.name == :id }
- limit(page_per).max_id(params[:max_id]).since_id(params[:since_id])
- else
- page([params[:page].to_i, 1].max, page_per)
- end
- }
-
class << self
# Builds a new instance of Tweet and initialize with JSON data from Twitter API.
# @note This method just builds an instance, doesn't save it.