2020-07-09 15:24:28 +00:00
|
|
|
defmodule Mobilizon.Federation.ActivityPub.Preloader do
|
|
|
|
@moduledoc """
|
|
|
|
Module to ensure entities are correctly preloaded
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO: Move me in a more appropriate place
|
2020-10-19 07:32:37 +00:00
|
|
|
alias Mobilizon.{Actors, Discussions, Events, Posts, Resources}
|
2020-08-20 08:54:58 +00:00
|
|
|
alias Mobilizon.Actors.{Actor, Member}
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Discussions.{Comment, Discussion}
|
|
|
|
alias Mobilizon.Events.Event
|
2020-10-19 07:32:37 +00:00
|
|
|
alias Mobilizon.Posts.Post
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Resources.Resource
|
|
|
|
alias Mobilizon.Tombstone
|
|
|
|
|
|
|
|
def maybe_preload(%Event{url: url}),
|
|
|
|
do: {:ok, Events.get_public_event_by_url_with_preload!(url)}
|
|
|
|
|
|
|
|
def maybe_preload(%Comment{url: url}),
|
|
|
|
do: {:ok, Discussions.get_comment_from_url_with_preload!(url)}
|
|
|
|
|
2020-08-14 09:32:23 +00:00
|
|
|
def maybe_preload(%Discussion{id: discussion_id}),
|
|
|
|
do: {:ok, Discussions.get_discussion(discussion_id)}
|
2020-07-09 15:24:28 +00:00
|
|
|
|
|
|
|
def maybe_preload(%Resource{url: url}),
|
|
|
|
do: {:ok, Resources.get_resource_by_url_with_preloads(url)}
|
|
|
|
|
2020-10-19 07:32:37 +00:00
|
|
|
def maybe_preload(%Post{url: url}),
|
|
|
|
do: {:ok, Posts.get_post_by_url_with_preloads(url)}
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
def maybe_preload(%Actor{url: url}), do: {:ok, Actors.get_actor_by_url!(url, true)}
|
|
|
|
|
2020-08-20 08:54:58 +00:00
|
|
|
def maybe_preload(%Member{} = member), do: {:ok, member}
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
def maybe_preload(%Tombstone{uri: _uri} = tombstone), do: {:ok, tombstone}
|
|
|
|
|
|
|
|
def maybe_preload(other), do: {:error, other}
|
|
|
|
end
|