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:
dtluna 2017-04-20 10:39:18 +03:00
commit d952b6cd7b
3 changed files with 20 additions and 14 deletions

View file

@ -108,9 +108,9 @@ def fetch_status(user, id) do
end
end
def follow(%User{} = follower, followed_id) do
with %User{} = followed <- Repo.get(User, followed_id),
{ :ok, follower } <- User.follow(follower, followed),
def follow(%User{} = follower, params) do
with { :ok, %User{} = followed } <- get_user(params),
{ :ok, follower } <- User.follow(follower, followed),
{ :ok, activity } <- ActivityPub.insert(%{
"type" => "Follow",
"actor" => follower.ap_id,
@ -259,7 +259,7 @@ def register_user(params) do
end
end
def get_user(user, params) do
def get_user(user \\ nil, params) do
case params do
%{ "user_id" => user_id } ->
case target = Repo.get(User, user_id) do

View file

@ -57,8 +57,8 @@ def user_timeline(%{assigns: %{user: user}} = conn, params) do
end
end
def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
case TwitterAPI.follow(user, followed_id) do
def follow(%{assigns: %{user: user}} = conn, params) do
case TwitterAPI.follow(user, params) do
{ :ok, user, followed, _activity } ->
response = followed |> UserRepresenter.to_json(%{for: user})
conn

View file

@ -144,19 +144,25 @@ test "fetch a single status" do
assert status == ActivityRepresenter.to_map(activity, %{for: user, user: actor})
end
test "Follow another user" do
test "Follow another user using user_id" do
user = insert(:user)
followed = insert(:user)
{ :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
user = Repo.get(User, user.id)
follow = Repo.get(Activity, activity.id)
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
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."
end