Add "flagger:" and "appealer:" metatags (fixes #3142)

This commit is contained in:
Type-kun
2017-06-13 00:15:49 +05:00
parent 04ef575704
commit 5d4592e0e0
2 changed files with 75 additions and 3 deletions

View File

@@ -236,6 +236,44 @@ class PostQueryBuilder
has_constraints!
end
if q[:flagger_ids_neg]
q[:flagger_ids_neg].each do |flagger_id|
relation = relation.where("posts.id NOT IN (?)", PostFlag.unscoped.search({:creator_id => flagger_id, :category => "normal"}).reorder("").select(:post_id).distinct)
end
end
if q[:flagger_ids]
q[:flagger_ids].each do |flagger_id|
if flagger_id == "any"
relation = relation.where('EXISTS (' + PostFlag.unscoped.search({:category => "normal"}).where('post_id = posts.id').reorder('').select('1').to_sql + ')')
elsif flagger_id == "none"
relation = relation.where('NOT EXISTS (' + PostFlag.unscoped.search({:category => "normal"}).where('post_id = posts.id').reorder('').select('1').to_sql + ')')
else
relation = relation.where("posts.id IN (?)", PostFlag.unscoped.search({:creator_id => flagger_id, :category => "normal"}).reorder("").select(:post_id).distinct)
end
end
has_constraints!
end
if q[:appealer_ids_neg]
q[:appealer_ids_neg].each do |appealer_id|
relation = relation.where("posts.id NOT IN (?)", PostAppeal.unscoped.where(creator_id: appealer_id).select(:post_id).distinct)
end
end
if q[:appealer_ids]
q[:appealer_ids].each do |appealer_id|
if appealer_id == "any"
relation = relation.where('EXISTS (' + PostAppeal.unscoped.where('post_id = posts.id').select('1').to_sql + ')')
elsif appealer_id == "none"
relation = relation.where('NOT EXISTS (' + PostAppeal.unscoped.where('post_id = posts.id').select('1').to_sql + ')')
else
relation = relation.where("posts.id IN (?)", PostAppeal.unscoped.where(creator_id: appealer_id).select(:post_id).distinct)
end
end
has_constraints!
end
if q[:commenter_ids]
q[:commenter_ids].each do |commenter_id|
if commenter_id == "any"

View File

@@ -1,7 +1,7 @@
class Tag < ActiveRecord::Base
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm"
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
attr_accessible :is_locked, :as => [:moderator, :admin]
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
@@ -442,7 +442,7 @@ class Tag < ActiveRecord::Base
when "approver"
if $2 == "none"
q[:approver_id] = "none"
q[:approver_id] = "none"
elsif $2 == "any"
q[:approver_id] = "any"
else
@@ -450,6 +450,40 @@ class Tag < ActiveRecord::Base
q[:approver_id] = user_id unless user_id.blank?
end
when "flagger"
q[:flagger_ids] ||= []
if $2 == "none"
q[:flagger_ids] << "none"
elsif $2 == "any"
q[:flagger_ids] << "any"
else
user_id = User.name_to_id($2)
q[:flagger_ids] << user_id unless user_id.blank?
end
when "-flagger"
q[:flagger_ids_neg] ||= []
user_id = User.name_to_id($2)
q[:flagger_ids_neg] << user_id unless user_id.blank?
when "appealer"
q[:appealer_ids] ||= []
if $2 == "none"
q[:appealer_ids] << "none"
elsif $2 == "any"
q[:appealer_ids] << "any"
else
user_id = User.name_to_id($2)
q[:appealer_ids] << user_id unless user_id.blank?
end
when "-appealer"
q[:appealer_ids_neg] ||= []
user_id = User.name_to_id($2)
q[:appealer_ids_neg] << user_id unless user_id.blank?
when "commenter", "comm"
q[:commenter_ids] ||= []