X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fmastodon_api_controller.ex;h=0615ac11a0ec26080f7396f3842d2352d6d64375;hb=baf66caefd0e8d483ed6feca768b6ad98ab55260;hp=a3587ff4459b4cc7e7c9130f72dc4e3b1077f9ef;hpb=a6f65083aeed755d31134144b973d87575ae549e;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 a3587ff44..0615ac11a 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller - alias Pleroma.{Repo, Activity, User, Notification} + alias Pleroma.{Repo, Activity, User, Notification, Stats} alias Pleroma.Web alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView} alias Pleroma.Web.ActivityPub.ActivityPub @@ -102,16 +102,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do urls: %{ streaming_api: String.replace(Web.base_url, ["http","https"], "wss") }, - stats: %{ - user_count: 1, - status_count: 2, - domain_count: 3 - } + stats: Stats.get_stats, + max_toot_chars: Keyword.get(@instance, :limit) } json(conn, response) end + def peers(conn, _params) do + json(conn, Stats.get_peers) + end + defp mastodonized_emoji do Pleroma.Formatter.get_custom_emoji() |> Enum.map(fn {shortcode, relative_url} -> @@ -160,7 +161,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def public_timeline(%{assigns: %{user: user}} = conn, params) do params = params |> Map.put("type", ["Create", "Announce"]) - |> Map.put("local_only", !!params["local"]) + |> Map.put("local_only", params["local"] in [true, "True", "true", "1"]) |> Map.put("blocking_user", user) activities = ActivityPub.fetch_public_activities(params) @@ -196,6 +197,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %Activity{} = activity <- Repo.get(Activity, id), activities <- ActivityPub.fetch_activities_for_context(activity.data["object"]["context"], %{"blocking_user" => user}), activities <- activities |> Enum.filter(fn (%{id: aid}) -> to_string(aid) != to_string(id) end), + activities <- activities |> Enum.filter(fn (%{data: %{"type" => type}}) -> type == "Create" end), grouped_activities <- Enum.group_by(activities, fn (%{id: id}) -> id < activity.id end) do result = %{ ancestors: StatusView.render("index.json", for: user, activities: grouped_activities[true] || [], as: :activity) |> Enum.reverse, @@ -209,6 +211,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do params = params |> Map.put("in_reply_to_status_id", params["in_reply_to_id"]) + |> Map.put("no_attachment_links", true) {:ok, activity} = CommonAPI.post(user, params) render conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity} @@ -557,7 +560,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def login(conn, _) do conn - |> render(MastodonView, "login.html") + |> render(MastodonView, "login.html", %{error: false}) end defp get_or_make_app() do @@ -579,9 +582,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> put_session(:oauth_token, token.token) |> redirect(to: "/web/getting-started") + else + _e -> + conn + |> render(MastodonView, "login.html", %{error: "Wrong username or password"}) end end + def logout(conn, _) do + conn + |> clear_session + |> redirect(to: "/") + end + def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do Logger.debug("Unimplemented, returning unmodified relationship") with %User{} = target <- Repo.get(User, id) do