Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into bugfix/repeated...
authordtluna <dtluna@openmailbox.org>
Thu, 13 Apr 2017 12:36:00 +0000 (15:36 +0300)
committerdtluna <dtluna@openmailbox.org>
Thu, 13 Apr 2017 12:36:00 +0000 (15:36 +0300)
1  2 
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_test.exs

index 66f78f3407b80cee58a182ddfa66c7c5703cf44f,0217b28d64139a815636f36a3908b3e1605fd732..f4ab5bdc6902b4c4e1fbfdc297bd0ea0ab58141f
@@@ -69,7 -69,7 +69,7 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
    end
  
    def fetch_friend_statuses(user, opts \\ %{}) do
-     ActivityPub.fetch_activities(user.following, opts)
+     ActivityPub.fetch_activities([user.ap_id | user.following], opts)
      |> activities_to_statuses(%{for: user})
    end
  
  
    def follow(%User{} = follower, followed_id) do
      with %User{} = followed <- Repo.get(User, followed_id),
 -         { :ok, follower } <- User.follow(follower, followed),
 +    { :ok, follower } <- User.follow(follower, followed),
           { :ok, activity } <- ActivityPub.insert(%{
             "type" => "Follow",
             "actor" => follower.ap_id,
           })
      do
        { :ok, follower, followed, activity }
 +    else
 +      err -> err
      end
    end
  
           { :ok, follower } <- User.unfollow(follower, followed)
      do
        { :ok, follower, followed }
 +    else
 +      err -> err
      end
    end
  
index f6574b8de7284ad5f362188a9cdc2f14b891273a,3f299a941690e2a93d0e5013ecec9c53e9f90e8f..13de1661dc9306a2fc5ae0353362f3362136354e
@@@ -44,24 -44,21 +44,24 @@@ defmodule Pleroma.Web.TwitterAPI.Contro
    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})
 -
 -    conn
 -    |> json_reply(200, response)
 +    case TwitterAPI.follow(user, followed_id) do
-       { :ok, _user, followed, _activity } ->
++      { :ok, user, followed, _activity } ->
 +        response = followed |> UserRepresenter.to_json(%{for: user})
-         conn |> json_reply(200, response)
++        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
 -    { :ok, user, follower } = TwitterAPI.unfollow(user, followed_id)
 -
 -    response = follower |> UserRepresenter.to_json(%{for: user})
 +    case TwitterAPI.unfollow(user, followed_id) do
 +      { :ok, user, followed } ->
 +        response = followed |> UserRepresenter.to_json(%{for: user})
  
 -    conn
 -    |> json_reply(200, response)
 +        conn
 +        |> json_reply(200, response)
 +      { :error, msg } -> forbidden_json_reply(conn, msg)
 +    end
    end
  
    def fetch_status(%{assigns: %{user: user}} = conn, %{ "id" => id }) do
      |> send_resp(200, response)
    end
  
+   def config(conn, _params) do
+     response = %{
+       site: %{
+         name: Pleroma.Web.base_url,
+         server: Pleroma.Web.base_url,
+         textlimit: -1
+       }
+     }
+     |> Poison.encode!
+     conn
+     |> json_reply(200, response)
+   end
    defp json_reply(conn, status, json) do
      conn
      |> put_resp_content_type("application/json")
      |> send_resp(status, json)
    end
 +
 +  defp forbidden_json_reply(conn, error_message) do
 +    json = %{"error" => error_message, "request" => conn.request_path}
 +    |> Poison.encode!
 +
 +    json_reply(conn, 403, json)
 +  end
  end
index c1f5881b8eb9bd1b541dfd2aed951005889461ad,e8853a9100c249f05aaa98f2c06376ec09934398..405aa1221a1dfac9cb27259fb829d520f379c536
@@@ -82,15 -82,18 +82,18 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
  
    test "fetch friends' statuses" do
      ActivityBuilder.public_and_non_public
      {:ok, activity} = ActivityBuilder.insert(%{"to" => ["someguy/followers"]})
+     {:ok, direct_activity} = ActivityBuilder.insert(%{"to" => ["some other id"]})
      {:ok, user} = UserBuilder.insert(%{ap_id: "some other id", following: ["someguy/followers"]})
  
      statuses = TwitterAPI.fetch_friend_statuses(user)
  
      activity_user = Repo.get_by(User, ap_id: activity.data["actor"])
  
-     assert length(statuses) == 1
+     assert length(statuses) == 2
      assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user})
+     assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: activity_user, mentioned: [user]})
    end
  
    test "fetch a single status" do
  
    test "Follow another user" do
      { :ok, user } = UserBuilder.insert
 -    { :ok, following } = UserBuilder.insert(%{nickname: "guy"})
 +    { :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
  
 -    {:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
 +    { :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
  
      user = Repo.get(User, user.id)
      follow = Repo.get(Activity, activity.id)
  
 -    assert user.following == [User.ap_followers(following)]
 +    assert user.following == [User.ap_followers(followed)]
      assert follow == activity
 +
 +    { :error, msg } = TwitterAPI.follow(user, followed.id)
 +    assert msg == "Could not follow user: #{followed.nickname} is already on your list."
    end
  
    test "Unfollow another user" do
 -    { :ok, following } = UserBuilder.insert(%{nickname: "guy"})
 -    { :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
 +    { :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
 +    { :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(followed)]})
  
 -    {:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
 +    { :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
  
      user = Repo.get(User, user.id)
  
      assert user.following == []
 +    { :error, msg } = TwitterAPI.unfollow(user, followed.id)
 +    assert msg == "Not subscribed!"
    end
  
    test "fetch statuses in a context using the conversation id" do