|> Enum.filter(& &1.last_activity_id)
end
- def get(nil), do: nil
+ def get(_, _ \\ [])
+ def get(nil, _), do: nil
+
+ def get(id, params) do
+ query =
+ if preload = params[:preload] do
+ from(p in __MODULE__,
+ preload: ^preload
+ )
+ else
+ __MODULE__
+ end
- def get(id) do
- Repo.get(__MODULE__, id)
+ Repo.get(query, id)
end
def set_recipients(participation, user_ids) do
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 7]
alias Pleroma.Conversation.Participation
- alias Pleroma.Repo
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.ConversationView
alias Pleroma.Web.MastodonAPI.StatusView
participation =
participation_id
- |> Participation.get()
- |> Repo.preload(:conversation)
+ |> Participation.get(preload: [:conversation])
if user.id == participation.user_id do
activities =
alias Pleroma.Conversation.Participation
alias Pleroma.Web.CommonAPI
+ test "getting a participation will also preload things" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Participation.get(participation.id, preload: [:conversation])
+
+ assert %Pleroma.Conversation{} = participation.conversation
+ end
+
test "for a new conversation, it sets the recipents of the participation" do
user = insert(:user)
other_user = insert(:user)