%Activity{data: %{"content" => emoji, "actor" => actor}},
object
) do
- reactions = object.data["reactions"] || []
+ reactions = get_cached_emoji_reactions(object)
new_reactions =
case Enum.find_index(reactions, fn [candidate, _] -> emoji == candidate end) do
%Activity{data: %{"content" => emoji, "actor" => actor}},
object
) do
- reactions = object.data["reactions"] || []
+ reactions = get_cached_emoji_reactions(object)
new_reactions =
case Enum.find_index(reactions, fn [candidate, _] -> emoji == candidate end) do
update_element_in_object("reaction", new_reactions, object, count)
end
+ def get_cached_emoji_reactions(object) do
+ if is_list(object.data["reactions"]) do
+ object.data["reactions"]
+ else
+ []
+ end
+ end
+
@spec add_like_to_object(Activity.t(), Object.t()) ::
{:ok, Object.t()} | {:error, Ecto.Changeset.t()}
def add_like_to_object(%Activity{data: %{"actor" => actor}}, object) do