X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fwebsub%2Fwebsub.ex;h=a683f6da40de022e443630f8adb279471f019431;hb=bdcf42180fa67e43f13584d5e19f26d751199d03;hp=7bdb778ad0621eb4608aab2a3328eb4058b21ece;hpb=d982f04a652ee95110ebd7d6dfc1ebdaa3c15d6f;p=akkoma diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 7bdb778ad..a683f6da4 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -39,6 +39,7 @@ defmodule Pleroma.Web.Websub do 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) @@ -51,10 +52,12 @@ defmodule Pleroma.Web.Websub do signature = sign(sub.secret || "", response) Logger.debug(fn -> "Pushing to #{sub.callback}" end) - @httpoison.post(sub.callback, response, [ - {"Content-Type", "application/atom+xml"}, - {"X-Hub-Signature", "sha1=#{signature}"} - ]) + Task.start(fn -> + @httpoison.post(sub.callback, response, [ + {"Content-Type", "application/atom+xml"}, + {"X-Hub-Signature", "sha1=#{signature}"} + ]) + end) end) end @@ -124,7 +127,7 @@ defmodule Pleroma.Web.Websub do topic = subscribed.info["topic"] # FIXME: Race condition, use transactions {:ok, subscription} = with subscription when not is_nil(subscription) <- Repo.get_by(WebsubClientSubscription, topic: topic) do - subscribers = [subscriber.ap_id, subscription.subscribers] |> Enum.uniq + subscribers = [subscriber.ap_id | subscription.subscribers] |> Enum.uniq change = Ecto.Changeset.change(subscription, %{subscribers: subscribers}) Repo.update(change) else _e -> @@ -153,6 +156,7 @@ defmodule Pleroma.Web.Websub do 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, @@ -160,7 +164,8 @@ defmodule Pleroma.Web.Websub do "nickname" => preferredUsername || name, "name" => displayName || name, "host" => URI.parse(uri).host, - "avatar" => avatar + "avatar" => avatar, + "bio" => bio }} else e -> {:error, e} @@ -202,4 +207,19 @@ defmodule Pleroma.Web.Websub do {: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 and sub.state == "accepted" + + subs = Repo.all(query) + + Enum.map(subs, fn (sub) -> + request_subscription(sub) + end) + end end