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)
data = %{
state: "requested",
topic: topic,
- secret: secret
+ secret: secret,
+ callback: params["hub.callback"]
}
change = Ecto.Changeset.change(%WebsubServerSubscription{}, data)
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} ->
end
defp lease_time(%{"hub.lease_seconds" => lease_seconds}) do
- {:ok, lease_seconds}
+ {:ok, String.to_integer(lease_seconds)}
end
defp lease_time(_) 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
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