X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fmastodon_api_controller.ex;h=0f7674f5dbe2c9ce1ec09629ce5a5cba5ca846ef;hb=b0363e80556b4c8271ab69d2680166ca844f660c;hp=3f0c7407f756b1262faf49115bed16863d6d1e9e;hpb=14b4029b1d8d2f036e39b1aefaf315d35fceaf01;p=akkoma diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 3f0c7407f..0f7674f5d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -28,6 +28,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, account) end + def user(conn, %{"id" => id}) do + with %User{} = user <- Repo.get(User, id) do + account = AccountView.render("account.json", %{user: user}) + json(conn, account) + else + _e -> conn + |> put_status(404) + |> json(%{error: "Can't find user"}) + end + end + def masto_instance(conn, _params) do response = %{ uri: Web.base_url, @@ -158,7 +169,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do result = Enum.map(notifications, fn (%{id: id, activity: activity, inserted_at: created_at}) -> actor = User.get_cached_by_ap_id(activity.data["actor"]) created_at = NaiveDateTime.to_iso8601(created_at) - |> String.replace(~r/\.\d+$/, ".000Z") + |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false) case activity.data["type"] do "Create" -> %{id: id, type: "mention", created_at: created_at, account: AccountView.render("account.json", %{user: actor}), status: StatusView.render("status.json", %{activity: activity})} @@ -188,6 +199,37 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do render conn, AccountView, "relationships.json", %{user: user, targets: targets} end + def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) do + with {:ok, object} <- ActivityPub.upload(file) do + data = object.data + |> Map.put("id", object.id) + + render conn, StatusView, "attachment.json", %{attachment: data} + 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 Logger.debug("Unimplemented, returning an empty array") json(conn, [])