Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/user-timeline
authordtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 14:08:17 +0000 (17:08 +0300)
committerdtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 14:08:17 +0000 (17:08 +0300)
1  2 
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_test.exs

Simple merge
index 007b96bc75ee32d43330d7c919b02b5dbf972d27,b0287a7f489f8439b71e26d55639e9b5225e5d8b..36e2d235be4461f139fe3dfa1bbe78d914b85e9b
@@@ -154,11 -143,18 +155,23 @@@ defmodule Pleroma.Web.TwitterAPI.Contro
      end
    end
  
+   def update_avatar(%{assigns: %{user: user}} = conn, params) do
+     {:ok, object} = ActivityPub.upload(params)
+     change = Ecto.Changeset.change(user, %{avatar: object.data})
+     {:ok, user} = Repo.update(change)
+     response = UserRepresenter.to_map(user, %{for: user})
+     |> Poison.encode!
+     conn
+     |> json_reply(200, response)
+   end
 +  defp bad_request_reply(conn, error_message) do
 +    json = Poison.encode!(%{"error" => error_message})
 +    json_reply(conn, 400, json)
 +  end
 +
    defp json_reply(conn, status, json) do
      conn
      |> put_resp_content_type("application/json")
index 2f7e777734702646b65c142bd666b2a99b5d2ec3,1e5204db8442955e544f1125ed65fd5c1176000a..9e843e877716f5b3edf0ec7ecdd2a4983d31500d
@@@ -99,41 -99,9 +99,41 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
  
      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]})
+     assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]})
    end
  
 +  test "get a user by params" do
 +    user1_result = {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
 +    {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
 +
 +    assert {:error, "You need to specify screen_name or user_id"} == TwitterAPI.get_user(nil, nil)
 +    assert user1_result == TwitterAPI.get_user(nil, %{"user_id" => user1.id})
 +    assert user1_result == TwitterAPI.get_user(nil, %{"screen_name" => user1.nickname})
 +    assert user1_result == TwitterAPI.get_user(user1, nil)
 +    assert user1_result == TwitterAPI.get_user(user2, %{"user_id" => user1.id})
 +    assert user1_result == TwitterAPI.get_user(user2, %{"screen_name" => user1.nickname})
 +    assert {:error, "No user with such screen_name"} == TwitterAPI.get_user(nil, %{"screen_name" => "Satan"})
 +    assert {:error, "No user with such user_id"} == TwitterAPI.get_user(nil, %{"user_id" => 666})
 +  end
 +
 +  test "fetch user's statuses" do
 +    {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
 +    {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
 +
 +    {:ok, status1} = ActivityBuilder.insert(%{"id" => 1}, %{user: user1})
 +    {:ok, status2} = ActivityBuilder.insert(%{"id" => 2}, %{user: user2})
 +
 +    user1_statuses = TwitterAPI.fetch_user_statuses(user1, %{"actor_id" => user1.ap_id})
 +
 +    assert length(user1_statuses) == 1
 +    assert Enum.at(user1_statuses, 0) == ActivityRepresenter.to_map(status1, %{user: user1})
 +
 +    user2_statuses = TwitterAPI.fetch_user_statuses(user1, %{"actor_id" => user2.ap_id})
 +
 +    assert length(user2_statuses) == 1
 +    assert Enum.at(user2_statuses, 0) == ActivityRepresenter.to_map(status2, %{user: user2})
 +  end
 +
    test "fetch a single status" do
      {:ok, activity} = ActivityBuilder.insert()
      {:ok, user} = UserBuilder.insert()