end
def publish(topic, user, activity) do
+ # TODO: Only send to still valid subscriptions.
query = from sub in WebsubServerSubscription,
where: sub.topic == ^topic and sub.state == "active"
subscriptions = Repo.all(query)
|> :xmerl.export_simple(:xmerl_xml)
|> to_string
- signature = sign(sub.secret || "", response)
- Logger.debug(fn -> "Pushing to #{sub.callback}" end)
-
- Task.start(fn ->
- @httpoison.post(sub.callback, response, [
- {"Content-Type", "application/atom+xml"},
- {"X-Hub-Signature", "sha1=#{signature}"}
- ])
- end)
+ data = %{
+ xml: response,
+ topic: topic,
+ callback: sub.callback,
+ secret: sub.secret
+ }
+ Pleroma.Web.Federator.enqueue(:publish_single_websub, data)
end)
end
preferredUsername = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc)
displayName = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc)
avatar = OStatus.make_avatar_object(doc)
+ bio = XML.string_from_xpath("/feed/author[1]/summary", doc)
{:ok, %{
"uri" => uri,
"nickname" => preferredUsername || name,
"name" => displayName || name,
"host" => URI.parse(uri).host,
- "avatar" => avatar
+ "avatar" => avatar,
+ "bio" => bio
}}
else e ->
{:error, e}
{:error, websub}
end
end
+
+ def refresh_subscriptions(delta \\ 60 * 60 * 24) do
+ Logger.debug("Refreshing subscriptions")
+
+ cut_off = NaiveDateTime.add(NaiveDateTime.utc_now, delta)
+
+ query = from sub in WebsubClientSubscription,
+ where: sub.valid_until < ^cut_off
+
+ subs = Repo.all(query)
+
+ Enum.each(subs, fn (sub) ->
+ Pleroma.Web.Federator.enqueue(:request_subscription, sub)
+ end)
+ end
end