From 8b18d10b0a581fc33126a0c40913a2d294ab01ee Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 26 Aug 2021 22:57:15 -0400 Subject: [PATCH] Fix notifications query not working for those without referenced_activity --- lib/clacks/timeline.ex | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/clacks/timeline.ex b/lib/clacks/timeline.ex index 8d8f518..96f2310 100644 --- a/lib/clacks/timeline.ex +++ b/lib/clacks/timeline.ex @@ -123,13 +123,24 @@ defmodule Clacks.Timeline do referenced_object: referenced_object, activity_actor: activity_actor ], + {n, activity, object, activity_actor, referenced_activity, referenced_object} + ) + |> Repo.all() + |> Enum.map(fn {n, activity, object, activity_actor, referenced_activity, referenced_object} -> + # unfortunately we can't use the select to set the associations because we need to handle the possibility of referenced_activity being nil + referenced_activity = + case referenced_activity do + nil -> nil + a -> %Activity{a | object: referenced_object} + end + %Notification{ n | activity: %Activity{activity | object: object, actor: activity_actor}, - referenced_activity: %Activity{referenced_activity | object: referenced_object} + referenced_activity: referenced_activity } - ) - |> Repo.all() + end) + |> IO.inspect() end defp restrict_to_actor(query, actor_id) do