diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index d77c88997..40e14005b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -12,16 +12,17 @@ defmodule Pleroma.Activity do def get_by_ap_id(ap_id) do Repo.one(from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{id: ap_id})) + where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))) end def all_by_object_ap_id(ap_id) do Repo.all(from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}})) + where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))) end def get_create_activity_by_object_ap_id(ap_id) do Repo.one(from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{type: "Create", object: %{id: ap_id}})) + where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)) + and fragment("(?)->>'type' = 'Create'", activity.data)) end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 140787587..47793ca6d 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -26,8 +26,8 @@ defmodule Pleroma.Web.Router do scope "/api", Pleroma.Web do pipe_through :api - get "/help/test", TwitterAPI.Controller, :help_test - get "/statusnet/config", TwitterAPI.Controller, :config + get "/help/test", TwitterAPI.UtilController, :help_test + get "/statusnet/config", TwitterAPI.UtilController, :config get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex new file mode 100644 index 000000000..6d6fd2202 --- /dev/null +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -0,0 +1,18 @@ +defmodule Pleroma.Web.TwitterAPI.UtilController do + use Pleroma.Web, :controller + alias Pleroma.Web + + def help_test(conn, _params) do + json(conn, "ok") + end + + def config(conn, _params) do + json(conn, %{ + site: %{ + name: Web.base_url, + server: Web.base_url, + textlimit: -1 + } + }) + end +end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 77d51a835..7418cee06 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller alias Pleroma.Web.TwitterAPI.{ErrorView, StatusView, TwitterAPI} - alias Pleroma.{Web, Repo, Activity, User} + alias Pleroma.{Repo, Activity, User} alias Pleroma.Web.ActivityPub.ActivityPub def status_update(%{assigns: %{user: user}} = conn, %{"status" => status_text} = status_data) do @@ -93,24 +93,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do |> send_resp(200, response) end - def help_test(conn, _params) do - json(conn, "ok") - end - def upload_json(conn, %{"media" => media}) do json(conn, TwitterAPI.upload(media, "json")) end - def config(conn, _params) do - json(conn, %{ - site: %{ - name: Web.base_url, - server: Web.base_url, - textlimit: -1 - } - }) - end - def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do activity = Repo.get(Activity, id) {:ok, activity} = TwitterAPI.favorite(user, activity) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index a683f6da4..410303b77 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -50,13 +50,17 @@ defmodule Pleroma.Web.Websub do |> to_string signature = sign(sub.secret || "", response) - Logger.debug(fn -> "Pushing to #{sub.callback}" end) + Logger.debug(fn -> "Pushing #{topic} to #{sub.callback}" end) Task.start(fn -> - @httpoison.post(sub.callback, response, [ + with {:ok, %{status_code: code}} <- @httpoison.post(sub.callback, response, [ {"Content-Type", "application/atom+xml"}, {"X-Hub-Signature", "sha1=#{signature}"} - ]) + ]) do + Logger.debug(fn -> "Pushed to #{sub.callback}, code #{code}" end) + else e -> + Logger.debug(fn -> "Couldn't push to #{sub.callback}, #{inspect(e)}" end) + end end) end) end diff --git a/priv/repo/migrations/20170620133028_add_object_activity_index.exs b/priv/repo/migrations/20170620133028_add_object_activity_index.exs new file mode 100644 index 000000000..1abbd7802 --- /dev/null +++ b/priv/repo/migrations/20170620133028_add_object_activity_index.exs @@ -0,0 +1,7 @@ +defmodule Pleroma.Repo.Migrations.AddObjectActivityIndex do + use Ecto.Migration + + def change do + create index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) + end +end diff --git a/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs new file mode 100644 index 000000000..705a05f82 --- /dev/null +++ b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs @@ -0,0 +1,8 @@ +defmodule Pleroma.Repo.Migrations.AddObjectActivityIndexPartTwo do + use Ecto.Migration + + def change do + drop index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) + create index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) + end +end