PollWorker defensive checks
authorAlex Gleason <alex@alexgleason.me>
Sun, 18 Jul 2021 15:49:35 +0000 (10:49 -0500)
committerAlex Gleason <alex@alexgleason.me>
Sun, 18 Jul 2021 16:10:22 +0000 (11:10 -0500)
lib/pleroma/workers/poll_worker.ex

index caec89cbe4948cded90c97b2820fb979470075fa..3423cc889df84e96fe46f414f3a834851099375a 100644 (file)
@@ -26,8 +26,10 @@ defmodule Pleroma.Workers.PollWorker do
   end
 
   def schedule_poll_end(%Activity{data: %{"type" => "Create"}, id: activity_id} = activity) do
-    with %Object{data: %{"type" => "Question", "closed" => closed}} <- Object.normalize(activity),
-         {:ok, end_time} <- NaiveDateTime.from_iso8601(closed) do
+    with %Object{data: %{"type" => "Question", "closed" => closed}} when is_binary(closed) <-
+           Object.normalize(activity),
+         {:ok, end_time} <- NaiveDateTime.from_iso8601(closed),
+         :gt <- NaiveDateTime.compare(end_time, NaiveDateTime.utc_now()) do
       %{
         op: "poll_end",
         activity_id: activity_id