Clear deleted posts and topics from listings

This commit is contained in:
byte[] 2023-04-20 14:02:24 -04:00
parent e2c94dda6c
commit b513e66578
2 changed files with 31 additions and 2 deletions

View file

@ -222,11 +222,23 @@ defmodule Philomena.Posts do
|> select([r], r.id)
|> update(set: [open: false, state: "closed", admin_id: ^user.id])
topics =
Topic
|> where(last_post_id: ^post.id)
|> update(set: [last_post_id: nil])
forums =
Forum
|> where(last_post_id: ^post.id)
|> update(set: [last_post_id: nil])
post = Post.hide_changeset(post, attrs, user)
Multi.new()
|> Multi.update(:post, post)
|> Multi.update_all(:reports, reports, [])
|> Multi.update_all(:topics, topics, [])
|> Multi.update_all(:forums, forums, [])
|> Repo.transaction()
|> case do
{:ok, %{post: post, reports: {_count, reports}}} ->

View file

@ -268,8 +268,25 @@ defmodule Philomena.Topics do
end
def hide_topic(topic, deletion_reason, user) do
Topic.hide_changeset(topic, deletion_reason, user)
|> Repo.update()
topic_changes = Topic.hide_changeset(topic, deletion_reason, user)
forums =
Forum
|> join(:inner, [f], _ in assoc(f, :last_post))
|> where([f, p], p.topic_id == ^topic.id)
|> update(set: [last_post_id: nil])
Multi.new()
|> Multi.update(:topic, topic_changes)
|> Multi.update_all(:forums, forums, [])
|> Repo.transaction()
|> case do
{:ok, %{topic: topic}} ->
{:ok, topic}
error ->
error
end
end
def unhide_topic(topic) do