2019-08-02 03:55:41 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# 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 08:11:23 -06:00
|
|
|
alias Pleroma.User
|
2019-08-02 03:55:41 -06:00
|
|
|
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
schema "conversation_participation_recipient_ships" do
|
2019-09-18 08:54:31 -06:00
|
|
|
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
2019-08-02 03:55:41 -06: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
|