This enables to address the same group of people every time.stable
parent
fd4b7239cd
commit
f88560accd
@ -0,0 +1,34 @@
|
||||
# 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.User
|
||||
alias Pleroma.Repo
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "conversation_participation_recipient_ships" do
|
||||
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||
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
|
@ -0,0 +1,13 @@
|
||||
defmodule Pleroma.Repo.Migrations.CreateConversationParticipationRecipientShips do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists table(:conversation_participation_recipient_ships) do
|
||||
add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
|
||||
add(:participation_id, references(:conversation_participations, on_delete: :delete_all))
|
||||
end
|
||||
|
||||
create_if_not_exists index(:conversation_participation_recipient_ships, [:user_id])
|
||||
create_if_not_exists index(:conversation_participation_recipient_ships, [:participation_id])
|
||||
end
|
||||
end
|
Loading…
Reference in new issue