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 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||||||
end
|
end
|
||||||
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),
|
with %User{} = followed <- Repo.get(User, followed_id),
|
||||||
{ :ok, follower } <- User.unfollow(follower, followed)
|
{ :ok, follower } <- User.unfollow(follower, followed)
|
||||||
do
|
do
|
||||||
@ -134,6 +134,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||||||
end
|
end
|
||||||
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
|
def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do
|
||||||
object = Object.get_by_ap_id(object["id"])
|
object = Object.get_by_ap_id(object["id"])
|
||||||
|
|
||||||
|
@ -67,11 +67,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
def unfollow(%{assigns: %{user: user}} = conn, params) do
|
||||||
case TwitterAPI.unfollow(user, followed_id) do
|
case TwitterAPI.unfollow(user, params) do
|
||||||
{ :ok, user, followed } ->
|
{ :ok, user, unfollowed, } ->
|
||||||
response = followed |> UserRepresenter.to_json(%{for: user})
|
response = unfollowed |> UserRepresenter.to_json(%{for: user})
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
{ :error, msg } -> forbidden_json_reply(conn, msg)
|
{ :error, msg } -> forbidden_json_reply(conn, msg)
|
||||||
|
@ -166,16 +166,25 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Unfollow another user" do
|
test "Unfollow another user using user_id" do
|
||||||
followed = insert(:user)
|
unfollowed = insert(:user)
|
||||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||||
|
|
||||||
{ :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
|
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
|
||||||
|
|
||||||
|
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||||
assert user.following == []
|
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!"
|
assert msg == "Not subscribed!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user