logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

recipient_ship.ex (975B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Conversation.Participation.RecipientShip do
  5. use Ecto.Schema
  6. alias Pleroma.Conversation.Participation
  7. alias Pleroma.Repo
  8. alias Pleroma.User
  9. import Ecto.Changeset
  10. schema "conversation_participation_recipient_ships" do
  11. belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
  12. belongs_to(:participation, Participation)
  13. end
  14. def creation_cng(struct, params) do
  15. struct
  16. |> cast(params, [:user_id, :participation_id])
  17. |> validate_required([:user_id, :participation_id])
  18. end
  19. def create(%User{} = user, participation), do: create([user], participation)
  20. def create(users, participation) do
  21. Enum.each(users, fn user ->
  22. %__MODULE__{}
  23. |> creation_cng(%{user_id: user.id, participation_id: participation.id})
  24. |> Repo.insert!()
  25. end)
  26. end
  27. end