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.
|
Next generation imageboard.
|
||||||
|
|
||||||
|
![](https://derpicdn.net/img/2019/8/23/2125268/full.png)
|
||||||
|
|
||||||
To start your Phoenix server:
|
To start your Phoenix server:
|
||||||
|
|
||||||
* Install dependencies with `mix deps.get`
|
* Install dependencies with `mix deps.get`
|
||||||
|
|
|
@ -37,7 +37,7 @@ defmodule Philomena.Comments.Comment do
|
||||||
|> validate_required([:body])
|
|> validate_required([:body])
|
||||||
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|
||||||
|> change(attribution)
|
|> change(attribution)
|
||||||
|> put_name_at_post_time()
|
|> put_name_at_post_time(attribution[:user])
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(comment, attrs) do
|
def changeset(comment, attrs) do
|
||||||
|
@ -48,8 +48,6 @@ defmodule Philomena.Comments.Comment do
|
||||||
|> validate_length(:edit_reason, max: 70, count: :bytes)
|
|> validate_length(:edit_reason, max: 70, count: :bytes)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_name_at_post_time(%{changes: %{user: %{data: %{name: name}}}} = changeset),
|
defp put_name_at_post_time(changeset, nil), do: changeset
|
||||||
do: change(changeset, name_at_post_time: name)
|
defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name)
|
||||||
defp put_name_at_post_time(changeset),
|
|
||||||
do: changeset
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,7 +46,7 @@ defmodule Philomena.Posts.Post do
|
||||||
|> validate_required([:body])
|
|> validate_required([:body])
|
||||||
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|
||||||
|> change(attribution)
|
|> change(attribution)
|
||||||
|> put_name_at_post_time()
|
|> put_name_at_post_time(attribution[:user])
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
|
@ -58,11 +58,9 @@ defmodule Philomena.Posts.Post do
|
||||||
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|
|> validate_length(:body, min: 1, max: 300_000, count: :bytes)
|
||||||
|> change(attribution)
|
|> change(attribution)
|
||||||
|> change(topic_position: 0)
|
|> change(topic_position: 0)
|
||||||
|> put_name_at_post_time()
|
|> put_name_at_post_time(attribution[:user])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_name_at_post_time(%{changes: %{user: %{data: %{name: name}}}} = changeset),
|
defp put_name_at_post_time(changeset, nil), do: changeset
|
||||||
do: change(changeset, name_at_post_time: name)
|
defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name)
|
||||||
defp put_name_at_post_time(changeset),
|
|
||||||
do: changeset
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue