From c30c8e3136c7213259d52c690e048427c756817a Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 23 Oct 2020 00:15:29 -0400 Subject: [PATCH] missing link to restore conversation (fixes philomena-dev/philomena#42) --- lib/philomena_web/templates/conversation/show.html.slime | 5 ++++- lib/philomena_web/views/conversation_view.ex | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/philomena_web/templates/conversation/show.html.slime b/lib/philomena_web/templates/conversation/show.html.slime index e5b98825..a8cd688b 100644 --- a/lib/philomena_web/templates/conversation/show.html.slime +++ b/lib/philomena_web/templates/conversation/show.html.slime @@ -16,7 +16,10 @@ h1 = @conversation.title => @messages.total_entries = pluralize("message", "messages", @messages.total_entries) = pagination - = link "Remove conversation", to: Routes.conversation_hide_path(@conn, :create, @conversation), data: [method: "post", confirm: "Are you really, really sure?"] + = if hidden_by?(@current_user, @conversation) do + = link "Restore conversation", to: Routes.conversation_hide_path(@conn, :delete, @conversation), data: [method: "delete"] + - else + = link "Remove conversation", to: Routes.conversation_hide_path(@conn, :create, @conversation), data: [method: "post", confirm: "Are you really, really sure?"] = link "Report conversation", to: Routes.conversation_report_path(@conn, :new, @conversation) = link "Mark as unread", to: Routes.conversation_read_path(@conn, :delete, @conversation), data: [method: "delete"] diff --git a/lib/philomena_web/views/conversation_view.ex b/lib/philomena_web/views/conversation_view.ex index 75e44293..4ce91283 100644 --- a/lib/philomena_web/views/conversation_view.ex +++ b/lib/philomena_web/views/conversation_view.ex @@ -16,6 +16,15 @@ defmodule PhilomenaWeb.ConversationView do def read_by?(_user, _conversation), do: false + def hidden_by?(%{id: user_id}, %{to_id: user_id} = conversation), + do: conversation.to_hidden + + def hidden_by?(%{id: user_id}, %{from_id: user_id} = conversation), + do: conversation.from_hidden + + def hidden_by?(_user, _conversation), + do: false + def conversation_class(user, conversation) do case read_by?(user, conversation) do false -> "warning"