Skip to content

Commit

Permalink
Posts: Avoid blank pages due to deleted posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nottalulah committed Sep 17, 2024
1 parent c748684 commit c9998ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
24 changes: 21 additions & 3 deletions app/logical/post_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,28 @@ def aliases

# Implicit metatags are metatags added by the user's account settings. rating:g,s is implicit under safe mode.
def implicit_metatags
return [] unless safe_mode?
tags = []

tags = Danbooru.config.safe_mode_restricted_tags.map { |tag| -AST.tag(tag) }
[AST.metatag("rating", "g"), *tags]
if safe_mode?
tags = Danbooru.config.safe_mode_restricted_tags.map { |tag| -AST.tag(tag) }
[AST.metatag("rating", "g"), *tags]
end

unless show_deleted?
tags << AST.metatag("status", "deleted").-@
end

tags
end

def show_deleted?
current_user.show_deleted_posts? || has_status_metatag?
end

def has_status_metatag?
select_metatags("is", "status").any? do |metatag|
metatag.value.downcase.in?(%w[all any active unmoderated modqueue deleted appealed])
end
end

concerning :CountMethods do
Expand Down
12 changes: 1 addition & 11 deletions app/logical/post_sets/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Post
MAX_WILDCARD_TAGS = PostQueryBuilder::MAX_WILDCARD_TAGS

attr_reader :current_user, :page, :format, :tag_string, :post_query, :normalized_query, :show_votes, :add_extra_data_attributes
delegate :tag, to: :post_query
delegate :tag, :show_deleted?, to: :post_query
alias_method :show_votes?, :show_votes
alias_method :add_extra_data_attributes?, :add_extra_data_attributes

Expand Down Expand Up @@ -133,16 +133,6 @@ def best_post
posts.reject(&:is_deleted).select(&:visible?).max_by { |post| [-post.rating_id, post.score] }
end

def show_deleted?
current_user.show_deleted_posts? || has_status_metatag?
end

def has_status_metatag?
post_query.select_metatags("is", "status").any? do |metatag|
metatag.value.downcase.in?(%w[all any active unmoderated modqueue deleted appealed])
end
end

def banned_artist?
artist.present? && artist.is_banned? && !current_user.is_approver?
end
Expand Down

0 comments on commit c9998ec

Please sign in to comment.