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