mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
fix derps
This commit is contained in:
parent
b655654acb
commit
884b5d4972
2 changed files with 19 additions and 4 deletions
|
@ -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
|
||||||
|
|
|
@ -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.")
|
||||||
|
|
Loading…
Reference in a new issue