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
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 upload(%Plug.Upload{} = file) do
{:ok, object} = ActivityPub.upload(file)
|> json_reply(200, response)
end
- def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
- { :ok, user, follower } = TwitterAPI.unfollow(user, followed_id)
+ def unfollow(%{assigns: %{user: user}} = conn, params) do
+ { :ok, user, follower } = TwitterAPI.unfollow(user, params)
response = follower |> UserRepresenter.to_json(%{for: user})
assert follow == activity
end
- test "Unfollow another user" do
+ test "Unfollow another user using user_id" do
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
- {:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
+ {:ok, user, _following } = TwitterAPI.unfollow(user, %{"user_id" => following.id})
+
+ user = Repo.get(User, user.id)
+
+ assert user.following == []
+ end
+
+ test "Unfollow another user using screen_name" do
+ { :ok, following } = UserBuilder.insert(%{nickname: "guy"})
+ { :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
+
+ {:ok, user, _following } = TwitterAPI.unfollow(user, %{"screen_name" => following.nickname})
user = Repo.get(User, user.id)