Merge branch 'feature/follow-by-screen-name' of ssh.gitgud.io:dtluna/pleroma into feature/follow-unfollow-by-screen-name
This commit is contained in:
commit
d952b6cd7b
|
@ -108,9 +108,9 @@ def fetch_status(user, id) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%User{} = follower, followed_id) do
|
def follow(%User{} = follower, params) do
|
||||||
with %User{} = followed <- Repo.get(User, followed_id),
|
with { :ok, %User{} = followed } <- get_user(params),
|
||||||
{ :ok, follower } <- User.follow(follower, followed),
|
{ :ok, follower } <- User.follow(follower, followed),
|
||||||
{ :ok, activity } <- ActivityPub.insert(%{
|
{ :ok, activity } <- ActivityPub.insert(%{
|
||||||
"type" => "Follow",
|
"type" => "Follow",
|
||||||
"actor" => follower.ap_id,
|
"actor" => follower.ap_id,
|
||||||
|
@ -259,7 +259,7 @@ def register_user(params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_user(user, params) do
|
def get_user(user \\ nil, params) do
|
||||||
case params do
|
case params do
|
||||||
%{ "user_id" => user_id } ->
|
%{ "user_id" => user_id } ->
|
||||||
case target = Repo.get(User, user_id) do
|
case target = Repo.get(User, user_id) do
|
||||||
|
|
|
@ -57,8 +57,8 @@ def user_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
def follow(%{assigns: %{user: user}} = conn, params) do
|
||||||
case TwitterAPI.follow(user, followed_id) do
|
case TwitterAPI.follow(user, params) do
|
||||||
{ :ok, user, followed, _activity } ->
|
{ :ok, user, followed, _activity } ->
|
||||||
response = followed |> UserRepresenter.to_json(%{for: user})
|
response = followed |> UserRepresenter.to_json(%{for: user})
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -144,19 +144,25 @@ test "fetch a single status" do
|
||||||
assert status == ActivityRepresenter.to_map(activity, %{for: user, user: actor})
|
assert status == ActivityRepresenter.to_map(activity, %{for: user, user: actor})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Follow another user" do
|
test "Follow another user using user_id" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
followed = insert(:user)
|
followed = insert(:user)
|
||||||
|
|
||||||
{ :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
|
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
|
||||||
follow = Repo.get(Activity, activity.id)
|
|
||||||
|
|
||||||
assert user.following == [User.ap_followers(followed)]
|
assert user.following == [User.ap_followers(followed)]
|
||||||
assert follow == activity
|
|
||||||
|
|
||||||
{ :error, msg } = TwitterAPI.follow(user, followed.id)
|
{ :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||||
|
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Follow another user using screen_name" do
|
||||||
|
user = insert(:user)
|
||||||
|
followed = insert(:user)
|
||||||
|
|
||||||
|
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||||
|
assert user.following == [User.ap_followers(followed)]
|
||||||
|
|
||||||
|
{ :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue