+ |> case do
+ {:ok, participation} ->
+ participation = Repo.preload(participation, :user)
+ User.set_unread_conversation_count(participation.user)
+ {:ok, participation}
+
+ error ->
+ error
+ end
+ end
+
+ def mark_all_as_read(user) do
+ {_, participations} =
+ __MODULE__
+ |> where([p], p.user_id == ^user.id)
+ |> where([p], not p.read)
+ |> update([p], set: [read: true])
+ |> select([p], p)
+ |> Repo.update_all([])
+
+ User.set_unread_conversation_count(user)
+ {:ok, participations}