diff options
author | re4k <re4k@re4k.info> | 2013-04-04 03:07:35 +0900 |
---|---|---|
committer | re4k <re4k@re4k.info> | 2013-04-04 03:07:35 +0900 |
commit | 61dde16fd55babd2ccf5ff6a9c8be1f600868d9b (patch) | |
tree | af4e6f14ad16f87e911426e950ff1d72128f8328 /app/controllers | |
parent | 1b49426b0c935a44262384acb526e5fbb86598c7 (diff) | |
download | aclog-61dde16fd55babd2ccf5ff6a9c8be1f600868d9b.tar.gz |
Add repoting copied tweets form
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 17 | ||||
-rw-r--r-- | app/controllers/i_controller.rb | 18 | ||||
-rw-r--r-- | app/controllers/report_controller.rb | 69 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 21 |
5 files changed, 100 insertions, 29 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 25c9e2b..50d1761 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -29,7 +29,14 @@ class ApplicationController < ActionController::Base end end - def render_tweets(a = nil, &blk) + def render_page(a = nil, &blk) + @items = (a || blk.call).page(page || 1).per(count) + @page_param = true + + render "shared/tweets" + end + + def render_timeline(a = nil, &blk) @items = a || blk.call if max_id @@ -40,7 +47,7 @@ class ApplicationController < ActionController::Base @items = @items.where("tweets.id > ?", since_id) end - @items = @items.page(page || 1).per(count) + @items = @items.page(1).per(count) render "shared/tweets" end @@ -64,9 +71,9 @@ class ApplicationController < ActionController::Base end end - def all - get_bool(params[:all]) - end + def all; get_bool(params[:all]) end + + def full; get_bool(params[:full]) end private def get_bool(str) diff --git a/app/controllers/i_controller.rb b/app/controllers/i_controller.rb index 59b71e8..89a887c 100644 --- a/app/controllers/i_controller.rb +++ b/app/controllers/i_controller.rb @@ -1,39 +1,31 @@ class IController < ApplicationController def best @title = "Best Tweets" - render_tweets do + render_page do Tweet .reacted .order_by_reactions + .original end end def recent @title = "Recent Best Tweets" - render_tweets do + render_page do Tweet .recent .reacted .order_by_reactions + .original end end def timeline @title = "Public Timeline" - render_tweets do + render_timeline do Tweet .reacted .order_by_id end end - - def report - if request.post? - case params[:type] - when "steal" - # パクリツイート - - end - end - end end diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb new file mode 100644 index 0000000..e50e10d --- /dev/null +++ b/app/controllers/report_controller.rb @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +class ReportController < ApplicationController + layout "index" + def index + # いんでっくす + end + + def tweet + original_id, tweet_id = [get_tweet_id(params[:tweet_id_0]), get_tweet_id(params[:tweet_id_1])].sort + + unless original_id && tweet_id + # 何かがおかしいよ + raise ActionController::BadRequest + end + + tweet = Tweet.cached(tweet_id) + if tweet + original = Tweet.cached(original_id) + unless original + add_issue_stolen(false, tweet_id, original_id) + return + # 記録されてなかった + # どうしよう。どのアカウントのAPIを使うか? + end + + if original_id < tweet_id + if iscopy?(original, tweet) + # 両方記録されており、パクリツイート + logger.debug("pakuri!!!") + StolenTweet.register(original, tweet) + add_issue_stolen(true, tweet_id, original_id) + else + # パクリツイートではない(違う) + logger.debug("not pakuri!") + add_issue_stolen(false, tweet_id, original_id) + end + else + # パクリツイートではない(新しい) + logger.debug("not old, new") + end + else + # 記録されてないけど? + # 403 + logger.debug("not recorded?") + end + end + + private + def get_tweet_id(str) + case str + when /^(?:(?:https?:\/\/)?(?:(?:www\.)?twitter\.com|aclog\.koba789\.com)\/(?:i\/|[0-9A-Za-z_]{1,15}\/status(?:es)?\/))?(\d+)/ + $1.to_i + end + end + + def iscopy?(original, tweet) + textr = -> str do + str.gsub(/([ \t\n\r\f]|[\x20\x00-\x20\x0f])/, "") + end + + textr.call(original.text) == textr.call(tweet.text) + end + + def add_issue_stolen(resolved, tweet_id, original_id) + Issue.register(Aclog::Constants::IssueType::TWEET_STOLEN, + resolved ? Aclog::Constants::IssueStatus::RESOLVED : Aclog::Constants::IssueStatus::PENDING, + {:tweet_id => tweet_id, :original_id => original_id}) + end +end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 2777c0a..45f10b1 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -7,7 +7,7 @@ class SearchController < ApplicationController # TODO: OR とか () とか対応したいよね unless params[:query] - render_tweets(Tweet.where(:id => -1)) + render_page(Tweet.where(:id => -1)) return end words = Shellwords.shellwords(params[:query]) @@ -74,7 +74,7 @@ class SearchController < ApplicationController end end - render_tweets(result) + render_page(result) end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5005000..98a53d5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,7 +4,7 @@ class UsersController < ApplicationController def best @title = "@#{@user.screen_name}'s Best Tweets" - render_tweets do + render_page do case order when :favorite @user.tweets.reacted.order_by_favorites @@ -18,7 +18,7 @@ class UsersController < ApplicationController def recent @title = "@#{@user.screen_name}'s Recent Best Tweets" - render_tweets do + render_page do case order when :favorite @user.tweets.recent.reacted.order_by_favorites @@ -34,7 +34,7 @@ class UsersController < ApplicationController raise Aclog::Exceptions::UserProtected if @user.protected @title = "@#{@user.screen_name}'s Newest Tweets" - render_tweets do + render_timeline do if all @user.tweets.order_by_id else @@ -45,7 +45,7 @@ class UsersController < ApplicationController def discovered @title = "@#{@user.screen_name}'s Recent Discoveries" - render_tweets do + render_timeline do case params[:tweets] when /^fav/ Tweet.favorited_by(@user).order_by_id @@ -73,7 +73,7 @@ class UsersController < ApplicationController def favorited_by if @user_b @title = "@#{@user.screen_name}'s Tweets" - render_tweets(@user.tweets.favorited_by(@user_b).order_by_id) + render_timeline(@user.tweets.favorited_by(@user_b).order_by_id) else @title = "Who Favorited @#{@user.screen_name}" @event_type = "favs" @@ -84,7 +84,7 @@ class UsersController < ApplicationController def retweeted_by if @user_b @title = "@#{@user.screen_name}'s Tweets" - render_tweets(@user.tweets.retweeted_by(@user_b).order_by_id) + render_timeline(@user.tweets.retweeted_by(@user_b).order_by_id) else @title = "Who Retweeted @#{@user.screen_name}" @event_type = "retweets" @@ -95,7 +95,7 @@ class UsersController < ApplicationController def given_favorites_to if @user_b @title = "@#{@user_b.screen_name}'s Tweets" - render_tweets(@user_b.tweets.favorited_by(@user).order_by_id) + render_timeline(@user_b.tweets.favorited_by(@user).order_by_id) else @title = "@#{@user.screen_name}'s Favorites" @event_type = "favs" @@ -106,7 +106,7 @@ class UsersController < ApplicationController def given_retweets_to if @user_b @title = "@#{@user_b.screen_name}'s Tweets" - render_tweets(@user_b.tweets.retweeted_by(@user).order_by_id) + render_timeline(@user_b.tweets.retweeted_by(@user).order_by_id) else @title = "@#{@user.screen_name}'s Retweets" @event_type = "retweets" @@ -131,7 +131,10 @@ class UsersController < ApplicationController @title_b = "@#{@user.screen_name}'s Tweet" respond_to do |format| - format.html + format.html do + @full = full + end + format.json do render "shared/_tweet", :locals => {:item => @item} end |