|> creation_cng(%{user_id: user.id, conversation_id: conversation.id})
|> Repo.insert()
end
+
+ def read_cng(struct, params) do
+ struct
+ |> cast(params, [:read])
+ |> validate_required([:read])
+ end
+
+ def mark_as_read(participation) do
+ participation
+ |> read_cng(%{read: true})
+ |> Repo.update()
+ end
+
+ def mark_as_unread(participation) do
+ participation
+ |> read_cng(%{read: false})
+ |> Repo.update()
+ end
end
assert participation.user_id == user.id
assert participation.conversation_id == conversation.id
end
+
+ test "it marks a participation as read" do
+ participation = insert(:participation, %{read: false})
+ {:ok, participation} = Participation.mark_as_read(participation)
+
+ assert participation.read
+ end
+
+ test "it marks a participation as unread" do
+ participation = insert(:participation, %{read: true})
+ {:ok, participation} = Participation.mark_as_unread(participation)
+
+ refute participation.read
+ end
end
defmodule Pleroma.Factory do
use ExMachina.Ecto, repo: Pleroma.Repo
+ def participation_factory do
+ conversation = insert(:conversation)
+ user = insert(:user)
+
+ %Pleroma.Conversation.Participation{
+ conversation: conversation,
+ user: user,
+ read: false
+ }
+ end
+
def conversation_factory do
%Pleroma.Conversation{
ap_id: sequence(:ap_id, &"https://some_conversation/#{&1}")