diff --git a/lib/philomena/conversations/conversation.ex b/lib/philomena/conversations/conversation.ex index 6e423ac2..19f05266 100644 --- a/lib/philomena/conversations/conversation.ex +++ b/lib/philomena/conversations/conversation.ex @@ -48,6 +48,7 @@ defmodule Philomena.Conversations.Conversation do |> set_slug() |> set_last_message() |> cast_assoc(:messages, with: {Message, :creation_changeset, [from]}) + |> validate_length(:messages, is: 1) end defp set_slug(changeset) do diff --git a/lib/philomena_web/controllers/conversation_controller.ex b/lib/philomena_web/controllers/conversation_controller.ex index 047d9cb7..7fcccc7a 100644 --- a/lib/philomena_web/controllers/conversation_controller.ex +++ b/lib/philomena_web/controllers/conversation_controller.ex @@ -62,11 +62,7 @@ defmodule PhilomenaWeb.ConversationController do render(conn, "new.html", changeset: changeset) end - # Somewhat annoying, cast_assoc has no "limit" validation so we force it - # here to require exactly 1 - def create(conn, %{"conversation" => %{"messages" => %{"0" => message_params} = messages_params} = conversation_params}) - when %{"0" => message_params} == messages_params - do + def create(conn, %{"conversation" => conversation_params}) do user = conn.assigns.current_user case Conversations.create_conversation(user, conversation_params) do