MastoAPI: Add favourited_by/reblogged_by.
This commit is contained in:
parent
ac3f32da7e
commit
b0363e8055
|
@ -208,6 +208,28 @@ def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def favourited_by(conn, %{"id" => id}) do
|
||||||
|
with %Activity{data: %{"object" => %{"likes" => likes} = data}} <- Repo.get(Activity, id) do
|
||||||
|
q = from u in User,
|
||||||
|
where: u.ap_id in ^likes
|
||||||
|
users = Repo.all(q)
|
||||||
|
render conn, AccountView, "accounts.json", %{users: users, as: :user}
|
||||||
|
else
|
||||||
|
_ -> json(conn, [])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def reblogged_by(conn, %{"id" => id}) do
|
||||||
|
with %Activity{data: %{"object" => %{"announcements" => announces}}} <- Repo.get(Activity, id) do
|
||||||
|
q = from u in User,
|
||||||
|
where: u.ap_id in ^announces
|
||||||
|
users = Repo.all(q)
|
||||||
|
render conn, AccountView, "accounts.json", %{users: users, as: :user}
|
||||||
|
else
|
||||||
|
_ -> json(conn, [])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def empty_array(conn, _) do
|
def empty_array(conn, _) do
|
||||||
Logger.debug("Unimplemented, returning an empty array")
|
Logger.debug("Unimplemented, returning an empty array")
|
||||||
json(conn, [])
|
json(conn, [])
|
||||||
|
|
|
@ -6,6 +6,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
|
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
|
||||||
defp image_url(_), do: nil
|
defp image_url(_), do: nil
|
||||||
|
|
||||||
|
def render("accounts.json", %{users: users} = opts) do
|
||||||
|
render_many(users, AccountView, "account.json", opts)
|
||||||
|
end
|
||||||
|
|
||||||
def render("account.json", %{user: user}) do
|
def render("account.json", %{user: user}) do
|
||||||
image = User.avatar_url(user)
|
image = User.avatar_url(user)
|
||||||
user_info = User.user_info(user)
|
user_info = User.user_info(user)
|
||||||
|
|
|
@ -68,6 +68,8 @@ def user_fetcher(username) do
|
||||||
|
|
||||||
get "/statuses/:id", MastodonAPIController, :get_status
|
get "/statuses/:id", MastodonAPIController, :get_status
|
||||||
get "/statuses/:id/context", MastodonAPIController, :get_context
|
get "/statuses/:id/context", MastodonAPIController, :get_context
|
||||||
|
get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
|
||||||
|
get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
|
||||||
|
|
||||||
get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
|
get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
|
||||||
get "/accounts/:id", MastodonAPIController, :user
|
get "/accounts/:id", MastodonAPIController, :user
|
||||||
|
|
Loading…
Reference in New Issue