Several fixes for the "This tag is under discussion" notice on the post index page: * Fix the notice appearing for BURs that aren't pending. * Fix the notice never going away because of the cache never expiring. * List all topics when a tag is involved in multiple BURs. * Link to the forum post instead of the forum topic (fix #4421). * Optimization: don't check for BURs when the search isn't a simple single tag search. * Add a `tags` field to the bulk update requests table for tracking all tags involved in the request (excluding tags in mass updates that are negated/optional/wildcards). Known issue: doesn't handle tag type prefixes in mass updates correctly (e.g. `mass update foo -> artist:bar` doesn't detect the tag `bar`). * Allow searching the /bulk_update_requests page by tags. We don't really need to cache the notice here, but we do it anyway to reduce queries on the post index page.
72 lines
2.3 KiB
Ruby
72 lines
2.3 KiB
Ruby
module PostsHelper
|
|
def post_previews_html(posts, **options)
|
|
posts.map do |post|
|
|
PostPresenter.preview(post, **options)
|
|
end.join("").html_safe
|
|
end
|
|
|
|
def post_search_counts_enabled?
|
|
Danbooru.config.enable_post_search_counts && Danbooru.config.reportbooru_server.present? && Danbooru.config.reportbooru_key.present?
|
|
end
|
|
|
|
def discover_mode?
|
|
params[:tags] =~ /order:rank/ || params[:action] =~ /searches|viewed/
|
|
end
|
|
|
|
def missed_post_search_count_js
|
|
return unless post_search_counts_enabled?
|
|
return unless params[:ms] == "1" && @post_set.post_count == 0 && @post_set.query.is_single_term?
|
|
|
|
sig = generate_reportbooru_signature(params[:tags])
|
|
render "posts/partials/index/missed_search_count", sig: sig
|
|
end
|
|
|
|
def post_search_count_js
|
|
return unless post_search_counts_enabled?
|
|
return unless params[:action] == "index" && params[:page].nil? && params[:tags].present?
|
|
|
|
tags = PostQueryBuilder.new(params[:tags]).normalize_query
|
|
sig = generate_reportbooru_signature("ps-#{tags}")
|
|
render "posts/partials/index/search_count", sig: sig
|
|
end
|
|
|
|
def post_view_count_js
|
|
return unless post_search_counts_enabled?
|
|
|
|
msg = generate_reportbooru_signature(params[:id])
|
|
render "posts/partials/show/view_count", msg: msg
|
|
end
|
|
|
|
def generate_reportbooru_signature(value)
|
|
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.reportbooru_key, serializer: JSON, digest: "SHA256")
|
|
verifier.generate("#{value},#{session[:session_id]}")
|
|
end
|
|
|
|
def post_source_tag(source, normalized_source = source)
|
|
# Only allow http:// and https:// links. Disallow javascript: links.
|
|
if source =~ %r!\Ahttps?://!i
|
|
external_link_to(normalized_source, strip: :subdomain) + " ".html_safe + link_to("»", source, rel: "external noreferrer nofollow")
|
|
else
|
|
source
|
|
end
|
|
end
|
|
|
|
def post_favlist(post)
|
|
post.favorited_users.reverse_each.map {|user| link_to_user(user)}.join(", ").html_safe
|
|
end
|
|
|
|
def is_pool_selected?(pool)
|
|
return false if params.key?(:q)
|
|
return false if params.key?(:favgroup_id)
|
|
return false if !params.key?(:pool_id)
|
|
return params[:pool_id].to_i == pool.id
|
|
end
|
|
|
|
private
|
|
|
|
def nav_params_for(page)
|
|
query_params = params.except(:controller, :action, :id).merge(page: page).permit!
|
|
{ params: query_params }
|
|
end
|
|
end
|