X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fmastodon_api_controller.ex;h=fcc87d414543d7e42ca895ac2a6755965388da95;hb=73bdfd6c2b92533b5d48c2801a8e6548e8a2551a;hp=c713c561bca81bab208d62feacfd555d27403714;hpb=3ca853fb6165b82c39f23e24783e813015db48d5;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 c713c561b..fcc87d414 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -39,12 +39,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + @instance Application.get_env(:pleroma, :instance) + def masto_instance(conn, _params) do response = %{ uri: Web.base_url, - title: Web.base_url, + title: Keyword.get(@instance, :name), description: "A Pleroma instance, an alternative fediverse server", - version: "Pleroma Dev" + version: Keyword.get(@instance, :version), + email: Keyword.get(@instance, :email), + urls: %{ + streaming_api: String.replace(Web.base_url, ["http","https"], "wss") + }, + stats: %{ + user_count: 1, + status_count: 2, + domain_count: 3 + } } json(conn, response) @@ -122,15 +133,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def post_status(%{assigns: %{user: user}} = conn, %{"status" => status} = params) do - l = status |> String.trim |> String.length - params = params |> Map.put("in_reply_to_status_id", params["in_reply_to_id"]) - if l > 0 && l < 5000 do - {:ok, activity} = TwitterAPI.create_status(user, params) - render conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity} - end + {:ok, activity} = CommonAPI.post(user, params) + render conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity} end def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do @@ -280,6 +287,27 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + def search(%{assigns: %{user: user}} = conn, %{"q" => query}) do + q = from u in User, + where: fragment("(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", u.nickname, u.name, ^query), + limit: 20 + accounts = Repo.all(q) + + q = from a in Activity, + where: fragment("?->>'type' = 'Create'", a.data), + where: fragment("to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)", a.data, ^query), + limit: 20 + statuses = Repo.all(q) + + res = %{ + "accounts" => AccountView.render("accounts.json", users: accounts, for: user, as: :user), + "statuses" => StatusView.render("index.json", activities: statuses, for: user, as: :activity), + "hashtags" => [] + } + + json(conn, res) + 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