1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ThreadMute do
9 alias Pleroma.ThreadMute
14 schema "thread_mutes" do
15 belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
16 field(:context, :string)
19 def changeset(mute, params \\ %{}) do
21 |> Ecto.Changeset.cast(params, [:user_id, :context])
22 |> Ecto.Changeset.foreign_key_constraint(:user_id)
23 |> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index)
26 def query(user_id, context) do
27 {:ok, user_id} = FlakeId.Ecto.CompatType.dump(user_id)
30 |> Ecto.Query.where(user_id: ^user_id)
31 |> Ecto.Query.where(context: ^context)
34 def add_mute(user_id, context) do
36 |> changeset(%{user_id: user_id, context: context})
40 def remove_mute(user_id, context) do
41 query(user_id, context)
45 def check_muted(user_id, context) do
46 query(user_id, context)