set name_at_post_time more explicitly

This commit is contained in:
byte[] 2019-11-18 22:58:21 -05:00
parent 623b2b486f
commit 92d53f6450
3 changed files with 9 additions and 11 deletions

View file

@ -2,6 +2,8 @@
Next generation imageboard.
![](https://derpicdn.net/img/2019/8/23/2125268/full.png)
To start your Phoenix server:
* Install dependencies with `mix deps.get`

View file

@ -37,7 +37,7 @@ defmodule Philomena.Comments.Comment do
|> validate_required([:body])
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|> change(attribution)
|> put_name_at_post_time()
|> put_name_at_post_time(attribution[:user])
end
def changeset(comment, attrs) do
@ -48,8 +48,6 @@ defmodule Philomena.Comments.Comment do
|> validate_length(:edit_reason, max: 70, count: :bytes)
end
defp put_name_at_post_time(%{changes: %{user: %{data: %{name: name}}}} = changeset),
do: change(changeset, name_at_post_time: name)
defp put_name_at_post_time(changeset),
do: changeset
defp put_name_at_post_time(changeset, nil), do: changeset
defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name)
end

View file

@ -46,7 +46,7 @@ defmodule Philomena.Posts.Post do
|> validate_required([:body])
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|> change(attribution)
|> put_name_at_post_time()
|> put_name_at_post_time(attribution[:user])
end
@doc false
@ -58,11 +58,9 @@ defmodule Philomena.Posts.Post do
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|> change(attribution)
|> change(topic_position: 0)
|> put_name_at_post_time()
|> put_name_at_post_time(attribution[:user])
end
defp put_name_at_post_time(%{changes: %{user: %{data: %{name: name}}}} = changeset),
do: change(changeset, name_at_post_time: name)
defp put_name_at_post_time(changeset),
do: changeset
defp put_name_at_post_time(changeset, nil), do: changeset
defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name)
end