Add callback to websub subscription.
This commit is contained in:
parent
1c00eb4a90
commit
39dc74f967
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user