From 92d53f6450ebfb72264db8541295de40b95a02dc Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 18 Nov 2019 22:58:21 -0500 Subject: [PATCH] set name_at_post_time more explicitly --- README.md | 2 ++ lib/philomena/comments/comment.ex | 8 +++----- lib/philomena/posts/post.ex | 10 ++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 89306a94..ae1eb291 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/philomena/comments/comment.ex b/lib/philomena/comments/comment.ex index a59c2deb..e6397738 100644 --- a/lib/philomena/comments/comment.ex +++ b/lib/philomena/comments/comment.ex @@ -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 diff --git a/lib/philomena/posts/post.ex b/lib/philomena/posts/post.ex index c140fbe5..d463df28 100644 --- a/lib/philomena/posts/post.ex +++ b/lib/philomena/posts/post.ex @@ -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