diff options
author | Maxim Filippov <colixer@gmail.com> | 2019-12-03 23:54:07 +0900 |
---|---|---|
committer | Maxim Filippov <colixer@gmail.com> | 2019-12-04 00:26:37 +0900 |
commit | 4b60d41db9d10e971ee91202389991da294c72de (patch) | |
tree | c5923b3f14d7a630ea4babb51925b8e0f692ee9b /lib/pleroma/report_note.ex | |
parent | d468cba2d56f60a41b0372a381b1017a8d2d046b (diff) | |
download | pleroma-4b60d41db9d10e971ee91202389991da294c72de.tar.gz |
Add report notes
Diffstat (limited to 'lib/pleroma/report_note.ex')
-rw-r--r-- | lib/pleroma/report_note.ex | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/pleroma/report_note.ex b/lib/pleroma/report_note.ex new file mode 100644 index 000000000..91102696b --- /dev/null +++ b/lib/pleroma/report_note.ex @@ -0,0 +1,46 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.ReportNote do + use Ecto.Schema + + import Ecto.Changeset + import Ecto.Query + + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.ReportNote + alias Pleroma.User + + @type t :: %__MODULE__{} + + schema "report_notes" do + field(:content, :string) + belongs_to(:user, User, type: FlakeId.Ecto.CompatType) + belongs_to(:activity, Activity, type: FlakeId.Ecto.CompatType) + + timestamps() + end + + @spec create(FlakeId.Ecto.CompatType.t(), FlakeId.Ecto.CompatType.t(), String.t()) :: + {:ok, ReportNote.t()} | {:error, Changeset.t()} + def create(user_id, activity_id, content) do + attrs = %{ + user_id: user_id, + activity_id: activity_id, + content: content + } + + %ReportNote{} + |> cast(attrs, [:user_id, :activity_id, :content]) + |> validate_required([:user_id, :activity_id, :content]) + |> Repo.insert() + end + + def get_all_for_status(status_id) do + ReportNote + |> where(activity_id: ^status_id) + |> Repo.all() + end +end |