Add favoriting to TwAPI controller.
This commit is contained in:
parent
d0da40dc81
commit
5cb446a148
7
TODO.txt
7
TODO.txt
@ -1 +1,8 @@
|
|||||||
- Add cache for user fetching / representing. (mostly in TwitterAPI.activity_to_status)
|
- Add cache for user fetching / representing. (mostly in TwitterAPI.activity_to_status)
|
||||||
|
|
||||||
|
Favorites:
|
||||||
|
- Add 'likes' to activity, collection of ids of people who liked it.
|
||||||
|
- show if you favorited something or not.
|
||||||
|
- Don't allow double favorites
|
||||||
|
- Address favorites to the followers of the liked activity's author.
|
||||||
|
|
||||||
|
@ -39,5 +39,6 @@ defmodule Pleroma.Web.Router do
|
|||||||
post "/friendships/create", TwitterAPI.Controller, :follow
|
post "/friendships/create", TwitterAPI.Controller, :follow
|
||||||
post "/friendships/destroy", TwitterAPI.Controller, :unfollow
|
post "/friendships/destroy", TwitterAPI.Controller, :unfollow
|
||||||
post "/statusnet/media/upload", TwitterAPI.Controller, :upload
|
post "/statusnet/media/upload", TwitterAPI.Controller, :upload
|
||||||
|
post "/favorites/create/:id", TwitterAPI.Controller, :favorite
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter}
|
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter}
|
||||||
|
alias Pleroma.{Repo, Activity}
|
||||||
|
|
||||||
def verify_credentials(%{assigns: %{user: user}} = conn, _params) do
|
def verify_credentials(%{assigns: %{user: user}} = conn, _params) do
|
||||||
response = user |> UserRepresenter.to_json(%{for: user})
|
response = user |> UserRepresenter.to_json(%{for: user})
|
||||||
@ -97,6 +98,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
|
activity = Repo.get(Activity, id)
|
||||||
|
{:ok, status} = TwitterAPI.favorite(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")
|
||||||
|
@ -4,6 +4,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||||||
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
|
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
|
||||||
alias Pleroma.{Repo, Activity, User}
|
alias Pleroma.{Repo, Activity, User}
|
||||||
|
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "POST /api/account/verify_credentials" do
|
describe "POST /api/account/verify_credentials" do
|
||||||
setup [:valid_user]
|
setup [:valid_user]
|
||||||
test "without valid credentials", %{conn: conn} do
|
test "without valid credentials", %{conn: conn} do
|
||||||
@ -154,6 +156,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "POST /api/favorites/create/:id" do
|
||||||
|
setup [:valid_user]
|
||||||
|
test "without valid credentials", %{conn: conn} do
|
||||||
|
note_activity = insert(:note_activity)
|
||||||
|
conn = post conn, "/api/favorites/create/#{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/favorites/create/#{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