1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Conversation.Participation do
8 alias Pleroma.Conversation
12 schema "conversation_participations" do
13 belongs_to(:user, User, type: Pleroma.FlakeId)
14 belongs_to(:conversation, Conversation)
15 field(:read, :boolean, default: false)
20 def creation_cng(struct, params) do
22 |> cast(params, [:user_id, :conversation_id])
23 |> validate_required([:user_id, :conversation_id])
26 def create_for_user_and_conversation(user, conversation) do
28 |> creation_cng(%{user_id: user.id, conversation_id: conversation.id})
32 def read_cng(struct, params) do
34 |> cast(params, [:read])
35 |> validate_required([:read])
38 def mark_as_read(participation) do
40 |> read_cng(%{read: true})
44 def mark_as_unread(participation) do
46 |> read_cng(%{read: false})