diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d1267d1db..270e36666 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -27,8 +27,11 @@ class PostsController < ApplicationController @comments = @comments.visible(CurrentUser.user) include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children? - @parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => include_deleted) - @children_post_set = PostSets::PostRelationship.new(@post.id, :include_deleted => include_deleted) + @sibling_posts = @post.parent.present? ? @post.parent.children : Post.none + @sibling_posts = @sibling_posts.undeleted unless include_deleted + + @child_posts = @post.children + @child_posts = @child_posts.undeleted unless include_deleted respond_with(@post) do |format| format.html.tooltip { render layout: false } diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index a8052afb0..7e3a2ffb4 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -1,4 +1,10 @@ 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 @@ -63,45 +69,6 @@ module PostsHelper post.favorited_users.reverse_each.map {|user| link_to_user(user)}.join(", ").html_safe end - def has_parent_message(post, parent_post_set) - html = "" - - html << "This post belongs to a " - html << link_to("parent", posts_path(:tags => "parent:#{post.parent_id}")) - html << " (deleted)" if parent_post_set.parent.first.is_deleted? - - sibling_count = parent_post_set.children.count - 1 - if sibling_count > 0 - html << " and has " - text = (sibling_count == 1) ? "a sibling" : "#{sibling_count} siblings" - html << link_to(text, posts_path(:tags => "parent:#{post.parent_id}")) - end - - html << " (#{link_to_wiki "learn more", "help:post_relationships"}) " - - html << link_to("« hide".html_safe, "#", :id => "has-parent-relationship-preview-link") - - html.html_safe - end - - def has_children_message(post, children_post_set) - html = "" - - html << "This post has " - text = (children_post_set.children.count == 1) ? "a child" : "#{children_post_set.children.count} children" - html << link_to(text, posts_path(:tags => "parent:#{post.id}")) - - html << " (#{link_to_wiki "learn more", "help:post_relationships"}) " - - html << link_to("« hide".html_safe, "#", :id => "has-children-relationship-preview-link") - - html.html_safe - end - - def pool_link(pool) - render("posts/partials/show/pool_link", post: @post, pool: pool) - end - def is_pool_selected?(pool) return false if params.key?(:q) return false if params.key?(:favgroup_id) diff --git a/app/logical/post_sets/post_relationship.rb b/app/logical/post_sets/post_relationship.rb deleted file mode 100644 index 2cd085590..000000000 --- a/app/logical/post_sets/post_relationship.rb +++ /dev/null @@ -1,24 +0,0 @@ -module PostSets - class PostRelationship < PostSets::Post - attr_reader :parent, :children - - def initialize(parent_id, options = {}) - @parent = ::Post.where("id = ?", parent_id) - @children = ::Post.where("parent_id = ?", parent_id).order("id ASC") - if options[:include_deleted] - super("parent:#{parent_id} status:any") - else - @children = @children.where("is_deleted = ?", false) - super("parent:#{parent_id}") - end - end - - def posts - @parent + @children - end - - def presenter - ::PostSetPresenters::Post.new(self) - end - end -end diff --git a/app/models/post.rb b/app/models/post.rb index e9b6b25c4..f7c736ae6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1239,10 +1239,6 @@ class Post < ApplicationRecord end end - def parent_exists? - Post.exists?(parent_id) - end - def has_visible_children? return true if has_active_children? return true if has_children? && CurrentUser.user.show_deleted_children? diff --git a/app/views/posts/partials/show/_child_notice.html.erb b/app/views/posts/partials/show/_child_notice.html.erb new file mode 100644 index 000000000..c363b9c4c --- /dev/null +++ b/app/views/posts/partials/show/_child_notice.html.erb @@ -0,0 +1,8 @@ +This post has <%= link_to pluralize(children.length, "child"), posts_path(tags: "parent:#{parent.id}") %> + +(<%= link_to_wiki "learn more", "help:post_relationships" %>) +<%= link_to("« hide", "#", id: "has-children-relationship-preview-link") %> + +