Correct active state websub name.
[akkoma] / lib / pleroma / web / websub / websub.ex
index 7c8efa917f169182887119d6094c5c050e0167dc..2276ddeec822cebad1179f56334f4b5475541d83 100644 (file)
@@ -204,4 +204,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