From 39dc74f967e3fdbcd949c50df8d2c5ed74f876ff Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 22 Apr 2017 12:05:48 +0200 Subject: [PATCH] Add callback to websub subscription. --- lib/pleroma/web/websub/websub_controller.ex | 9 +++++++-- test/web/websub/websub_controller_test.exs | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) 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 @@ def websub_subscription_request(conn, %{"nickname" => nickname} = params) do data = %{ state: "requested", topic: topic, - secret: secret + secret: secret, + callback: params["hub.callback"] } change = Ecto.Changeset.change(%WebsubServerSubscription{}, data) @@ -22,6 +24,9 @@ def websub_subscription_request(conn, %{"nickname" => nickname} = params) 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 @@ def websub_subscription_request(conn, %{"nickname" => nickname} = params) 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 @@ test "websub subscription request", %{conn: conn} 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 @@ test "websub subscription request", %{conn: conn} 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