ap_id when is_binary(ap_id) <- activity.data["object"]["context"] do
{:ok, conversation} = create_for_ap_id(ap_id)
- local_users = User.get_users_from_set(activity.recipients, true)
+ users = User.get_users_from_set(activity.recipients)
participations =
- Enum.map(local_users, fn user ->
+ Enum.map(users, fn user ->
{:ok, participation} =
Participation.create_for_user_and_conversation(user, conversation)
alias Pleroma.Conversation
alias Pleroma.Repo
import Ecto.Changeset
+ import Ecto.Query
schema "conversation_participations" do
belongs_to(:user, User, type: Pleroma.FlakeId)
|> read_cng(%{read: false})
|> Repo.update()
end
+
+ def for_user(user, params \\ %{}) do
+ from(p in __MODULE__,
+ where: p.user_id == ^user.id,
+ order_by: [desc: p.updated_at]
+ )
+ |> Pleroma.Pagination.fetch_paginated(params)
+ end
end
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.Conversation.Participation
+ alias Pleroma.Web.CommonAPI
test "it creates a participation for a conversation and a user" do
user = insert(:user)
refute participation.read
end
+
+ test "gets all the participations for a user, ordered by updated at descending" do
+ user = insert(:user)
+ {:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
+ :timer.sleep(1000)
+ {:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
+ :timer.sleep(1000)
+
+ {:ok, activity_three} =
+ CommonAPI.post(user, %{
+ "status" => "x",
+ "visibility" => "direct",
+ "in_reply_to_status_id" => activity_one.id
+ })
+
+ assert [participation_one, participation_two] =
+ Participation.for_user(user)
+ |> Repo.preload(:conversation)
+
+ assert participation_one.conversation.ap_id == activity_three.data["object"]["context"]
+ assert participation_two.conversation.ap_id == activity_two.data["object"]["context"]
+
+ # Pagination
+ assert [participation_one] =
+ Participation.for_user(user, %{limit: 1})
+ |> Repo.preload(:conversation)
+
+ assert participation_one.conversation.ap_id == activity_three.data["object"]["context"]
+ end
end