Add retweeting to TwAPI controller.
This commit is contained in:
parent
60c60de330
commit
4799dc6991
@ -43,5 +43,6 @@ defmodule Pleroma.Web.Router do
|
|||||||
post "/favorites/create/:id", TwitterAPI.Controller, :favorite
|
post "/favorites/create/:id", TwitterAPI.Controller, :favorite
|
||||||
post "/favorites/create", TwitterAPI.Controller, :favorite
|
post "/favorites/create", TwitterAPI.Controller, :favorite
|
||||||
post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
|
post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
|
||||||
|
post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -122,6 +122,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
|
activity = Repo.get(Activity, id)
|
||||||
|
{:ok, status} = TwitterAPI.retweet(user, activity)
|
||||||
|
response = Poison.encode!(status)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> json_reply(200, response)
|
||||||
|
end
|
||||||
|
|
||||||
defp json_reply(conn, status, json) do
|
defp json_reply(conn, status, json) do
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|
@ -197,6 +197,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "POST /api/statuses/retweet/:id" do
|
||||||
|
setup [:valid_user]
|
||||||
|
test "without valid credentials", %{conn: conn} do
|
||||||
|
note_activity = insert(:note_activity)
|
||||||
|
conn = post conn, "/api/statuses/retweet/#{note_activity.id}.json"
|
||||||
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials", %{conn: conn, user: current_user} do
|
||||||
|
note_activity = insert(:note_activity)
|
||||||
|
|
||||||
|
conn = conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/statuses/retweet/#{note_activity.id}.json")
|
||||||
|
|
||||||
|
assert json_response(conn, 200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp valid_user(_context) do
|
defp valid_user(_context) do
|
||||||
{ :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"})
|
{ :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"})
|
||||||
[user: user]
|
[user: user]
|
||||||
|
Loading…
Reference in New Issue
Block a user