mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
set name_at_post_time more explicitly
This commit is contained in:
parent
623b2b486f
commit
92d53f6450
3 changed files with 9 additions and 11 deletions
|
@ -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`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue