Use User.get_cached_by*
This commit is contained in:
parent
507e7821e3
commit
27d78dc526
2 changed files with 5 additions and 5 deletions
|
@ -815,7 +815,7 @@ def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) d
|
|||
end
|
||||
|
||||
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||
with {_, %User{} = followed} <- {:followed, User.get_by_id(id)},
|
||||
with {_, %User{} = followed} <- {:followed, User.get_cached_by_id(id)},
|
||||
{_, true} <- {:followed, follower.id != followed.id},
|
||||
false <- User.following?(follower, followed),
|
||||
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
||||
|
@ -847,7 +847,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
|||
end
|
||||
|
||||
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
||||
with {_, %User{} = followed} <- {:followed, User.get_by_nickname(uri)},
|
||||
with {_, %User{} = followed} <- {:followed, User.get_cached_by_nickname(uri)},
|
||||
{_, true} <- {:followed, follower.id != followed.id},
|
||||
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
||||
conn
|
||||
|
@ -865,7 +865,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
|||
end
|
||||
|
||||
def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||
with {_, %User{} = followed} <- {:followed, User.get_by_id(id)},
|
||||
with {_, %User{} = followed} <- {:followed, User.get_cached_by_id(id)},
|
||||
{_, true} <- {:followed, follower.id != followed.id},
|
||||
{:ok, follower} <- CommonAPI.unfollow(follower, followed) do
|
||||
conn
|
||||
|
|
|
@ -1599,12 +1599,12 @@ test "following / unfollowing errors" do
|
|||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# self unfollow
|
||||
user = User.get_by_id(user.id)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# self follow via uri
|
||||
user = User.get_by_id(user.id)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
|
|
Loading…
Reference in a new issue