summaryrefslogtreecommitdiff
path: root/lib/conversation.ex
blob: cfb78d9253149ef2ab657923b9853e3df2d28830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Conversation do
  alias Pleroma.Repo
  alias Pleroma.Conversation.Participation
  use Ecto.Schema
  import Ecto.Changeset

  schema "conversations" do
    field(:ap_id, :string)
    has_many(:participations, Participation)

    timestamps()
  end

  def creation_cng(struct, params) do
    struct
    |> cast(params, [:ap_id])
    |> validate_required([:ap_id])
    |> unique_constraint(:ap_id)
  end

  def create_for_ap_id(ap_id) do
    %__MODULE__{}
    |> creation_cng(%{ap_id: ap_id})
    |> Repo.insert()
  end
end