diff options
author | rhenium <rhenium@rhe.jp> | 2015-04-05 15:58:03 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2015-04-05 15:58:03 +0900 |
commit | a1812b253efdc1b06dba4ef59b6c3dcc8ef22c54 (patch) | |
tree | 558bb10f0bdf4b0b7b50916a5c3aa5c5e80db21c /app/models/tweet.rb | |
parent | e3d1ef82877f8bbeb6c2e9d6499fdd5ecbc40c94 (diff) | |
download | aclog-a1812b253efdc1b06dba4ef59b6c3dcc8ef22c54.tar.gz |
web: reorganize views
Diffstat (limited to 'app/models/tweet.rb')
-rw-r--r-- | app/models/tweet.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 5b58c07..9877d5a 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -24,6 +24,15 @@ class Tweet < ActiveRecord::Base scope :favorited_by, ->(user) { joins(:favorites).where(favorites: { user: user }) } + scope :paginate, ->(params) { + page_per = [(params[:count] || Settings.tweets.count.default).to_i, Settings.tweets.count.max].min + if params[:page] + page([params[:page].to_i, 1].max, page_per) + else + limit(page_per).max_id(params[:max_id]).since_id(params[:since_id]) + 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. @@ -73,8 +82,8 @@ class Tweet < ActiveRecord::Base # @param [Integer] id Target status ID. # @param [Account] client The Twitter::REST::Client to be used. # @return [Tweet] The Tweet instance imported. - def import_from_twitter(id, account = nil) - client = (account || Account.random).client + def import_from_twitter(id, current_user = nil) + client = (current_user ? current_user.account : Account.random).client st = client.status(id) st = st.retweeted_status if st.retweet? |