aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlambda <lain@soykaf.club>2019-04-15 10:24:37 +0000
committerlambda <lain@soykaf.club>2019-04-15 10:24:37 +0000
commitf358295cbe8f1d250e92dcc9265cdc83cb2cabdd (patch)
tree5155bfdb8bfbb664b139100d8175fa35e6092765 /lib
parentf896699357fc7ba05fd539396bf22818d8bd98b4 (diff)
parent27d78dc5265ea90724c698162c24290ba1b99e13 (diff)
downloadpleroma-f358295cbe8f1d250e92dcc9265cdc83cb2cabdd.tar.gz
Merge branch 'unfollow-oneself' into 'develop'
Consistent response for self follow/unfollow Closes #819 See merge request pleroma/pleroma!1061
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index e0a090659..63fadce38 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -815,13 +815,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
- with %User{} = 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
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: follower, target: followed})
else
+ {:followed, _} ->
+ {:error, :not_found}
+
true ->
followed = User.get_cached_by_id(id)
@@ -843,12 +847,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
- with %User{} = 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
|> put_view(AccountView)
|> render("account.json", %{user: followed, for: follower})
else
+ {:followed, _} ->
+ {:error, :not_found}
+
{:error, message} ->
conn
|> put_resp_content_type("application/json")
@@ -857,11 +865,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
- with %User{} = 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
|> put_view(AccountView)
|> render("relationship.json", %{user: follower, target: followed})
+ else
+ {:followed, _} ->
+ {:error, :not_found}
+
+ error ->
+ error
end
end