Merge branch 'feature/unfollow-by-screen-name' of ssh.gitgud.io:dtluna/pleroma into feature/follow-unfollow-by-screen-name
This commit is contained in:
commit
01901d9835
|
@ -124,7 +124,7 @@ def follow(%User{} = follower, params) do
|
|||
end
|
||||
end
|
||||
|
||||
def unfollow(%User{} = follower, followed_id) do
|
||||
def unfollow(%User{} = follower, %{ "user_id" => followed_id }) do
|
||||
with %User{} = followed <- Repo.get(User, followed_id),
|
||||
{ :ok, follower } <- User.unfollow(follower, followed)
|
||||
do
|
||||
|
@ -134,6 +134,14 @@ def unfollow(%User{} = follower, followed_id) do
|
|||
end
|
||||
end
|
||||
|
||||
def unfollow(%User{} = follower, %{ "screen_name" => followed_name }) do
|
||||
with %User{} = followed <- Repo.get_by(User, nickname: followed_name),
|
||||
{ :ok, follower } <- User.unfollow(follower, followed)
|
||||
do
|
||||
{ :ok, follower, followed }
|
||||
end
|
||||
end
|
||||
|
||||
def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do
|
||||
object = Object.get_by_ap_id(object["id"])
|
||||
|
||||
|
|
|
@ -67,11 +67,10 @@ def follow(%{assigns: %{user: user}} = conn, params) do
|
|||
end
|
||||
end
|
||||
|
||||
def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
||||
case TwitterAPI.unfollow(user, followed_id) do
|
||||
{ :ok, user, followed } ->
|
||||
response = followed |> UserRepresenter.to_json(%{for: user})
|
||||
|
||||
def unfollow(%{assigns: %{user: user}} = conn, params) do
|
||||
case TwitterAPI.unfollow(user, params) do
|
||||
{ :ok, user, unfollowed, } ->
|
||||
response = unfollowed |> UserRepresenter.to_json(%{for: user})
|
||||
conn
|
||||
|> json_reply(200, response)
|
||||
{ :error, msg } -> forbidden_json_reply(conn, msg)
|
||||
|
|
|
@ -166,16 +166,25 @@ test "Follow another user using screen_name" do
|
|||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||
end
|
||||
|
||||
test "Unfollow another user" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
||||
{ :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
test "Unfollow another user using user_id" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert user.following == []
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, followed.id)
|
||||
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
test "Unfollow another user using screen_name" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert user.following == []
|
||||
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue