fix derps

This commit is contained in:
Luna D 2022-03-24 19:01:38 +01:00
parent b655654acb
commit 884b5d4972
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
2 changed files with 19 additions and 4 deletions

View file

@ -7,6 +7,7 @@ defmodule Philomena.Conversations do
alias Ecto.Multi alias Ecto.Multi
alias Philomena.Repo alias Philomena.Repo
alias Philomena.Reports alias Philomena.Reports
alias Philomena.Reports.Report
alias Philomena.Conversations.Conversation alias Philomena.Conversations.Conversation
@doc """ @doc """
@ -207,7 +208,13 @@ defmodule Philomena.Conversations do
|> Repo.transaction() |> Repo.transaction()
end end
def approve_conversation_message(message) do def approve_conversation_message(message, user) do
reports_query =
Report
|> where(reportable_type: "Conversation", reportable_id: ^message.conversation_id)
|> select([r], r.id)
|> update(set: [open: false, state: "closed", admin_id: ^user.id])
message_query = message_query =
message message
|> Message.approve_changeset() |> Message.approve_changeset()
@ -216,12 +223,20 @@ defmodule Philomena.Conversations do
Conversation Conversation
|> where(id: ^message.conversation_id) |> where(id: ^message.conversation_id)
now = DateTime.utc_now()
Multi.new() Multi.new()
|> Multi.update(:message, message_query) |> Multi.update(:message, message_query)
|> Multi.update_all(:conversation, conversation_query, set: [to_read: false]) |> Multi.update_all(:conversation, conversation_query, set: [to_read: false])
|> Multi.update_all(:reports, reports_query, [])
|> Repo.transaction() |> Repo.transaction()
|> case do
{:ok, %{reports: {_count, reports}} = result} ->
Reports.reindex_reports(reports)
{:ok, result}
error ->
error
end
end end
def report_non_approved(id) do def report_non_approved(id) do

View file

@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Conversation.Message.ApproveController do
def create(conn, _params) do def create(conn, _params) do
message = conn.assigns.message message = conn.assigns.message
{:ok, _message} = Conversations.approve_conversation_message(message) {:ok, _message} = Conversations.approve_conversation_message(message, conn.assigns.current_user)
conn conn
|> put_flash(:info, "Conversation message approved.") |> put_flash(:info, "Conversation message approved.")