From: dtluna Date: Thu, 20 Apr 2017 07:46:27 +0000 (+0300) Subject: Merge branch 'feature/unfollow-by-screen-name' of ssh.gitgud.io:dtluna/pleroma into... X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=01901d9835113f35c67cf4c09cbe6530e96f4e79;p=akkoma Merge branch 'feature/unfollow-by-screen-name' of ssh.gitgud.io:dtluna/pleroma into feature/follow-unfollow-by-screen-name --- 01901d9835113f35c67cf4c09cbe6530e96f4e79 diff --cc lib/pleroma/web/twitter_api/twitter_api_controller.ex index 92c20f97a,b70af3b09..3d6487396 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@@ -45,37 -45,22 +45,36 @@@ defmodule Pleroma.Web.TwitterAPI.Contro |> json_reply(200, json) end - def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do - { :ok, user, follower, _activity } = TwitterAPI.follow(user, followed_id) - - response = follower |> UserRepresenter.to_json(%{for: user}) + def user_timeline(%{assigns: %{user: user}} = conn, params) do + case TwitterAPI.get_user(user, params) do + {:ok, target_user} -> + params = Map.merge(params, %{"actor_id" => target_user.ap_id}) + statuses = TwitterAPI.fetch_user_statuses(user, params) + conn + |> json_reply(200, statuses |> Poison.encode!) + {:error, msg} -> + bad_request_reply(conn, msg) + end + end - conn - |> json_reply(200, response) + 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 + |> json_reply(200, response) + { :error, msg } -> forbidden_json_reply(conn, msg) + 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 - { :ok, user, follower } = TwitterAPI.unfollow(user, params) - - response = follower |> UserRepresenter.to_json(%{for: user}) - - conn - |> json_reply(200, response) ++ 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) + end end def fetch_status(%{assigns: %{user: user}} = conn, %{ "id" => id }) do diff --cc test/web/twitter_api/twitter_api_test.exs index 3a1745a1b,3d16a2049..8b4e0b1d8 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@@ -144,39 -112,39 +144,48 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte 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) - following = insert(:user) - - {:ok, user, following, activity } = TwitterAPI.follow(user, following.id) + followed = insert(:user) - 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 user.following == [User.ap_followers(following)] - assert follow == activity + { :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id}) + assert msg == "Could not follow user: #{followed.nickname} is already on your list." end - test "Unfollow another user using user_id" do - following = insert(:user) - user = insert(:user, %{following: [User.ap_followers(following)]}) + test "Follow another user using screen_name" do + user = insert(:user) + followed = insert(:user) - {:ok, user, _following } = TwitterAPI.unfollow(user, %{"user_id" => following.id}) + {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname}) + assert user.following == [User.ap_followers(followed)] - user = Repo.get(User, user.id) + { :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname}) + 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)]}) ++ 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 == [] + - { :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id) ++ { :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id}) ++ assert msg == "Not subscribed!" + end - user = Repo.get(User, user.id) + test "Unfollow another user using screen_name" do - following = insert(:user) - user = insert(:user, %{following: [User.ap_followers(following)]}) - - {:ok, user, _following } = TwitterAPI.unfollow(user, %{"screen_name" => following.nickname}) - - user = Repo.get(User, user.id) ++ 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, followed.id) ++ ++ { :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname}) + assert msg == "Not subscribed!" end test "fetch statuses in a context using the conversation id" do