2019-08-02 09:55:41 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-26 06:11:42 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-08-02 09:55:41 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Conversation.Participation.RecipientShip do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
alias Pleroma.Conversation.Participation
|
|
|
|
alias Pleroma.Repo
|
2019-08-05 14:11:23 +00:00
|
|
|
alias Pleroma.User
|
2019-08-02 09:55:41 +00:00
|
|
|
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
schema "conversation_participation_recipient_ships" do
|
2019-09-18 14:54:31 +00:00
|
|
|
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
2019-08-02 09:55:41 +00:00
|
|
|
belongs_to(:participation, Participation)
|
|
|
|
end
|
|
|
|
|
|
|
|
def creation_cng(struct, params) do
|
|
|
|
struct
|
|
|
|
|> cast(params, [:user_id, :participation_id])
|
|
|
|
|> validate_required([:user_id, :participation_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(%User{} = user, participation), do: create([user], participation)
|
|
|
|
|
|
|
|
def create(users, participation) do
|
|
|
|
Enum.each(users, fn user ->
|
|
|
|
%__MODULE__{}
|
|
|
|
|> creation_cng(%{user_id: user.id, participation_id: participation.id})
|
|
|
|
|> Repo.insert!()
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|