From: Roger Braun Date: Sat, 22 Apr 2017 10:05:48 +0000 (+0200) Subject: Add callback to websub subscription. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=39dc74f967e3fdbcd949c50df8d2c5ed74f876ff;p=akkoma Add callback to websub subscription. --- diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index 09305c337..5766dff64 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -3,6 +3,7 @@ defmodule Pleroma.Web.Websub.WebsubController do alias Pleroma.Web.Websub.WebsubServerSubscription alias Pleroma.{Repo, User} alias Pleroma.Web.OStatus + alias Pleroma.Web.Websub def websub_subscription_request(conn, %{"nickname" => nickname} = params) do user = User.get_cached_by_nickname(nickname) @@ -13,7 +14,8 @@ defmodule Pleroma.Web.Websub.WebsubController do data = %{ state: "requested", topic: topic, - secret: secret + secret: secret, + callback: params["hub.callback"] } change = Ecto.Changeset.change(%WebsubServerSubscription{}, data) @@ -22,6 +24,9 @@ defmodule Pleroma.Web.Websub.WebsubController do change = Ecto.Changeset.change(websub, %{valid_until: NaiveDateTime.add(websub.inserted_at, lease_time)}) websub = Repo.update!(change) + # Just spawn that for now, maybe pool later. + spawn(fn -> Websub.verify(websub) end) + conn |> send_resp(202, "Accepted") else {:error, reason} -> @@ -31,7 +36,7 @@ defmodule Pleroma.Web.Websub.WebsubController do end defp lease_time(%{"hub.lease_seconds" => lease_seconds}) do - {:ok, lease_seconds} + {:ok, String.to_integer(lease_seconds)} end defp lease_time(_) do diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 4eff598d6..584db0a19 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -14,7 +14,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do "hub.mode": "subscription", "hub.topic": Pleroma.Web.OStatus.feed_path(user), "hub.secret": "a random secret", - "hub.lease_seconds": 100 + "hub.lease_seconds": "100" } conn = conn @@ -25,6 +25,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do assert subscription.topic == Pleroma.Web.OStatus.feed_path(user) assert subscription.state == "requested" assert subscription.secret == "a random secret" + assert subscription.callback == "http://example.org/sub" assert subscription.valid_until == NaiveDateTime.add(subscription.inserted_at, 100) end end