philomena/lib/philomena_web/controllers/conversation/hide_controller.ex

37 lines
1,005 B
Elixir
Raw Normal View History

2019-12-08 00:24:37 +01:00
defmodule PhilomenaWeb.Conversation.HideController do
use PhilomenaWeb, :controller
alias Philomena.Conversations.Conversation
alias Philomena.Conversations
plug PhilomenaWeb.CanaryMapPlug, create: :show, delete: :show
2020-01-11 05:20:19 +01:00
plug :load_and_authorize_resource,
model: Conversation,
id_field: "slug",
id_name: "conversation_id",
persisted: true
2019-12-08 00:24:37 +01:00
def create(conn, _params) do
conversation = conn.assigns.conversation
user = conn.assigns.current_user
{:ok, _conversation} = Conversations.mark_conversation_hidden(conversation, user)
conn
|> put_flash(:info, "Conversation hidden.")
2024-06-06 22:28:35 +02:00
|> redirect(to: ~p"/conversations")
2019-12-08 00:24:37 +01:00
end
def delete(conn, _params) do
conversation = conn.assigns.conversation
user = conn.assigns.current_user
{:ok, _conversation} = Conversations.mark_conversation_hidden(conversation, user, false)
conn
|> put_flash(:info, "Conversation restored.")
2024-06-06 22:28:35 +02:00
|> redirect(to: ~p"/conversations/#{conversation}")
2019-12-08 00:24:37 +01:00
end
2020-01-11 05:20:19 +01:00
end