Participations: Add marking as read and unread.
[akkoma] / lib / conversation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Conversation do
6 alias Pleroma.Repo
7 alias Pleroma.Conversation.Participation
8 use Ecto.Schema
9 import Ecto.Changeset
10
11 schema "conversations" do
12 field(:ap_id, :string)
13 has_many(:participations, Participation)
14
15 timestamps()
16 end
17
18 def creation_cng(struct, params) do
19 struct
20 |> cast(params, [:ap_id])
21 |> validate_required([:ap_id])
22 |> unique_constraint(:ap_id)
23 end
24
25 def create_for_ap_id(ap_id) do
26 %__MODULE__{}
27 |> creation_cng(%{ap_id: ap_id})
28 |> Repo.insert()
29 end
30 end