1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.UserNote do
13 alias Pleroma.UserNote
15 schema "user_notes" do
16 belongs_to(:source, User, type: FlakeId.Ecto.CompatType)
17 belongs_to(:target, User, type: FlakeId.Ecto.CompatType)
18 field(:comment, :string)
23 def changeset(%UserNote{} = user_note, params \\ %{}) do
25 |> cast(params, [:source_id, :target_id, :comment])
26 |> validate_required([:source_id, :target_id])
29 def show(%User{} = source, %User{} = target) do
30 with %UserNote{} = note <-
32 |> where(source_id: ^source.id, target_id: ^target.id)
40 def create(%User{} = source, %User{} = target, comment) do
48 on_conflict: {:replace, [:comment]},
49 conflict_target: [:source_id, :target_id]